Skip to content

Commit

Permalink
MINOR SSViewer->testCastingHelpers()
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Feb 29, 2012
1 parent da879da commit 68914ef
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/view/SSViewerTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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}";
}
Expand Down
3 changes: 3 additions & 0 deletions tests/view/ViewableDataTest.php
@@ -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
*/
Expand Down

0 comments on commit 68914ef

Please sign in to comment.