Advertisement
geekdenz

SilverStripe Testing - Director::test not working as expect

Jul 15th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. -- mysite/tests/HomePageTest.yaml:
  2.  
  3. HomePage:
  4.     home:
  5.         Title: Home Page 12
  6.         Content: This is the content of home
  7.         URLSegment: home
  8.  
  9. -- mysite/tests/HomePageTest.php
  10. <?php
  11. class HomePageTest extends SapphireTest {
  12.     static $fixture_file = 'HomePageTest.yml';
  13.  
  14.     private $someVar = "nothing";
  15.     public function setUp() {
  16.         parent::setUp();
  17.         $this->someVar = "this is set in setUp";
  18.  
  19.     }
  20.     /**
  21.      * sample unit test with 3 assertions
  22.      */
  23.     public function testUnitHome() {
  24.         $fixture = "home";
  25.         $obj = $this->objFromFixture("HomePage", $fixture);
  26.         $this->assertEquals("Home Page 12", $obj->getTitle());
  27.         $this->assertEquals("this is set in setUp", $this->someVar);
  28.         $this->assertTrue(stripos($obj->getField('Content'), 'This is the content of home') !== false);
  29.     }
  30.  
  31.     /**
  32.      * sample functional test
  33.      */
  34.     public function testFunctionalHome() {
  35.         $response = Director::test('');
  36.         $body = $response->getBody();
  37.         $this->assertTrue(stripos($body, '<head>') !== false);
  38.     }
  39.  
  40.     /**
  41.      * functional test: see if js are there
  42.      */
  43.     public function testJsThere() {
  44.         $response = Director::test('home/');
  45.         $body = $response->getBody();
  46.         echo "\n\n". $body ."\n\n";
  47.         $jss = array(
  48.             '<script src="themes/bootstrap/js/bootstrap-modal.js"></script>',
  49.         );
  50.         foreach ($jss as $js) {
  51.             $this->assertTrue(stripos($body, $js) !== false);
  52.         }
  53.     }
  54. }
  55. ?>
  56.  
  57. OUTPUT:
  58. ...
  59. Page not found
  60. ...
  61.  
  62. 3 tests run: 3 passes, 0 failures, and 0 incomplete with 0 errors
  63.  
  64. EXPECTED:
  65. This is the content of home
  66. instead of
  67. Page not found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement