1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 21:26:48 +02:00

feat(shortcodes): [strings] shortcode - add containsAny modifier

This commit is contained in:
Awilum
2022-05-05 08:22:19 +03:00
parent 385b1c9f23
commit 336f2c5daa
2 changed files with 10 additions and 0 deletions

View File

@@ -122,6 +122,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
$content = strings($content)->{'containsAll'}(isset($vars[0]) ? explode($itemsDelimeter, $vars[0]) : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false";
}
if ($key == 'containsAny') {
$content = strings($content)->{'containsAny'}(isset($vars[0]) ? explode($itemsDelimeter, $vars[0]) : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false";
}
if ($key == 'count') {
$content = (string) strings($content)->{'count'}();
}

View File

@@ -72,6 +72,12 @@ test('[strings] shortcode', function () {
$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]'));
// count
$this->assertEquals(49, parsers()->shortcodes()->parse('[strings count]SG-1 returns from an off-world mission to P9Y-3C3[/strings]'));