Permalink
Browse files

BUGFIX: Fixing tests

ENHANCEMENT: Add <%-- --%> comments

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@66946 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 3d5600c commit c7a4afee52eeee719f9455694317cf8c6e22924c @sminnee sminnee committed Nov 28, 2008
Showing with 18 additions and 9 deletions.
  1. +1 −0 core/SSViewer.php
  2. +1 −3 core/model/ComponentSet.php
  3. +4 −4 tests/ControllerTest.php
  4. +12 −2 tests/SSViewerTest.php
View
1 core/SSViewer.php
@@ -373,6 +373,7 @@ static function parseTemplateContent($content, $template="") {
// $val, $val.property, $val(param), etc.
$replacements = array(
+ '/<%--.*--%>/U' => '',
'/\$Iteration/' => '<?= {dlr}key ?>',
'/{\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+)}/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->obj("\\4",null,true)->XML_val("\\5",null,true) ?>',
'/{\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)}/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->XML_val("\\4",null,true) ?>',
View
4 core/model/ComponentSet.php
@@ -96,9 +96,7 @@ function add($item, $extraFields = null) {
$item = DataObject::get_by_id($this->childClass, $item);
- if(!isset($item)) {
- return;
- }
+ if(!$item) return;
}
// If we've already got a database object, then update the database
View
8 tests/ControllerTest.php
@@ -6,24 +6,24 @@ class ControllerTest extends SapphireTest {
function testDefaultAction() {
/* For a controller with a template, the default action will simple run that template. */
$response = Director::test("ControllerTest_Controller/");
- $this->assertEquals("This is the main template. Content is 'default content'.", $response->getBody());
+ $this->assertRegExp("/This is the main template. Content is 'default content'/", $response->getBody());
}
function testMethodActions() {
/* The Action can refer to a method that is called on the object. If a method returns an array, then it will be
used to customise the template data */
$response = Director::test("ControllerTest_Controller/methodaction");
- $this->assertEquals("This is the main template. Content is 'methodaction content'.", $response->getBody());
+ $this->assertRegExp("/This is the main template. Content is 'methodaction content'./", $response->getBody());
/* If the method just returns a string, then that will be used as the response */
$response = Director::test("ControllerTest_Controller/stringaction");
- $this->assertEquals("stringaction was called.", $response->getBody());
+ $this->assertRegExp("/stringaction was called./", $response->getBody());
}
function testTemplateActions() {
/* If there is no method, it can be used to point to an alternative template. */
$response = Director::test("ControllerTest_Controller/templateaction");
- $this->assertEquals("This is the template for templateaction. Content is 'default content'.", $response->getBody());
+ $this->assertRegExp("/This is the template for templateaction. Content is 'default content'./", $response->getBody());
}
function testAllowedActions() {
View
14 tests/SSViewerTest.php
@@ -10,7 +10,7 @@ function testTemplateWithoutHeadRenders() {
));
$result = $data->renderWith("SSViewerTestPartialTemplate");
- $this->assertEquals('Test partial template: var value', $result);
+ $this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U",'',$result)));
}
function testRequirements() {
@@ -33,4 +33,14 @@ function testRequirements() {
$template = $viewer->process($data);
$this->assertFalse((bool)trim($template), "Should be no content in this return.");
}
-}
+
+ function testComments() {
+ $viewer = SSViewer::fromString(<<<SS
+This is my template<%-- this is a comment --%>This is some content<%-- this is another comment --%>This is the final content
+SS
+);
+ $output = $viewer->process(new ArrayData(array()));
+
+ $this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?<!--.*-->\n?/U",'',$output));
+ }
+}

0 comments on commit c7a4afe

Please sign in to comment.