From 9f676ebd43b38869a4ce6afee114b5d6ae7f7449 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 31 May 2022 21:22:12 +0300 Subject: [PATCH] feat(tests): improve tests for shortcodes --- .../core/Parsers/Shortcodes/CalcShortcodeTest.php | 7 +++++++ .../core/Parsers/Shortcodes/ConstShortcodeTest.php | 8 ++++++++ .../Parsers/Shortcodes/EntriesShortcodeTest.php | 7 +++++++ .../core/Parsers/Shortcodes/EvalShortcodeTest.php | 7 +++++++ .../core/Parsers/Shortcodes/FieldShortcodeTest.php | 7 +++++++ .../Parsers/Shortcodes/FilesystemShortcodeTest.php | 14 +++++++++++++- .../core/Parsers/Shortcodes/I18nShortcodeTest.php | 6 ++++++ .../core/Parsers/Shortcodes/IfShortcodeTest.php | 6 ++++++ 8 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/src/flextype/core/Parsers/Shortcodes/CalcShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/CalcShortcodeTest.php index ddb7d479..7a8e9f9f 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/CalcShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/CalcShortcodeTest.php @@ -13,4 +13,11 @@ afterEach(function () { test('calc shortcode', function () { expect(entries()->create('foo', ['price' => '(calc:2+2)']))->toBeTrue(); expect(entries()->fetch('foo')['price'])->toBe('4'); +}); + +test('calc shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.calc.enabled', false); + expect(entries()->create('foo', ['price' => '(calc:2+2)']))->toBeTrue(); + expect(entries()->fetch('foo')['price'])->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.calc.enabled', true); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/ConstShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/ConstShortcodeTest.php index ed30d354..d062eb9a 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/ConstShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/ConstShortcodeTest.php @@ -14,4 +14,12 @@ test('const shortcode', function () { define('foo', 'Foo'); expect(entries()->create('const', ['test' => '(const:foo)']))->toBeTrue(); expect(entries()->fetch('const')['test'])->toBe('Foo'); +}); + + +test('const shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.const.enabled', false); + expect(entries()->create('foo', ['test' => '(const:foo)']))->toBeTrue(); + expect(entries()->fetch('foo')['test'])->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.const.enabled', true); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/EntriesShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/EntriesShortcodeTest.php index 12f8d8ef..7ce693dc 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/EntriesShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/EntriesShortcodeTest.php @@ -31,3 +31,10 @@ test('entries shortcode', function () { $this->assertTrue(entries()->create('shop/product-1', ['title' => 'Product 1'])); expect(count(entries()->fetch('shop')['products']))->toBe(1); }); + +test('entries shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.entries.enabled', false); + expect(entries()->create('foo', ['test' => ""]))->toBeTrue(); + expect(entries()->fetch('foo')['test'])->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.entries.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/EvalShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/EvalShortcodeTest.php index b87697c7..2ac941a7 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/EvalShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/EvalShortcodeTest.php @@ -13,4 +13,11 @@ afterEach(function () { test('eval shortcode', function () { expect(entries()->create('foo', ['price' => '(eval:2+2) (eval)2+2(/eval)']))->toBeTrue(); expect(entries()->fetch('foo')['price'])->toBe('4 4'); +}); + +test('eval shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.eval.enabled', false); + expect(entries()->create('foo', ['test' => '(eval:2+2) (eval)2+2(/eval)']))->toBeTrue(); + expect(entries()->fetch('foo')['test'])->toBe(' '); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.eval.enabled', true); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php index cfa96d72..888b266b 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php @@ -13,4 +13,11 @@ afterEach(function () { test('field shortcode', function () { expect(entries()->create('foo', ['title' => '(field:id)']))->toBeTrue(); expect(entries()->fetch('foo')['title'])->toBe('foo'); +}); + +test('field shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.field.enabled', false); + expect(entries()->create('foo', ['test' => '(field:id)']))->toBeTrue(); + expect(entries()->fetch('foo')['test'])->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.field.enabled', true); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/FilesystemShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/FilesystemShortcodeTest.php index 39eb9d5d..4d570ca0 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/FilesystemShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/FilesystemShortcodeTest.php @@ -3,18 +3,30 @@ declare(strict_types=1); beforeEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true); + $this->tempDir = __DIR__ . '/tmp-foo'; @mkdir($this->tempDir); }); afterEach(function (): void { + filesystem()->directory(PATH['project'] . '/entries')->delete(); $filesystem = filesystem(); $filesystem->directory($this->tempDir)->delete(); unset($this->tempDir); }); -test('[filesystem] shortcode', function () { +test('filesystem shortcode', function () { $filesystem = filesystem(); $filesystem->file($this->tempDir . '/foo.txt')->put('Foo'); $this->assertEquals("Foo", parsers()->shortcodes()->parse("(filesystem get file:'". $this->tempDir . "/foo.txt')")); }); + +test('filesystem shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.filesystem.enabled', false); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.filesystem.get.enabled', false); + expect(entries()->create('foo', ['test' => '(filesystem get file:1.txt)']))->toBeTrue(); + expect(entries()->fetch('foo')['test'])->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.filesystem.enabled', true); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.filesystem.get.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php index 90ac174b..92bef23b 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/I18nShortcodeTest.php @@ -5,3 +5,9 @@ declare(strict_types=1); test('tr shortcode', function () { expect(parsers()->shortcodes()->parse('(tr:foo)'))->toBe('foo'); }); + +test('tr shortcode disabled', function () { + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.i18n.enabled', false); + expect(parsers()->shortcodes()->parse('(tr:foo)'))->toBe(''); + registry()->set('flextype.settings.parsers.shortcodes.shortcodes.i18n.enabled', true); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php index 20a49d53..d407f5c8 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/IfShortcodeTest.php @@ -7,3 +7,9 @@ test('if shortcode', function () { expect(parsers()->shortcodes()->parse("(if:'2>1')yes(/if)"))->toBe("yes"); expect(parsers()->shortcodes()->parse("(if:'2<1')yes(/if)"))->toBe(""); }); + +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