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 22:02:02 +03:00
parent b68bc7a8a9
commit a195b3e7bb
5 changed files with 35 additions and 5 deletions

View File

@@ -16,3 +16,9 @@ test('textile shortcode', function () {
expect(entries()->create('textile', ['test' => '(textile) **Foo**']))->toBeTrue();
expect(entries()->fetch('textile')['test'])->toBe("<p> <b>Foo</b></p>");
});
test('textile shortcode disabled', function () {
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.textile.enabled', false);
expect(parsers()->shortcodes()->parse("(textile)foo(/textile)"))->toBe('');
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.textile.enabled', true);
});

View File

@@ -16,4 +16,10 @@ test('type shortcode', function () {
expect(entries()->create('test-2', ['price' => '(type:string) 10']))->toBeTrue();
expect(entries()->fetch('test-2')['price'])->toBe('10');
});
test('type shortcode disabled', function () {
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.type.enabled', false);
expect(parsers()->shortcodes()->parse("(type:int) 10"))->toBe(' 10');
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.type.enabled', true);
});

View File

@@ -2,26 +2,32 @@
declare(strict_types=1);
test('(getBaseUrl) shortcode', function () {
test('getBaseUrl shortcode', function () {
registry()->set('flextype.settings.base_url', 'https://awilum.github.io/flextype');
$this->assertStringContainsString('https://awilum.github.io/flextype', parsers()->shortcodes()->parse('(getBaseUrl)'));
});
test('(getBasePath) shortcode', function () {
test('getBasePath shortcode', function () {
app()->setBasePath('/foo/');
$this->assertStringContainsString('/foo/', parsers()->shortcodes()->parse('(getBasePath)'));
});
test('(getAbsoluteUrl) shortcode', function () {
test('getAbsoluteUrl shortcode', function () {
$this->assertStringContainsString('/', parsers()->shortcodes()->parse('(getAbsoluteUrl)'));
});
test('(getUriString) shortcode', function () {
test('getUriString shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse('(getUriString)'));
});
test('(urlFor) shortcode', function () {
test('urlFor shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse("(urlFor routeName='test-route' queryParams='{\"foo\": \"Foo\"}')"));
});
test('url shortcode disabled', function () {
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.url.enabled', false);
expect(parsers()->shortcodes()->parse("(getBasePath)"))->toBe('');
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.url.enabled', true);
});

View File

@@ -5,4 +5,10 @@ declare(strict_types=1);
test('uuid shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('(uuid)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid:4)'))->length() > 0)->toBeTrue();
});
test('uuid shortcode disabled', function () {
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled', false);
expect(parsers()->shortcodes()->parse("(uuid)"))->toBe('');
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled', true);
});

View File

@@ -19,4 +19,10 @@ test('var shortcode', function () {
expect(entries()->create('zed', ['title' => '(var set:zed)Zed(/var)(var:zed)']))->toBeTrue();
expect(entries()->fetch('zed')['title'])->toBe('Zed');
});
test('var shortcode disabled', function () {
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.var.enabled', false);
expect(parsers()->shortcodes()->parse("(var set:bar value:Bar)"))->toBe('');
registry()->set('flextype.settings.parsers.shortcodes.shortcodes.var.enabled', true);
});