mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add test for new modifiers and fix bugs
This commit is contained in:
parent
8e48d1aaee
commit
e6a9b511bd
@ -136,6 +136,9 @@ class Fenom
|
|||||||
"ereplace" => 'Fenom\Modifier::ereplace',
|
"ereplace" => 'Fenom\Modifier::ereplace',
|
||||||
"match" => 'Fenom\Modifier::match',
|
"match" => 'Fenom\Modifier::match',
|
||||||
"ematch" => 'Fenom\Modifier::ematch',
|
"ematch" => 'Fenom\Modifier::ematch',
|
||||||
|
"split" => 'Fenom\Modifier::split',
|
||||||
|
"esplit" => 'Fenom\Modifier::esplit',
|
||||||
|
"join" => 'Fenom\Modifier::join',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +255,7 @@ class Modifier
|
|||||||
*/
|
*/
|
||||||
public static function esplit($value, $pattern = '/,\s*/S')
|
public static function esplit($value, $pattern = '/,\s*/S')
|
||||||
{
|
{
|
||||||
if(is_string($pattern)) {
|
if(is_string($value)) {
|
||||||
return preg_split($pattern, $value);
|
return preg_split($pattern, $value);
|
||||||
} elseif(is_array($value)) {
|
} elseif(is_array($value)) {
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -119,4 +119,65 @@ class ModifiersTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testSplit()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if ["a", "b", "c"] === "a,b,c"|split:","}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSplitArray()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if ["a", "b", "c"] === ["a", "b", "c"]|split:","}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSplitOther()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if [] === true|split:","}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testESplit()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if ["a", "b", "c"] === "a:b:c"|esplit:"/:/"}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testESplitArray()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if ["a", "b", "c"] === ["a", "b", "c"]|esplit:"/:/"}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testESplitOther()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if [] === true|esplit:"/:/"}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReplace()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if "a;c" === "a,b,c"|replace:",b,":";"}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEReplace()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if "a;c" === "a,b,c"|ereplace:"/,b,?/miS":";"}equal{/if}');
|
||||||
|
$this->assertEquals("equal", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMatch()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if "a,b,c"|match:"a,[bd]*c":";"}match{/if}');
|
||||||
|
$this->assertEquals("match", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEMatch()
|
||||||
|
{
|
||||||
|
$tpl = $this->fenom->compileCode('{if "a,b,c"|ematch:"/^a,[bd].*?c$/":";"}match{/if}');
|
||||||
|
$this->assertEquals("match", $tpl->fetch(array()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user