1
0
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:
Awilum
2022-05-31 21:57:09 +03:00
parent fbdcc8af3c
commit b68bc7a8a9
6 changed files with 34 additions and 2 deletions

View File

@@ -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);
});
});

View File

@@ -16,3 +16,9 @@ test('markdown shortcode', function () {
expect(entries()->create('md', ['test' => '(markdown) **Foo**']))->toBeTrue();
expect(entries()->fetch('md')['test'])->toBe("<p> <strong>Foo</strong></p>");
});
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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});