mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: Applied patch from walec51 for <% control %> on empty set (#5579) Also added unit tests by ischommer (from r109127)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112785 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0bcb61f261
commit
634a3afeff
@ -507,17 +507,17 @@ class SSViewer {
|
|||||||
$content = ereg_replace('<!-- +pc_end +-->', '<' . '% end_control %' . '>', $content);
|
$content = ereg_replace('<!-- +pc_end +-->', '<' . '% end_control %' . '>', $content);
|
||||||
|
|
||||||
// < % control Foo % >
|
// < % control Foo % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1")) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", null, false)) foreach($loop as $key => $item) { ?>', $content);
|
||||||
// < % control Foo.Bar % >
|
// < % control Foo.Bar % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+) +%' . '>', '<? array_push($itemStack, $item); if(($loop = $item->obj("\\1")) && ($loop = $loop->obj("\\2"))) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+) +%' . '>', '<? array_push($itemStack, $item); if(($loop = $item->obj("\\1", null, false)) && ($loop = $loop->obj("\\2"))) foreach($loop as $key => $item) { ?>', $content);
|
||||||
// < % control Foo.Bar(Baz) % >
|
// < % control Foo.Bar(Baz) % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+)\\(([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if(($loop = $item->obj("\\1")) && ($loop = $loop->obj("\\2", array("\\3")))) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+)\\(([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if(($loop = $item->obj("\\1", null, false)) && ($loop = $loop->obj("\\2", array("\\3")))) foreach($loop as $key => $item) { ?>', $content);
|
||||||
// < % control Foo(Bar) % >
|
// < % control Foo(Bar) % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2"))) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2"), false)) foreach($loop as $key => $item) { ?>', $content);
|
||||||
// < % control Foo(Bar, Baz) % >
|
// < % control Foo(Bar, Baz) % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+), *([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2","\\3"))) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+), *([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2","\\3"), false)) foreach($loop as $key => $item) { ?>', $content);
|
||||||
// < % control Foo(Bar, Baz, Buz) % >
|
// < % control Foo(Bar, Baz, Buz) % >
|
||||||
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+), *([^),]+), *([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2", "\\3", "\\4"))) foreach($loop as $key => $item) { ?>', $content);
|
$content = ereg_replace('<' . '% +control +([A-Za-z0-9_]+)\\(([^),]+), *([^),]+), *([^),]+)\\) +%' . '>', '<? array_push($itemStack, $item); if($loop = $item->obj("\\1", array("\\2", "\\3", "\\4"), false)) foreach($loop as $key => $item) { ?>', $content);
|
||||||
$content = ereg_replace('<' . '% +end_control +%' . '>', '<? } $item = array_pop($itemStack); ?>', $content);
|
$content = ereg_replace('<' . '% +end_control +%' . '>', '<? } $item = array_pop($itemStack); ?>', $content);
|
||||||
$content = ereg_replace('<' . '% +debug +%' . '>', '<? Debug::show($item) ?>', $content);
|
$content = ereg_replace('<' . '% +debug +%' . '>', '<? Debug::show($item) ?>', $content);
|
||||||
$content = ereg_replace('<' . '% +debug +([A-Za-z0-9_]+) +%' . '>', '<? Debug::show($item->cachedCall("\\1")) ?>', $content);
|
$content = ereg_replace('<' . '% +debug +([A-Za-z0-9_]+) +%' . '>', '<? Debug::show($item->cachedCall("\\1")) ?>', $content);
|
||||||
|
@ -2,6 +2,67 @@
|
|||||||
|
|
||||||
class SSViewerTest extends SapphireTest {
|
class SSViewerTest extends SapphireTest {
|
||||||
|
|
||||||
|
function testControlBlockDataObjectSet() {
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
<% control TestSet %>
|
||||||
|
Test: \$TestValue
|
||||||
|
<% end_control %>
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$data = new ArrayData(array(
|
||||||
|
'TestSet' => new DataObjectSet(array(
|
||||||
|
new ArrayData(array(
|
||||||
|
'TestValue' => '1'
|
||||||
|
)),
|
||||||
|
new ArrayData(array(
|
||||||
|
'TestValue' => '2'
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
));
|
||||||
|
$out = $viewer->process($data);
|
||||||
|
$this->assertEquals('Test:1Test:2', str_replace(array(' ', "\t", PHP_EOL), '', $out));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testControlBlockNullValueDoesntLoop() {
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
<% control NullValue %>
|
||||||
|
notdisplayed
|
||||||
|
<% end_control %>
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$data = new ArrayData(array(
|
||||||
|
'NullValue' => null
|
||||||
|
));
|
||||||
|
$out = $viewer->process($data);
|
||||||
|
$this->assertNotContains('notdisplayed', str_replace(array(' ', "\t", PHP_EOL), '', $out));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testControlBlockFalseValueDoesntLoop() {
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
<% control FalseValue %>
|
||||||
|
notdisplayed
|
||||||
|
<% end_control %>
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$data = new ArrayData(array(
|
||||||
|
'FalseValue' => null
|
||||||
|
));
|
||||||
|
$out = $viewer->process($data);
|
||||||
|
$this->assertNotContains('notdisplayed', str_replace(array(' ', "\t", PHP_EOL), '', $out));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testControlBlockMethodReturningNullDoesntLoop() {
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
<% control methodNull %>
|
||||||
|
notdisplayed
|
||||||
|
<% end_control %>
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$data = new SSViewerTest_ViewableData();
|
||||||
|
$out = $viewer->process($data);
|
||||||
|
$this->assertNotContains('notdisplayed', str_replace(array(' ', "\t", PHP_EOL), '', $out));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SSViewer::current_theme()} for different behaviour
|
* Tests for {@link SSViewer::current_theme()} for different behaviour
|
||||||
* of user defined themes via {@link SiteConfig} and default theme
|
* of user defined themes via {@link SiteConfig} and default theme
|
||||||
@ -385,7 +446,7 @@ class SSViewerTestFixture extends ViewableData {
|
|||||||
return (bool)$this->XML_val($fieldName, $arguments);
|
return (bool)$this->XML_val($fieldName, $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
||||||
function methodWithOneArgument($arg1) {
|
function methodWithOneArgument($arg1) {
|
||||||
return "arg1:{$arg1}";
|
return "arg1:{$arg1}";
|
||||||
@ -394,5 +455,8 @@ class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
|||||||
function methodWithTwoArguments($arg1, $arg2) {
|
function methodWithTwoArguments($arg1, $arg2) {
|
||||||
return "arg1:{$arg1},arg2:{$arg2}";
|
return "arg1:{$arg1},arg2:{$arg2}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function methodNull() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
Loading…
Reference in New Issue
Block a user