【问题标题】:Silverstripe Tests Can't find page from fixtureSilverstripe 测试无法从夹具中找到页面
【发布时间】:2013-11-22 01:48:32
【问题描述】:

我不明白如何进行功能测试。

我想通过运行简单的功能测试开始:

class PageTest extends FunctionalTest{

  static $fixture_file = 'mysite/tests/PageTest.yml';

    public function testDirectorView() {
        $response1 = Director::test('/hello', null, null);               
        $this->assertTrue(
          strpos(
            $response1->getBody(), 
            '<h3>Hello World</h3>'
          ) !== false);        
    }  
}

使用以下夹具

Page:
    hello:
        Title: HelloWorld

但是我的测试失败并且响应正文显示我正在获取 404。

我怎样才能正确获得页面响应/设置夹具?

【问题讨论】:

    标签: testing silverstripe


    【解决方案1】:

    我会尝试以下方法

    class PageTest extends FunctionalTest{
    
    static $fixture_file = 'mysite/tests/PageTest.yml';
    
    static $use_draft_site = true;
    
    public function testDirectorView() {
        $page = $this->objFromFixture('Page','hello');
        $response1 = $this->get($page->RelativeLink());               
        $this->assertTrue(
          strpos(
            $response1->getBody(), 
            '<h3>Hello World</h3>'
          ) !== false);        
    }  
    }
    

    【讨论】:

    • 是的,做到了。很遗憾,我不能使用所有漂亮的“assertExactMatchBySelector”类型语法,因为我正在使用 mamp - 最终可能会转向更胡须的东西,比如适当的自制 php 安装。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 2013-09-10
    • 1970-01-01
    • 2017-05-23
    相关资源
    最近更新 更多