1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-10 15:14:20 +02:00

feat(parsers): standardise parsers container names with macroable ability for Parsers API. #519

This commit is contained in:
Awilum
2020-12-18 14:10:22 +03:00
parent 9031ea3fa5
commit 5cd5b9fed7
13 changed files with 124 additions and 109 deletions

View File

@@ -8,34 +8,34 @@ use Thunder\Shortcode\Events;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
test('test getInstance() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('shortcode')->getInstance());
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->getInstance());
});
test('test addHandler() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('shortcode')->addHandler('foo', static function() { return ''; }));
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('foo', static function() { return ''; }));
});
test('test addEventHandler() method', function () {
flextype('shortcode')->addHandler('barz', static function () {
flextype('parsers')->shortcode()->addHandler('barz', static function () {
return 'Barz';
});
flextype('shortcode')->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['barz']));
$this->assertEquals('Barz', flextype('shortcode')->process('[barz]'));
flextype('parsers')->shortcode()->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['barz']));
$this->assertEquals('Barz', flextype('parsers')->shortcode()->process('[barz]'));
});
test('test parse() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('shortcode')->addHandler('bar', static function() { return ''; }));
$this->assertTrue(is_array(flextype('shortcode')->parse('[bar]')));
$this->assertTrue(is_object(flextype('shortcode')->parse('[bar]')[0]));
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('bar', static function() { return ''; }));
$this->assertTrue(is_array(flextype('parsers')->shortcode()->parse('[bar]')));
$this->assertTrue(is_object(flextype('parsers')->shortcode()->parse('[bar]')[0]));
});
test('test process() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('shortcode')->addHandler('zed', static function() { return 'Zed'; }));
$this->assertEquals('Zed', flextype('shortcode')->process('[zed]'));
$this->assertEquals('fòôBàřZed', flextype('shortcode')->process('fòôBàř[zed]'));
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('zed', static function() { return 'Zed'; }));
$this->assertEquals('Zed', flextype('parsers')->shortcode()->process('[zed]'));
$this->assertEquals('fòôBàřZed', flextype('parsers')->shortcode()->process('fòôBàř[zed]'));
});
test('test getCacheID() method', function () {
$this->assertNotEquals(flextype('shortcode')->getCacheID('fòôBàř[bar]'),
flextype('shortcode')->getCacheID('fòôBàř[foo]'));
$this->assertNotEquals(flextype('parsers')->shortcode()->getCacheID('fòôBàř[bar]'),
flextype('parsers')->shortcode()->getCacheID('fòôBàř[foo]'));
});

View File

@@ -12,6 +12,6 @@ afterEach(function (): void {
test('test entries_fetch shortcode', function () {
$this->assertTrue(flextype('entries')->create('foo', ['title' => 'Foo']));
$this->assertEquals('Foo', flextype('shortcode')->process('[entries_fetch id="foo" field="title"]'));
$this->assertEquals('Bar', flextype('shortcode')->process('[entries_fetch id="foo" field="bar" default="Bar"]'));
$this->assertEquals('Foo', flextype('parsers')->shortcode()->process('[entries_fetch id="foo" field="title"]'));
$this->assertEquals('Bar', flextype('parsers')->shortcode()->process('[entries_fetch id="foo" field="bar" default="Bar"]'));
});

View File

@@ -13,5 +13,5 @@ afterEach(function (): void {
test('test raw shortcode', function () {
$this->assertTrue(flextype('entries')->create('foo', ['title' => 'Foo']));
$this->assertEquals('[entries_fetch id="foo" field="title"]',
flextype('shortcode')->process('[raw][entries_fetch id="foo" field="title"][/raw]'));
flextype('parsers')->shortcode()->process('[raw][entries_fetch id="foo" field="title"][/raw]'));
});

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
test('test registry_get shortcode', function () {
$this->assertEquals('Flextype',
flextype('shortcode')->process('[registry_get name="flextype.manifest.name"]'));
flextype('parsers')->shortcode()->process('[registry_get name="flextype.manifest.name"]'));
$this->assertEquals('default-value',
flextype('shortcode')->process('[registry_get name="item-name" default="default-value"]'));
flextype('parsers')->shortcode()->process('[registry_get name="item-name" default="default-value"]'));
});

View File

@@ -3,8 +3,8 @@
declare(strict_types=1);
test('test registry_get shortcode', function () {
$this->assertStringContainsString('http', flextype('shortcode')->process('[url]'));
$this->assertStringContainsString('http', flextype('parsers')->shortcode()->process('[url]'));
flextype('registry')->set('flextype.settings.url', 'https://flextype.org');
$this->assertStringContainsString('https://flextype.org', flextype('shortcode')->process('[url]'));
$this->assertStringContainsString('https://flextype.org', flextype('parsers')->shortcode()->process('[url]'));
});