Theme;
$config->Theme = '';
$config->write();
SSViewer::set_theme('mytheme');
$this->assertEquals('mytheme', SSViewer::current_theme(), 'Current theme is the default - user has not defined one');
$config->Theme = 'myusertheme';
$config->write();
// Pretent to load the page
$c = new ContentController();
$c->handleRequest(new SS_HTTPRequest('GET', '/'));
$this->assertEquals('myusertheme', SSViewer::current_theme(), 'Current theme is a user defined one');
// Set the theme back to the original
$config->Theme = $oldTheme;
$config->write();
}
/**
* Test that a template without a
tag still renders.
*/
function testTemplateWithoutHeadRenders() {
$data = new ArrayData(array(
'Var' => 'var value'
));
$result = $data->renderWith("SSViewerTestPartialTemplate");
$this->assertEquals('Test partial template: var value', trim(preg_replace("//U",'',$result)));
}
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);
Requirements::set_backend($requirements);
$data = new ArrayData(array());
$viewer = SSViewer::fromString(<<
<% require css($cssFile) %>
SS
);
$template = $viewer->process($data);
$this->assertFalse((bool)trim($template), "Should be no content in this return.");
}
function testComments() {
$viewer = SSViewer::fromString(<<This is some content<%-- this is another comment --%>This is the final content
SS
);
$output = $viewer->process(new ArrayData(array()));
$this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?\n?/U",'',$output));
}
function testObjectDotArguments() {
// one argument
$viewer = SSViewer::fromString(<<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(<<assertEquals(
$viewer->process(new ArrayData(array('TestObject'=>$obj))),
"arg1:one,arg2:two",
"Object method calls in dot notation work with two arguments"
);
}
function testBaseTagGeneration() {
// XHTML wil have a closed base tag
$tmpl1 = SSViewer::fromString('
<% base_tag %>
test
');
$this->assertRegExp('/<\/head>/', $tmpl1->process(new ViewableData()));
// HTML4 and 5 will only have it for IE
$tmpl2 = SSViewer::fromString('
<% base_tag %>
test
');
$this->assertRegExp('/<\/head>/', $tmpl2->process(new ViewableData()));
$tmpl3 = SSViewer::fromString('
<% base_tag %>
test
');
$this->assertRegExp('/<\/head>/', $tmpl3->process(new ViewableData()));
// Check that the content negotiator converts to the equally legal formats
$negotiator = new ContentNegotiator();
$response = new SS_HTTPResponse($tmpl1->process(new ViewableData()));
$negotiator->html($response);
$this->assertRegExp('/<\/head>/', $response->getBody());
$response = new SS_HTTPResponse($tmpl1->process(new ViewableData()));
$negotiator->xhtml($response);
$this->assertRegExp('/<\/head>/', $response->getBody());
}
function testRewriteHashlinks() {
$oldRewriteHashLinks = SSViewer::getOption('rewriteHashlinks');
SSViewer::setOption('rewriteHashlinks', true);
// Emulate SSViewer::process()
$base = Convert::raw2att($_SERVER['REQUEST_URI']);
$tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinks_' . sha1(rand()) . '.ss';
// Note: SSViewer_FromString doesn't rewrite hash links.
file_put_contents($tmplFile, '
<% base_tag %>
InlineLink
$InsertedLink
');
$tmpl = new SSViewer($tmplFile);
$obj = new ViewableData();
$obj->InsertedLink = 'InsertedLink';
$result = $tmpl->process($obj);
$this->assertContains(
'InsertedLink',
$result
);
$this->assertContains(
'InlineLink',
$result
);
unlink($tmplFile);
SSViewer::setOption('rewriteHashlinks', $oldRewriteHashLinks);
}
function testRewriteHashlinksInPhpMode() {
$oldRewriteHashLinks = SSViewer::getOption('rewriteHashlinks');
SSViewer::setOption('rewriteHashlinks', 'php');
$tmplFile = TEMP_FOLDER . '/SSViewerTest_testRewriteHashlinksInPhpMode_' . sha1(rand()) . '.ss';
// Note: SSViewer_FromString doesn't rewrite hash links.
file_put_contents($tmplFile, '
<% base_tag %>
InlineLink
$InsertedLink
');
$tmpl = new SSViewer($tmplFile);
$obj = new ViewableData();
$obj->InsertedLink = 'InsertedLink';
$result = $tmpl->process($obj);
$this->assertContains(
'