Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Solved] Templates for functional tests

Go to End

2 Posts   1338 Views

Capt. Morgan

Community Member, 30 Posts

28 July 2010 at 3:31am

Edited: 30/09/2010 3:38am

I have had problems when writing functional tests using Director::test()
Because the test made for a shared module needs to be independent of theme templates I want to force it to use a template in the module. But because theme templates overrides the module template my tests does not know what to expect.

Did anyone face the same problem and come up with a solution?

Capt. Morgan

Community Member, 30 Posts

30 September 2010 at 3:37am

A collegue had this simple but brilliant idea when working on something entirely different.
By setting theme in SSViewer to null during test setup we force Director::test() to use eigther the template in the tested module or in mysite. Given that we're testing ajax or a pagetype of course.

public function setUp() {
  SSViewer::set_theme( null );

public function tearDown() {
  SSViewer::set_theme( SSViewer::current_custom_theme() );

public function testTemplate() {
  $responseByTemplateInModule = Director::test("/mypage");