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

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

This commit is contained in:
Awilum
2022-05-05 08:21:05 +03:00
parent 0fe947395c
commit 385b1c9f23
2 changed files with 14 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
$content = $s->getContent();
$varsDelimeter = $s->getParameter('varsDelimeter') ?: '|';
$itemsDelimeter = $s->getParameter('itemsDelimeter') ?: ',';
foreach($s->getParameters() as $key => $value) {
@@ -114,7 +115,11 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
}
if ($key == 'contains') {
$content = strings($content)->{'contains'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false";
$content = strings($content)->{'contains'}(isset($vars[0]) ? explode($itemsDelimeter, $vars[0]) : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false";
}
if ($key == 'containsAll') {
$content = strings($content)->{'containsAll'}(isset($vars[0]) ? explode($itemsDelimeter, $vars[0]) : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false";
}
if ($key == 'count') {

View File

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