2008-07-21 13:59:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SSViewerTest extends SapphireTest {
|
|
|
|
/**
|
|
|
|
* Test that a template without a <head> tag still renders.
|
|
|
|
*/
|
|
|
|
function testTemplateWithoutHeadRenders() {
|
|
|
|
$data = new ArrayData(array(
|
|
|
|
'Var' => 'var value'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $data->renderWith("SSViewerTestPartialTemplate");
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertEquals('Test partial template: var value', trim(preg_replace("/<!--.*-->/U",'',$result)));
|
2008-07-21 13:59:24 +02:00
|
|
|
}
|
2008-11-10 02:01:55 +01:00
|
|
|
|
|
|
|
function testRequirements() {
|
|
|
|
$requirements = $this->getMock("Requirements_Backend", array("javascript", "css"));
|
|
|
|
$jsFile = 'sapphire/tests/forms/a.js';
|
|
|
|
$cssFile = 'sapphire/tests/forms/a.js';
|
|
|
|
|
|
|
|
$requirements->expects($this->once())->method('javascript')->with($jsFile);
|
|
|
|
$requirements->expects($this->once())->method('css')->with($cssFile);
|
|
|
|
|
2008-11-10 02:13:42 +01:00
|
|
|
Requirements::set_backend($requirements);
|
2008-11-10 02:01:55 +01:00
|
|
|
|
|
|
|
$data = new ArrayData(array());
|
|
|
|
|
|
|
|
$viewer = SSViewer::fromString(<<<SS
|
|
|
|
<% require javascript($jsFile) %>
|
|
|
|
<% require css($cssFile) %>
|
|
|
|
SS
|
|
|
|
);
|
|
|
|
$template = $viewer->process($data);
|
|
|
|
$this->assertFalse((bool)trim($template), "Should be no content in this return.");
|
|
|
|
}
|
2008-11-14 04:43:26 +01:00
|
|
|
|
|
|
|
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()));
|
|
|
|
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?<!--.*-->\n?/U",'',$output));
|
2008-11-14 04:43:26 +01:00
|
|
|
}
|
2009-01-04 23:20:36 +01:00
|
|
|
|
|
|
|
function testObjectDotArguments() {
|
|
|
|
// one argument
|
|
|
|
$viewer = SSViewer::fromString(<<<SS
|
|
|
|
\$TestObject.methodWithOneArgument(one)
|
|
|
|
SS
|
|
|
|
);
|
|
|
|
$obj = new SSViewerTest_ViewableData();
|
|
|
|
$this->assertEquals(
|
|
|
|
$viewer->process(new ArrayData(array('TestObject'=>$obj))),
|
|
|
|
"arg1:one",
|
|
|
|
"Object method calls in dot notation work with one argument"
|
|
|
|
);
|
|
|
|
|
|
|
|
// two arguments
|
|
|
|
$viewer = SSViewer::fromString(<<<SS
|
|
|
|
\$TestObject.methodWithTwoArguments(one,two)
|
|
|
|
SS
|
|
|
|
);
|
|
|
|
$obj = new SSViewerTest_ViewableData();
|
|
|
|
$this->assertEquals(
|
|
|
|
$viewer->process(new ArrayData(array('TestObject'=>$obj))),
|
|
|
|
"arg1:one,arg2:two",
|
|
|
|
"Object method calls in dot notation work with two arguments"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
|
|
|
function methodWithOneArgument($arg1) {
|
|
|
|
return "arg1:{$arg1}";
|
|
|
|
}
|
|
|
|
|
|
|
|
function methodWithTwoArguments($arg1, $arg2) {
|
|
|
|
return "arg1:{$arg1},arg2:{$arg2}";
|
|
|
|
}
|
2008-07-21 13:59:24 +02:00
|
|
|
}
|