MINOR SSViewer->testCastingHelpers()

This commit is contained in:
Ingo Schommer 2012-02-29 20:35:48 +01:00
parent da879da940
commit 68914efb8d
2 changed files with 68 additions and 0 deletions

View File

@ -364,6 +364,65 @@ after')
$this->assertEquals(preg_replace('/\s+/', '', $a), preg_replace('/\s+/', '', $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 * Test $Up works when the scope $Up refers to was entered with a "with" block
*/ */
@ -677,6 +736,12 @@ class SSViewerTestFixture extends ViewableData {
} }
class SSViewerTest_ViewableData extends ViewableData implements TestOnly { class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
public static $casting = array(
'TextValue' => 'Text',
'HTMLValue' => 'HTMLText'
);
function methodWithOneArgument($arg1) { function methodWithOneArgument($arg1) {
return "arg1:{$arg1}"; return "arg1:{$arg1}";
} }

View File

@ -1,5 +1,8 @@
<?php <?php
/** /**
* See {@link SSViewerTest->testCastingHelpers()} for more tests related to casting and ViewableData behaviour,
* from a template-parsing perspective.
*
* @package sapphire * @package sapphire
* @subpackage tests * @subpackage tests
*/ */