mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(tests): improve tests for shortcodes
This commit is contained in:
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
@@ -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);
|
||||
});
|
Reference in New Issue
Block a user