Permalink
Browse files

MINOR SSViewer->testCastingHelpers()

  • Loading branch information...
1 parent da879da commit 68914efb8dcc19a2af5a0476eda08316509da99c @chillu chillu committed Feb 29, 2012
Showing with 68 additions and 0 deletions.
  1. +65 −0 tests/view/SSViewerTest.php
  2. +3 −0 tests/view/ViewableDataTest.php
@@ -363,6 +363,65 @@ function testRecursiveInclude() {
function assertEqualIgnoringWhitespace($a, $b) {
$this->assertEquals(preg_replace('/\s+/', '', $a), preg_replace('/\s+/', '', $b));
}
+
+ /**
+ * See {@link ViewableDataTest} for more extensive casting tests,
+ * this test just ensures that basic casting is correctly applied during template parsing.
+ */
+ function testCastingHelpers() {
+ $vd = new SSViewerTest_ViewableData();
+ $vd->TextValue = '<b>html</b>';
+ $vd->HTMLValue = '<b>html</b>';
+ $vd->UncastedValue = '<b>html</b>';
+
+ // Value casted as "Text"
+ $this->assertEquals(
+ '&lt;b&gt;html&lt;/b&gt;',
+ $t = SSViewer::fromString('$TextValue')->process($vd)
+ );
+ $this->assertEquals(
+ '<b>html</b>',
+ $t = SSViewer::fromString('$TextValue.RAW')->process($vd)
+ );
+ $this->assertEquals(
+ '&lt;b&gt;html&lt;/b&gt;',
+ $t = SSViewer::fromString('$TextValue.XML')->process($vd)
+ );
+
+ // Value casted as "HTMLText"
+ $this->assertEquals(
+ '<b>html</b>',
+ $t = SSViewer::fromString('$HTMLValue')->process($vd)
+ );
+ $this->assertEquals(
+ '<b>html</b>',
+ $t = SSViewer::fromString('$HTMLValue.RAW')->process($vd)
+ );
+ $this->assertEquals(
+ '&lt;b&gt;html&lt;/b&gt;',
+ $t = SSViewer::fromString('$HTMLValue.XML')->process($vd)
+ );
+
+ // Uncasted value (falls back to ViewableData::$default_cast="HTMLText")
+ $vd = new SSViewerTest_ViewableData(); // TODO Fix caching
+ $vd->UncastedValue = '<b>html</b>';
+ $this->assertEquals(
+ '<b>html</b>',
+ $t = SSViewer::fromString('$UncastedValue')->process($vd)
+ );
+ $vd = new SSViewerTest_ViewableData(); // TODO Fix caching
+ $vd->UncastedValue = '<b>html</b>';
+ $this->assertEquals(
+ '<b>html</b>',
+ $t = SSViewer::fromString('$UncastedValue.RAW')->process($vd)
+ );
+ $vd = new SSViewerTest_ViewableData(); // TODO Fix caching
+ $vd->UncastedValue = '<b>html</b>';
+ $this->assertEquals(
+ '&lt;b&gt;html&lt;/b&gt;',
+ $t = SSViewer::fromString('$UncastedValue.XML')->process($vd)
+ );
+ }
/**
* Test $Up works when the scope $Up refers to was entered with a "with" block
@@ -677,6 +736,12 @@ function hasValue($fieldName, $arguments = null) {
}
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
+
+ public static $casting = array(
+ 'TextValue' => 'Text',
+ 'HTMLValue' => 'HTMLText'
+ );
+
function methodWithOneArgument($arg1) {
return "arg1:{$arg1}";
}
@@ -1,5 +1,8 @@
<?php
/**
+ * See {@link SSViewerTest->testCastingHelpers()} for more tests related to casting and ViewableData behaviour,
+ * from a template-parsing perspective.
+ *
* @package sapphire
* @subpackage tests
*/

0 comments on commit 68914ef

Please sign in to comment.