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

feat(shortcodes): implement new syntax for shortcodes

This commit is contained in:
Awilum
2022-05-21 16:22:18 +03:00
parent f102755072
commit 09e7c20ca2
14 changed files with 193 additions and 190 deletions

View File

@@ -17,7 +17,10 @@ declare(strict_types=1);
namespace Flextype\Parsers;
use Exception;
use Thunder\Shortcode\ShortcodeFacade;
use Thunder\Shortcode\Syntax\Syntax;
use Thunder\Shortcode\Parser\RegularParser;
use function cache;
use function count;
@@ -60,8 +63,9 @@ final class Shortcodes
protected function __construct()
{
$this->shortcodeFacade = new ShortcodeFacade();
$this->shortcodeFacade->setParser((new RegularParser((new Syntax('(', ')', '/', ':', '"')))));
}
/**
* Gets the instance via lazy initialization (created on first usage).
*/

View File

@@ -10,8 +10,8 @@ afterEach(function () {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('[entries-fetch] shortcode', function () {
$this->assertTrue(entries()->create('blog', ['title' => 'Blog', 'categories' => "@type(array) [entries fetch=\"blog,collection=true&filter[sort_by][key]=date&filter[sort_by][direction]=ASC\" /]"]));
test('(entries-fetch] shortcode', function () {
$this->assertTrue(entries()->create('blog', ['title' => 'Blog', 'categories' => "@type[array] (entries fetch:\"blog,collection=true&filter[sort_by][key]=date&filter[sort_by][direction]=ASC\" /)"]));
$this->assertTrue(entries()->create('blog/post-1', ['title' => 'Post 1']));
$this->assertTrue(entries()->create('blog/post-2', ['title' => 'Post 2']));
$this->assertTrue(entries()->create('blog/post-3', ['title' => 'Post 3']));
@@ -21,9 +21,9 @@ test('[entries-fetch] shortcode', function () {
expect(entries()->fetch('blog')->dot()->count())->toBe(44);
$this->assertTrue(entries()->create('blog-2', ['title' => 'Blog', 'category-cat' => "[entries fetch=\"categories/cat\" field=\"title,Foo\" /]"]));
$this->assertTrue(entries()->create('blog-2', ['title' => 'Blog', 'category-cat' => "(entries fetch:\"categories/cat\" field:\"title,Foo\" /)"]));
expect(entries()->fetch('blog-2')['category-cat'])->toBe('Cat');
$this->assertTrue(entries()->create('blog-3', ['title' => 'Blog', 'category-cat' => "[entries fetch=\"categories/cat\" field=\"title2,Foo\" /]"]));
$this->assertTrue(entries()->create('blog-3', ['title' => 'Blog', 'category-cat' => "(entries fetch:\"categories/cat\" field:\"title2,Foo\" /)"]));
expect(entries()->fetch('blog-3')['category-cat'])->toBe('Foo');
});

View File

@@ -16,5 +16,5 @@ afterEach(function (): void {
test('[filesystem] shortcode', function () {
$filesystem = filesystem();
$filesystem->file($this->tempDir . '/foo.txt')->put('Foo');
$this->assertEquals("Foo", parsers()->shortcodes()->parse('[filesystem get="' . $this->tempDir .'/foo.txt"]'));
$this->assertEquals("Foo", parsers()->shortcodes()->parse('(filesystem get:"' . $this->tempDir .'/foo.txt")'));
});

View File

@@ -3,5 +3,5 @@
declare(strict_types=1);
test('[tr] shortcode', function () {
expect(parsers()->shortcodes()->parse('[tr find="Foo"]'))->toBe('Foo');
expect(parsers()->shortcodes()->parse('(tr find:foo)'))->toBe('foo');
});

View File

@@ -2,27 +2,27 @@
declare(strict_types=1);
test('[if] shortcode', function () {
expect(parsers()->shortcodes()->parse('[if val1="2" operator="lt" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="<" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="5" operator="gt" val2="2"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="lte" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="<=" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="5" operator="gte" val2="2"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="5" operator=">=" val2="2"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="5" operator="eq" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="5" operator="=" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="neq" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="<>" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2" operator="!=" val2="5"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobarfoo" operator="contains" val2="bar"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobarfoo" operator="like" val2="bar"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobarfoo" operator="ncontains" val2="zed"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobarfoo" operator="nlike" val2="zed"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobar" operator="starts_with" val2="foo"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="foobar" operator="ends_with" val2="bar"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2020-11-12" operator="newer" val2="2020-11-11"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="2020-11-11" operator="older" val2="2020-11-12"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="PHP is the web scripting language of choice." operator="regexp" val2="php"]yes[/if]'))->toBe('yes');
expect(parsers()->shortcodes()->parse('[if val1="PHP is the web scripting language of choice." operator="nregexp" val2="delphi"]yes[/if]'))->toBe('yes');
test('(if] shortcode', function () {
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"lt" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"<" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"5" operator:"gt" val2:"2")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"lte" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"<=" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"5" operator:"gte" val2:"2")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"5" operator:">=" val2:"2")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"5" operator:"eq" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"5" operator:"=" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"neq" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"<>" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2" operator:"!=" val2:"5")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobarfoo" operator:"contains" val2:"bar")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobarfoo" operator:"like" val2:"bar")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobarfoo" operator:"ncontains" val2:"zed")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobarfoo" operator:"nlike" val2:"zed")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobar" operator:"starts_with" val2:"foo")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"foobar" operator:"ends_with" val2:"bar")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2020-11-12" operator:"newer" val2:"2020-11-11")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"2020-11-11" operator:"older" val2:"2020-11-12")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"PHP is the web scripting language of choice." operator:"regexp" val2:"php")yes(/if)'))->toBe('yes');
expect(parsers()->shortcodes()->parse('(if val1:"PHP is the web scripting language of choice." operator:"nregexp" val2:"delphi")yes(/if)'))->toBe('yes');
});

View File

@@ -4,5 +4,5 @@ declare(strict_types=1);
test('[markdown] shortcode', function () {
$this->assertEquals("<p><strong>Foo</strong></p>\n",
parsers()->shortcodes()->parse('[markdown]**Foo**[/markdown]'));
parsers()->shortcodes()->parse('(markdown)**Foo**(/markdown)'));
});

View File

@@ -4,5 +4,5 @@ declare(strict_types=1);
test('[php] shortcode', function () {
$this->assertEquals("Foo",
parsers()->shortcodes()->parse('[php]echo "Foo";[/php]'));
parsers()->shortcodes()->parse('(php)echo "Foo";(/php)'));
});

View File

@@ -12,6 +12,6 @@ afterEach(function () {
test('[raw] shortcode', function () {
$this->assertTrue(entries()->create('foo', ['title' => 'Foo']));
$this->assertEquals('[entries_fetch id="foo" field="title"]',
parsers()->shortcodes()->parse('[raw][entries_fetch id="foo" field="title"][/raw]'));
$this->assertEquals('(entries fetch:"foo" field:"title")',
parsers()->shortcodes()->parse('(raw)(entries fetch:"foo" field:"title")(/raw)'));
});

View File

@@ -3,8 +3,7 @@
declare(strict_types=1);
test('[registry] shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('[registry get="flextype.manifest"]'))->isJson())->toBeTrue();
expect(parsers()->shortcodes()->parse('[registry get="flextype.manifest.name"]'))->toBe('Flextype');
expect(parsers()->shortcodes()->parse('[registry get="flextype.manifest.foo,Default"]'))->toBe('Default');
expect(strings(parsers()->shortcodes()->parse('(registry get:"flextype.manifest")'))->isJson())->toBeTrue();
expect(parsers()->shortcodes()->parse('(registry get:"flextype.manifest.name")'))->toBe('Flextype');
expect(parsers()->shortcodes()->parse('(registry get:"flextype.manifest.foo,Default")'))->toBe('Default');
});

View File

@@ -2,341 +2,341 @@
declare(strict_types=1);
test('[strings] shortcode', function () {
test('(strings) shortcode', function () {
// lower
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('[strings lower]zed foo bar[/strings]'));
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('(strings lower)zed foo bar(/strings)'));
// upper
$this->assertEquals("ZED FOO BAR", parsers()->shortcodes()->parse('[strings upper]zed foo bar[/strings]'));
$this->assertEquals("ZED FOO BAR", parsers()->shortcodes()->parse('(strings upper)zed foo bar(/strings)'));
// append
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('[strings append=" bar"]zed foo[/strings]'));
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('(strings append:" bar")zed foo(/strings)'));
// prepend
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('[strings prepend="zed "]foo bar[/strings]'));
$this->assertEquals("zed foo bar", parsers()->shortcodes()->parse('(strings prepend:"zed ")foo bar(/strings)'));
// sort
$this->assertEquals("a b c", parsers()->shortcodes()->parse('[strings sort="asc"]b a c[/strings]'));
$this->assertEquals("c b a", parsers()->shortcodes()->parse('[strings sort="desc"]b a c[/strings]'));
$this->assertEquals("a b c", parsers()->shortcodes()->parse('(strings sort:"asc")b a c(/strings)'));
$this->assertEquals("c b a", parsers()->shortcodes()->parse('(strings sort:"desc")b a c(/strings)'));
// after
$this->assertEquals(" bar zed", parsers()->shortcodes()->parse('[strings after="foo"]foo bar zed[/strings]'));
$this->assertEquals(" bar zed", parsers()->shortcodes()->parse('(strings after:"foo")foo bar zed(/strings)'));
// afterLast
$this->assertEquals(" bar zed", parsers()->shortcodes()->parse('[strings afterLast="foo"]foo foo bar zed[/strings]'));
$this->assertEquals(" bar zed", parsers()->shortcodes()->parse('(strings afterLast:"foo")foo foo bar zed(/strings)'));
// before
$this->assertEquals("foo bar ", parsers()->shortcodes()->parse('[strings before="zed"]foo bar zed[/strings]'));
$this->assertEquals("foo bar ", parsers()->shortcodes()->parse('(strings before:"zed")foo bar zed(/strings)'));
// beforeLast
$this->assertEquals("foo ", parsers()->shortcodes()->parse('[strings beforeLast="foo"]foo foo bar zed[/strings]'));
$this->assertEquals("foo ", parsers()->shortcodes()->parse('(strings beforeLast:"foo")foo foo bar zed(/strings)'));
// wordsLimit
$this->assertEquals("foo...", parsers()->shortcodes()->parse('[strings wordsLimit="1"]foo bar zed[/strings]'));
$this->assertEquals("foo >>>", parsers()->shortcodes()->parse('[strings wordsLimit="1, >>>"]foo bar zed[/strings]'));
$this->assertEquals("foo...", parsers()->shortcodes()->parse('(strings wordsLimit:"1")foo bar zed(/strings)'));
$this->assertEquals("foo >>>", parsers()->shortcodes()->parse('(strings wordsLimit:"1, >>>")foo bar zed(/strings)'));
// at
$this->assertEquals("a", parsers()->shortcodes()->parse('[strings at=0]abc[/strings]'));
$this->assertEquals("b", parsers()->shortcodes()->parse('[strings at=1]abc[/strings]'));
$this->assertEquals("c", parsers()->shortcodes()->parse('[strings at=2]abc[/strings]'));
$this->assertEquals("a", parsers()->shortcodes()->parse('(strings at:0)abc(/strings)'));
$this->assertEquals("b", parsers()->shortcodes()->parse('(strings at:1)abc(/strings)'));
$this->assertEquals("c", parsers()->shortcodes()->parse('(strings at:2)abc(/strings)'));
// base64Decode
$this->assertEquals("test", parsers()->shortcodes()->parse('[strings base64Decode]dGVzdA==[/strings]'));
$this->assertEquals("test", parsers()->shortcodes()->parse('(strings base64Decode)dGVzdA==(/strings)'));
// base64Encode
$this->assertEquals("dGVzdA==", parsers()->shortcodes()->parse('[strings base64Encode]test[/strings]'));
$this->assertEquals("dGVzdA==", parsers()->shortcodes()->parse('(strings base64Encode)test(/strings)'));
// between
$this->assertEquals("b", parsers()->shortcodes()->parse('[strings between=a,c]abc[/strings]'));
$this->assertEquals("b", parsers()->shortcodes()->parse('(strings between:a,c)abc(/strings)'));
// camel
$this->assertEquals("fooBar", parsers()->shortcodes()->parse('[strings camel]foo_bar[/strings]'));
$this->assertEquals("fooBar", parsers()->shortcodes()->parse('(strings camel)foo_bar(/strings)'));
// capitalize
$this->assertEquals("That Country Was At The Same Stage Of Development As The United States In The 1940S", parsers()->shortcodes()->parse('[strings capitalize]that country was at the same stage of development as the United States in the 1940s[/strings]'));
$this->assertEquals("That Country Was At The Same Stage Of Development As The United States In The 1940S", parsers()->shortcodes()->parse('(strings capitalize)that country was at the same stage of development as the United States in the 1940s(/strings)'));
// chars
$this->assertEquals('["c","a","r","_","f","ò","ô","_","b","à","ř","s","_","a","p","p","l","e"]', parsers()->shortcodes()->parse('[strings chars]car_fòô_bàřs_apple[/strings]'));
$this->assertEquals('["c","a","r","_","f","ò","ô","_","b","à","ř","s","_","a","p","p","l","e"]', parsers()->shortcodes()->parse('(strings chars)car_fòô_bàřs_apple(/strings)'));
// charsFrequency
$this->assertEquals('{"_":"16.67","a":"11.11","p":"11.11","c":"5.56","r":"5.56","f":"5.56","ò":"5.56","ô":"5.56","b":"5.56","à":"5.56","ř":"5.56","s":"5.56","l":"5.56","e":"5.56"}', parsers()->shortcodes()->parse('[strings charsFrequency]car_fòô_bàřs_apple[/strings]'));
$this->assertEquals('{"_":"16.67","a":"11.11","p":"11.11","c":"5.56","r":"5.56","f":"5.56","ò":"5.56","ô":"5.56","b":"5.56","à":"5.56","ř":"5.56","s":"5.56","l":"5.56","e":"5.56"}', parsers()->shortcodes()->parse('(strings charsFrequency)car_fòô_bàřs_apple(/strings)'));
// 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]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$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)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
// containsAll
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAll=SG-1]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAll=SG-1&P9Y-3C3]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("false", parsers()->shortcodes()->parse('[strings containsAll=SG-1&XXX-3C3]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAll=sg-1&P9Y-3C3,false]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAll:SG-1)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAll:SG-1&P9Y-3C3)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("false", parsers()->shortcodes()->parse('(strings containsAll:SG-1&XXX-3C3)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAll:sg-1&P9Y-3C3,false)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
// containsAny
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAny=SG-1]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAny=SG-1&P9Y-3C3]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAny=SG-1&XXX-3C3]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings containsAny=sg-1&P9Y-3C3,false]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAny:SG-1)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAny:SG-1&P9Y-3C3)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAny:SG-1&XXX-3C3)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings containsAny:sg-1&P9Y-3C3,false)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
// count
$this->assertEquals(49, parsers()->shortcodes()->parse('[strings count]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));
$this->assertEquals(49, parsers()->shortcodes()->parse('(strings count)SG-1 returns from an off-world mission to P9Y-3C3(/strings)'));
// countSubString
$this->assertEquals(1, parsers()->shortcodes()->parse('[strings countSubString=test]Test string here for test[/strings]'));
$this->assertEquals(2, parsers()->shortcodes()->parse('[strings countSubString=test,false]Test string here for test[/strings]'));
$this->assertEquals(1, parsers()->shortcodes()->parse('(strings countSubString:test)Test string here for test(/strings)'));
$this->assertEquals(2, parsers()->shortcodes()->parse('(strings countSubString:test,false)Test string here for test(/strings)'));
// crc32
$this->assertEquals(3632233996, parsers()->shortcodes()->parse('[strings crc32]test[/strings]'));
$this->assertEquals(3632233996, parsers()->shortcodes()->parse('(strings crc32)test(/strings)'));
// endsWith
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21/[/strings]'));
$this->assertEquals("false", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings endsWith:"/")/movies/sg-1/season-5/episode-21/(/strings)'));
$this->assertEquals("false", parsers()->shortcodes()->parse('(strings endsWith:"/")/movies/sg-1/season-5/episode-21(/strings)'));
// finish
$this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('[strings finish="/"]/movies/sg-1/season-5/episode-21[/strings]'));
$this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('(strings finish:"/")/movies/sg-1/season-5/episode-21(/strings)'));
// firstSegment
$this->assertEquals("SG-1", parsers()->shortcodes()->parse('[strings firstSegment]SG-1 returns from an off-world mission[/strings]'));
$this->assertEquals("SG", parsers()->shortcodes()->parse('[strings firstSegment="-"]SG-1 returns from an off-world mission[/strings]'));
$this->assertEquals("SG-1", parsers()->shortcodes()->parse('(strings firstSegment)SG-1 returns from an off-world mission(/strings)'));
$this->assertEquals("SG", parsers()->shortcodes()->parse('(strings firstSegment:"-")SG-1 returns from an off-world mission(/strings)'));
// format
$this->assertEquals("There are 5 monkeys in the tree", parsers()->shortcodes()->parse('[strings format="5,tree"]There are %d monkeys in the %s[/strings]'));
$this->assertEquals("There are 5 monkeys in the tree", parsers()->shortcodes()->parse('(strings format:"5,tree")There are %d monkeys in the %s(/strings)'));
// getEncoding
$this->assertEquals("UTF-8", parsers()->shortcodes()->parse('[strings getEncoding]Foo[/strings]'));
$this->assertEquals("UTF-8", parsers()->shortcodes()->parse('(strings getEncoding)Foo(/strings)'));
// hash
$this->assertEquals("1356c67d7ad1638d816bfb822dd2c25d", parsers()->shortcodes()->parse('[strings hash]Foo[/strings]'));
$this->assertEquals("201a6b3053cc1422d2c3670b62616221d2290929", parsers()->shortcodes()->parse('[strings hash=sha1]Foo[/strings]'));
$this->assertEquals("1356c67d7ad1638d816bfb822dd2c25d", parsers()->shortcodes()->parse('(strings hash)Foo(/strings)'));
$this->assertEquals("201a6b3053cc1422d2c3670b62616221d2290929", parsers()->shortcodes()->parse('(strings hash:sha1)Foo(/strings)'));
// increment
$this->assertEquals("Page_2", parsers()->shortcodes()->parse('[strings increment]Page_1[/strings]'));
$this->assertEquals("Page-2", parsers()->shortcodes()->parse('[strings increment=1,-]Page-1[/strings]'));
$this->assertEquals("Page_2", parsers()->shortcodes()->parse('(strings increment)Page_1(/strings)'));
$this->assertEquals("Page-2", parsers()->shortcodes()->parse('(strings increment:1,-)Page-1(/strings)'));
// indexOf
$this->assertEquals(1, parsers()->shortcodes()->parse('[strings indexOf=e]hello[/strings]'));
$this->assertEquals(1, parsers()->shortcodes()->parse('(strings indexOf:e)hello(/strings)'));
// indexOfLast
$this->assertEquals(3, parsers()->shortcodes()->parse('[strings indexOfLast=l]hello[/strings]'));
$this->assertEquals(3, parsers()->shortcodes()->parse('(strings indexOfLast:l)hello(/strings)'));
// insert
$this->assertEquals("hello world", parsers()->shortcodes()->parse('[strings insert="hello ,0"]world[/strings]'));
$this->assertEquals("hello world", parsers()->shortcodes()->parse('[strings insert=" world,5"]hello[/strings]'));
$this->assertEquals("hello world", parsers()->shortcodes()->parse('(strings insert:"hello ,0")world(/strings)'));
$this->assertEquals("hello world", parsers()->shortcodes()->parse('(strings insert:" world,5")hello(/strings)'));
// isAlpha
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isAlpha]foo[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isAlpha)foo(/strings)'));
// isAlphanumeric
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isAlphanumeric]fòôbàřs12345[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isAlphanumeric)fòôbàřs12345(/strings)'));
// isAscii
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isAscii]#@$%[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isAscii)#@$%(/strings)'));
// isBase64
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isBlank][/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isBlank)(/strings)'));
// isDigit
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isDigit]01234569[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isDigit)01234569(/strings)'));
// isEmail
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isEmail]awilum@msn.com[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isEmail)awilum@msn.com(/strings)'));
// isEmpty
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isEmpty][/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isEmpty)(/strings)'));
// isEqual
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isEqual=Foo]Foo[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isEqual:Foo)Foo(/strings)'));
// isTrue
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isTrue]true[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isTrue)true(/strings)'));
// isFalse
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isFalse]false[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isFalse)false(/strings)'));
// isHexadecimal
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isHexadecimal]19FDE[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isHexadecimal)19FDE(/strings)'));
// isHTML
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isHTML]<p>Hello</p>[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isHTML)<p>Hello</p>(/strings)'));
// isIP
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isIP]127.0.0.1[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isIP)127.0.0.1(/strings)'));
// isJSON
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isJson]{"foo":"bar"}[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isJson){"foo":"bar"}(/strings)'));
// isLower
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isLower]foo[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isLower)foo(/strings)'));
// isMAC
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isMAC]00:00:00:00:00:00[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isMAC)00:00:00:00:00:00(/strings)'));
// isUpper
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isUpper]FOO[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isUpper)FOO(/strings)'));
// isNumeric
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isNumeric]12345[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isNumeric)12345(/strings)'));
// isPrintable
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isPrintable]!@#$%^&*()_+-=[]{};\':\"./<>?\\`~"[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isPrintable)!@#$%^&*()_+-:(){};\':\"./<>?\\`~"(/strings)'));
// isPunctuation
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isPunctuation],[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isPunctuation),(/strings)'));
// isUrl
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isUrl]http://awilum.github.io[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isUrl]https://awilum.github.io[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isUrl)http://awilum.github.io(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isUrl)https://awilum.github.io(/strings)'));
// isSimilar
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isSimilar=Foo]Foo[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isSimilar=Foo,50]Foo[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isSimilar:Foo)Foo(/strings)'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isSimilar:Foo,50)Foo(/strings)'));
// isSerialized
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings isSerialized]a:1:{i:0;s:3:"foo";}[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings isSerialized)a:1:{i:0;s:3:"foo";}(/strings)'));
// kebab
$this->assertEquals("foo-bar", parsers()->shortcodes()->parse('[strings kebab]Foo Bar[/strings]'));
$this->assertEquals("foo-bar", parsers()->shortcodes()->parse('(strings kebab)Foo Bar(/strings)'));
// lastSegment
$this->assertEquals("baz", parsers()->shortcodes()->parse('[strings lastSegment]foo bar baz[/strings]'));
$this->assertEquals("baz", parsers()->shortcodes()->parse('[strings lastSegment="/"]foo/bar/baz[/strings]'));
$this->assertEquals("baz", parsers()->shortcodes()->parse('(strings lastSegment)foo bar baz(/strings)'));
$this->assertEquals("baz", parsers()->shortcodes()->parse('(strings lastSegment:"/")foo/bar/baz(/strings)'));
// length
$this->assertEquals(11, parsers()->shortcodes()->parse('[strings length]foo bar baz[/strings]'));
$this->assertEquals(11, parsers()->shortcodes()->parse('(strings length)foo bar baz(/strings)'));
// lines
$this->assertEquals('["Fòô òô"," fòô fò fò ","fò"]', parsers()->shortcodes()->parse("[strings lines]Fòô òô\n fòô fò fò \n\r[/strings]"));
$this->assertEquals('["Fòô òô"," fòô fò fò ","fò"]', parsers()->shortcodes()->parse("(strings lines)Fòô òô\n fòô fò fò \n\r(/strings)"));
// md5
$this->assertEquals("01677e4c0ae5468b9b8b823487f14524", parsers()->shortcodes()->parse('[strings md5]Foo Bar[/strings]'));
$this->assertEquals("01677e4c0ae5468b9b8b823487f14524", parsers()->shortcodes()->parse('(strings md5)Foo Bar(/strings)'));
// move
$this->assertEquals("worldhello", parsers()->shortcodes()->parse('[strings move=0,5,10]helloworld[/strings]'));
$this->assertEquals("worldhello", parsers()->shortcodes()->parse('(strings move:0,5,10)helloworld(/strings)'));
// normalizeNewLines
$this->assertEquals("\n \n", parsers()->shortcodes()->parse("[strings normalizeNewLines]\r\n \r[/strings]"));
$this->assertEquals("\n \n", parsers()->shortcodes()->parse("(strings normalizeNewLines)\r\n \r(/strings)"));
// normalizeSpaces
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse("[strings normalizeSpaces]foo bar baz[/strings]"));
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse("(strings normalizeSpaces)foo bar baz(/strings)"));
// offsetExists
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings offsetExists=0]foo bar baz[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings offsetExists:0)foo bar baz(/strings)'));
// offsetGet
$this->assertEquals("f", parsers()->shortcodes()->parse('[strings offsetGet=0]foo bar baz[/strings]'));
$this->assertEquals("f", parsers()->shortcodes()->parse('(strings offsetGet:0)foo bar baz(/strings)'));
// padBoth
$this->assertEquals(" foo ", parsers()->shortcodes()->parse('[strings padBoth=9]foo[/strings]'));
$this->assertEquals(" foo ", parsers()->shortcodes()->parse('(strings padBoth:9)foo(/strings)'));
// padLeft
$this->assertEquals(" foo", parsers()->shortcodes()->parse('[strings padLeft=6]foo[/strings]'));
$this->assertEquals(" foo", parsers()->shortcodes()->parse('(strings padLeft:6)foo(/strings)'));
// padRight
$this->assertEquals("foo ", parsers()->shortcodes()->parse('[strings padRight=6]foo[/strings]'));
$this->assertEquals("foo ", parsers()->shortcodes()->parse('(strings padRight:6)foo(/strings)'));
// quotesToEntities
$this->assertEquals("&quot;foo&quot;", parsers()->shortcodes()->parse('[strings quotesToEntities]"foo"[/strings]'));
$this->assertEquals("&quot;foo&quot;", parsers()->shortcodes()->parse('(strings quotesToEntities)"foo"(/strings)'));
// random
$test1 = parsers()->shortcodes()->parse('[strings random /]');
$test2 = parsers()->shortcodes()->parse('[strings random=10 /]');
$test3 = parsers()->shortcodes()->parse('[strings random=4,1234 /]');
$test1 = parsers()->shortcodes()->parse('(strings random /)');
$test2 = parsers()->shortcodes()->parse('(strings random:10 /)');
$test3 = parsers()->shortcodes()->parse('(strings random:4,1234 /)');
$this->assertEquals(64, strings($test1)->length());
$this->assertEquals(10, strings($test2)->length());
$this->assertEquals(4, strings($test3)->length());
// reduceSlashes
$this->assertEquals("foo/bar/baz", parsers()->shortcodes()->parse('[strings reduceSlashes]foo//bar/baz[/strings]'));
$this->assertEquals("foo/bar/baz", parsers()->shortcodes()->parse('(strings reduceSlashes)foo//bar/baz(/strings)'));
// repeat
$this->assertEquals("foofoofoo", parsers()->shortcodes()->parse('[strings repeat=3]foo[/strings]'));
$this->assertEquals("foofoofoo", parsers()->shortcodes()->parse('(strings repeat:3)foo(/strings)'));
// replace
$this->assertEquals("bar baz", parsers()->shortcodes()->parse('[strings replace=foo,bar]foo baz[/strings]'));
$this->assertEquals("bar baz", parsers()->shortcodes()->parse('(strings replace:foo,bar)foo baz(/strings)'));
// replaceDashes
$this->assertEquals("foobarbaz", parsers()->shortcodes()->parse('[strings replaceDashes]foo-bar-baz[/strings]'));
$this->assertEquals("foo_bar_baz", parsers()->shortcodes()->parse('[strings replaceDashes="_"]foo-bar-baz[/strings]'));
$this->assertEquals("foobarbaz", parsers()->shortcodes()->parse('(strings replaceDashes)foo-bar-baz(/strings)'));
$this->assertEquals("foo_bar_baz", parsers()->shortcodes()->parse('(strings replaceDashes:"_")foo-bar-baz(/strings)'));
// replaceFirst
$this->assertEquals("bar foo bar", parsers()->shortcodes()->parse('[strings replaceFirst=foo,bar]foo foo bar[/strings]'));
$this->assertEquals("bar foo bar", parsers()->shortcodes()->parse('(strings replaceFirst:foo,bar)foo foo bar(/strings)'));
// replaceLast
$this->assertEquals("foo bar bar", parsers()->shortcodes()->parse('[strings replaceLast=foo,bar]foo foo bar[/strings]'));
$this->assertEquals("foo bar bar", parsers()->shortcodes()->parse('(strings replaceLast:foo,bar)foo foo bar(/strings)'));
// replaceNonAlpha
$this->assertEquals("foo baz bar", parsers()->shortcodes()->parse('[strings replaceNonAlpha]foo 123 baz 345 bar[/strings]'));
$this->assertEquals("foo baz bar", parsers()->shortcodes()->parse('(strings replaceNonAlpha)foo 123 baz 345 bar(/strings)'));
// replaceNonAlphanumeric
$this->assertEquals("Fòôbàřs123", parsers()->shortcodes()->parse('[strings replaceNonAlphanumeric]Fòô-bàřs-123[/strings]'));
$this->assertEquals("Fòôbàřs123", parsers()->shortcodes()->parse('(strings replaceNonAlphanumeric)Fòô-bàřs-123(/strings)'));
// replacePunctuations
$this->assertEquals("foo 123 baz 345 bar", parsers()->shortcodes()->parse('[strings replacePunctuations]foo 123, baz, 345 bar[/strings]'));
$this->assertEquals("foo 123 baz 345 bar", parsers()->shortcodes()->parse('(strings replacePunctuations)foo 123, baz, 345 bar(/strings)'));
// reverse
$this->assertEquals("oof", parsers()->shortcodes()->parse('[strings reverse]foo[/strings]'));
$this->assertEquals("oof", parsers()->shortcodes()->parse('(strings reverse)foo(/strings)'));
// segement
$this->assertEquals("foo", parsers()->shortcodes()->parse('[strings segment=0]foo bar baz[/strings]'));
$this->assertEquals("foo", parsers()->shortcodes()->parse('[strings segment="0,/"]foo/bar/baz[/strings]'));
$this->assertEquals("foo", parsers()->shortcodes()->parse('(strings segment:0)foo bar baz(/strings)'));
$this->assertEquals("foo", parsers()->shortcodes()->parse('(strings segment:"0,/")foo/bar/baz(/strings)'));
// segements
$this->assertEquals('["foo","bar","baz"]', parsers()->shortcodes()->parse('[strings segments]foo bar baz[/strings]'));
$this->assertEquals('["foo","bar","baz"]', parsers()->shortcodes()->parse('(strings segments)foo bar baz(/strings)'));
// sha1
$this->assertEquals("5cb8681884af2923487a6034d8dbe753828e2660", parsers()->shortcodes()->parse('[strings sha1]Foo Bar[/strings]'));
$this->assertEquals("5cb8681884af2923487a6034d8dbe753828e2660", parsers()->shortcodes()->parse('(strings sha1)Foo Bar(/strings)'));
// sha256
$this->assertEquals("55282c18206b9beb9998f5eaa15b85c9388463965678af5209e2cc3a3ff5b947", parsers()->shortcodes()->parse('[strings sha256]Foo Bar[/strings]'));
$this->assertEquals("55282c18206b9beb9998f5eaa15b85c9388463965678af5209e2cc3a3ff5b947", parsers()->shortcodes()->parse('(strings sha256)Foo Bar(/strings)'));
// shuffle
$this->assertEquals(9, strings(parsers()->shortcodes()->parse('[strings shuffle]123456890[/strings]'))->length());
$this->assertEquals(9, strings(parsers()->shortcodes()->parse('(strings shuffle)123456890(/strings)'))->length());
// similarity
$this->assertEquals(100, parsers()->shortcodes()->parse('[strings similarity=foo]foo[/strings]'));
$this->assertEquals(100, parsers()->shortcodes()->parse('(strings similarity:foo)foo(/strings)'));
// snake
$this->assertEquals("foo_bar", parsers()->shortcodes()->parse('[strings snake]fooBar[/strings]'));
$this->assertEquals("foo_bar", parsers()->shortcodes()->parse('(strings snake)fooBar(/strings)'));
// start
$this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('[strings start="/"]movies/sg-1/season-5/episode-21/[/strings]'));
$this->assertEquals("/movies/sg-1/season-5/episode-21/", parsers()->shortcodes()->parse('(strings start:"/")movies/sg-1/season-5/episode-21/(/strings)'));
// startsWith
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings startsWith="/"]/foo/[/strings]'));
$this->assertEquals("true", parsers()->shortcodes()->parse('(strings startsWith:"/")/foo/(/strings)'));
// stripQuotes
$this->assertEquals("some text here", parsers()->shortcodes()->parse('[strings stripQuotes]some "text" here[/strings]'));
$this->assertEquals("some text here", parsers()->shortcodes()->parse('(strings stripQuotes)some "text" here(/strings)'));
// stripSpaces
$this->assertEquals("foobarbaz", parsers()->shortcodes()->parse('[strings stripSpaces]foo bar baz[/strings]'));
$this->assertEquals("foobarbaz", parsers()->shortcodes()->parse('(strings stripSpaces)foo bar baz(/strings)'));
// studly
$this->assertEquals("FooBar", parsers()->shortcodes()->parse('[strings studly]foo_bar[/strings]'));
$this->assertEquals("FooBar", parsers()->shortcodes()->parse('(strings studly)foo_bar(/strings)'));
// substr
$this->assertEquals("bar baz", parsers()->shortcodes()->parse('[strings substr=4]foo bar baz[/strings]'));
$this->assertEquals("bar baz", parsers()->shortcodes()->parse('(strings substr:4)foo bar baz(/strings)'));
// trim
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('[strings trim] foo bar baz [/strings]'));
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('(strings trim) foo bar baz (/strings)'));
// trimLeft
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('[strings trimLeft] foo bar baz[/strings]'));
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('(strings trimLeft) foo bar baz(/strings)'));
// trimRight
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('[strings trimRight]foo bar baz [/strings]'));
$this->assertEquals("foo bar baz", parsers()->shortcodes()->parse('(strings trimRight)foo bar baz (/strings)'));
// trimSlashes
$this->assertEquals("foo/bar/baz", parsers()->shortcodes()->parse('[strings trimSlashes]/foo/bar/baz/[/strings]'));
$this->assertEquals("foo/bar/baz", parsers()->shortcodes()->parse('(strings trimSlashes)/foo/bar/baz/(/strings)'));
// ucfirst
$this->assertEquals("Foo", parsers()->shortcodes()->parse('[strings ucfirst]foo[/strings]'));
$this->assertEquals("Foo", parsers()->shortcodes()->parse('(strings ucfirst)foo(/strings)'));
// wordsCount
$this->assertEquals(3, parsers()->shortcodes()->parse('[strings wordsCount]foo bar baz[/strings]'));
$this->assertEquals(3, parsers()->shortcodes()->parse('(strings wordsCount)foo bar baz(/strings)'));
// words
$this->assertEquals('["foo","bar","baz"]', parsers()->shortcodes()->parse('[strings words]foo bar baz[/strings]'));
$this->assertEquals('["foo","bar","baz"]', parsers()->shortcodes()->parse('(strings words)foo bar baz(/strings)'));
// wordsFrequency
$this->assertEquals('{"foo":"33.33","bar":"33.33","baz":"33.33"}', parsers()->shortcodes()->parse('[strings wordsFrequency]foo bar baz[/strings]'));
$this->assertEquals('{"foo":"33.33","bar":"33.33","baz":"33.33"}', parsers()->shortcodes()->parse('(strings wordsFrequency)foo bar baz(/strings)'));
});

View File

@@ -4,5 +4,5 @@ declare(strict_types=1);
test('[textile] shortcode', function () {
$this->assertEquals("<p><b>Foo</b></p>",
parsers()->shortcodes()->parse('[textile]**Foo**[/textile]'));
parsers()->shortcodes()->parse('(textile)**Foo**(/textile)'));
});

View File

@@ -2,26 +2,26 @@
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]'));
$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]'));
$this->assertStringContainsString('/foo/', parsers()->shortcodes()->parse('(getBasePath)'));
});
test('[getAbsoluteUrl] shortcode', function () {
$this->assertStringContainsString('/', parsers()->shortcodes()->parse('[getAbsoluteUrl]'));
test('(getAbsoluteUrl) shortcode', function () {
$this->assertStringContainsString('/', parsers()->shortcodes()->parse('(getAbsoluteUrl)'));
});
test('[getUriString] shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse('[getUriString]'));
test('(getUriString) shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse('(getUriString)'));
});
test('[urlFor] shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse('[urlFor routeName="test-route" queryParams=\'{"foo": "Foo"}\']'));
test('(urlFor) shortcode', function () {
$this->assertStringContainsString('', parsers()->shortcodes()->parse('(urlFor routeName="test-route" queryParams=\'{"foo": "Foo"}\')'));
});

View File

@@ -2,9 +2,9 @@
declare(strict_types=1);
test('[uuid1-4] shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('[uuid1]'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('[uuid2]'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('[uuid3]'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('[uuid4]'))->length() > 0)->toBeTrue();
test('(uuid1-4) shortcode', function () {
expect(strings(parsers()->shortcodes()->parse('(uuid1)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid2)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid3)'))->length() > 0)->toBeTrue();
expect(strings(parsers()->shortcodes()->parse('(uuid4)'))->length() > 0)->toBeTrue();
});

View File

@@ -20,22 +20,22 @@ test('add shortcodes event handler', function () {
return 'Barz';
});
parsers()->shortcodes()->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['barz']));
$this->assertEquals('Barz', parsers()->shortcodes()->parse('[barz]'));
$this->assertEquals('Barz', parsers()->shortcodes()->parse('(barz)'));
});
test('parse text', function () {
$this->assertInstanceOf(Thunder\Shortcode\ShortcodeFacade::class, parsers()->shortcodes()->addHandler('bar', static function() { return ''; }));
$this->assertTrue(is_array(parsers()->shortcodes()->parseText('[bar]')));
$this->assertTrue(is_object(parsers()->shortcodes()->parseText('[bar]')[0]));
$this->assertTrue(is_array(parsers()->shortcodes()->parseText('(bar)')));
$this->assertTrue(is_object(parsers()->shortcodes()->parseText('(bar)')[0]));
});
test('parse shortcodes', function () {
$this->assertInstanceOf(Thunder\Shortcode\ShortcodeFacade::class, parsers()->shortcodes()->addHandler('zed', static function() { return 'Zed'; }));
$this->assertEquals('Zed', parsers()->shortcodes()->parse('[zed]'));
$this->assertEquals('fòôBàřZed', parsers()->shortcodes()->parse('fòôBàř[zed]'));
$this->assertEquals('Zed', parsers()->shortcodes()->parse('(zed)'));
$this->assertEquals('fòôBàřZed', parsers()->shortcodes()->parse('fòôBàř(zed)'));
});
test('get cache ID', function () {
$this->assertNotEquals(parsers()->shortcodes()->getCacheID('fòôBàř[bar]'),
parsers()->shortcodes()->getCacheID('fòôBàř[foo]'));
$this->assertNotEquals(parsers()->shortcodes()->getCacheID('fòôBàř(bar)'),
parsers()->shortcodes()->getCacheID('fòôBàř(foo)'));
});