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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

[Solved] Templates for functional tests


Go to End


2 Posts   1547 Views

Avatar
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?

Avatar
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");
}