Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » [Solved] Templates for functional tests

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

Page: 1
Go to End
Author Topic: 1045 Views
  • Capt. Morgan
    Avatar
    Community Member
    30 Posts

    [Solved] Templates for functional tests Link to this post

    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
    Avatar
    Community Member
    30 Posts

    Re: [Solved] Templates for functional tests Link to this post

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

    1045 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.