2013-11-22 44 views
1

我不瞭解如何進行功能測試。銀條紋測試從夾具中找不到頁面

我想通過運行簡單的功能測試,以得到持續:

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

我怎樣才能正確得到頁面響應/設置夾具?

回答

3

我會嘗試以下

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);   
} 
} 
+0

是的是做到了。它的一個恥辱我不能使用所有漂亮的「assertExactMatchBySelector」類型語法,因爲我使用的是mamp--可能最終會轉移到更多的鬍子,就像一個正確的自制PHP安裝。非常感謝 – Will