mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR SSViewer->testCastingHelpers()
This commit is contained in:
parent
da879da940
commit
68914efb8d
@ -364,6 +364,65 @@ after')
|
||||
$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(
|
||||
'<b>html</b>',
|
||||
$t = SSViewer::fromString('$TextValue')->process($vd)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'<b>html</b>',
|
||||
$t = SSViewer::fromString('$TextValue.RAW')->process($vd)
|
||||
);
|
||||
$this->assertEquals(
|
||||
'<b>html</b>',
|
||||
$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(
|
||||
'<b>html</b>',
|
||||
$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(
|
||||
'<b>html</b>',
|
||||
$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 @@ class SSViewerTestFixture extends ViewableData {
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user