From b68bc7a8a9803fd485fdce42db2c8ba58beca01c Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 31 May 2022 21:57:09 +0300 Subject: [PATCH] feat(tests): improve tests for shortcodes --- .../flextype/core/Parsers/Shortcodes/IfShortcodeTest.php | 2 +- .../core/Parsers/Shortcodes/MarkdownShortcodeTest.php | 6 ++++++ .../flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php | 6 ++++++ .../flextype/core/Parsers/Shortcodes/RawShortcodeTest.php | 8 +++++++- .../core/Parsers/Shortcodes/RegistryShortcodeTest.php | 6 ++++++ .../core/Parsers/Shortcodes/StringsShortcodeTest.php | 8 ++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php index d407f5c8..10937463 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php @@ -12,4 +12,4 @@ test('if shortcode disabled', function () { registry()->set('flextype.settings.parsers.shortcodes.shortcodes.if.enabled', false); expect(parsers()->shortcodes()->parse("(if:'2 > 1')yes(/if)"))->toBe(''); registry()->set('flextype.settings.parsers.shortcodes.shortcodes.if.enabled', true); - }); \ No newline at end of file +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php index f299046d..2a02dff5 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/MarkdownShortcodeTest.php @@ -16,3 +16,9 @@ test('markdown shortcode', function () { expect(entries()->create('md', ['test' => '(markdown) **Foo**']))->toBeTrue(); expect(entries()->fetch('md')['test'])->toBe("

Foo

"); }); + +test('markdown shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.markdown.enabled', false); + expect(parsers()->shortcodes()->parse("(markdown)**Foo**(/markdown)"))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.markdown.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php index 5c4556f2..0d67809a 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php @@ -16,3 +16,9 @@ test('php shortcode', function () { expect(entries()->create('bar', ['test' => '(php) echo "Bar";']))->toBeTrue(); expect(entries()->fetch('bar')['test'])->toBe('Bar'); }); + +test('php shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.php.enabled', false); + expect(parsers()->shortcodes()->parse("(php)**Foo**(/php)"))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.php.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/RawShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/RawShortcodeTest.php index 0ed7b978..aff1aa01 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/RawShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/RawShortcodeTest.php @@ -10,8 +10,14 @@ afterEach(function () { filesystem()->directory(PATH['project'] . '/entries')->delete(); }); -test('[raw] shortcode', function () { +test('raw shortcode', function () { $this->assertTrue(entries()->create('foo', ['title' => 'Foo'])); $this->assertEquals("(entries fetch:'foo' field:'title')", parsers()->shortcodes()->parse("(raw)(entries fetch:'foo' field:'title')(/raw)")); }); + +test('raw shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.raw.enabled', false); + expect(parsers()->shortcodes()->parse("(raw)(entries fetch:'foo' field:'title')(/raw)"))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.raw.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php index 3b81756d..29e31a6a 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php @@ -7,3 +7,9 @@ test('registry shortcode', function () { expect(parsers()->shortcodes()->parse("(registry get:'flextype.manifest.name')"))->toBe('Flextype'); expect(parsers()->shortcodes()->parse("(registry get:'flextype.manifest.foo' default:'Default')"))->toBe('Default'); }); + +test('registry shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.registry.enabled', false); + expect(parsers()->shortcodes()->parse("(registry get:'flextype.manifest.name')"))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.registry.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php index ceae36e6..b57c78a3 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/StringsShortcodeTest.php @@ -12,6 +12,7 @@ test('strings shortcode', function () { // append $this->assertEquals("zed foo bar", parsers()->shortcodes()->parse("(strings append:' bar')zed foo(/strings)")); + $this->assertEquals("zed foo bar zed", parsers()->shortcodes()->parse("(strings append:' bar, zed')zed foo(/strings)")); // prepend $this->assertEquals("zed foo bar", parsers()->shortcodes()->parse("(strings prepend:'zed ')foo bar(/strings)")); @@ -65,6 +66,7 @@ test('strings shortcode', function () { // contains $this->assertEquals("true", parsers()->shortcodes()->parse("(strings contains:SG-1)SG-1 returns from an off-world mission to P9Y-3C3(/strings)")); $this->assertEquals("true", parsers()->shortcodes()->parse("(strings contains:SG-1,P9Y-3C3)SG-1 returns from an off-world mission to P9Y-3C3(/strings)")); + $this->assertEquals("false", parsers()->shortcodes()->parse("(strings contains:'')SG-1 returns from an off-world mission to P9Y-3C3(/strings)")); $this->assertEquals("false", parsers()->shortcodes()->parse("(strings contains:sg-1)SG-1 returns from an off-world mission to P9Y-3C3(/strings)")); // containsAll @@ -344,4 +346,10 @@ test('strings shortcode', function () { test('strings nested shortcode', function () { expect(parsers()->shortcodes()->parse("(strings append:'(strings hash)(strings upper)foo(/strings)(/strings)')Hash: (/strings)"))->toBe('Hash: 901890a8e9c8cf6d5a1a542b229febff'); +}); + +test('strings shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.strings.enabled', false); + expect(parsers()->shortcodes()->parse("(strings ucfirst)foo(/strings)"))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.strings.enabled', true); }); \ No newline at end of file