CommentTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. class CommentTest extends WebTestCase
  3. {
  4. /**
  5. * We use both 'Post' and 'Comment' fixtures.
  6. * @see CWebTestCase::fixtures
  7. */
  8. public $fixtures=array(
  9. 'posts'=>'Post',
  10. 'comments'=>'Comment',
  11. );
  12. public function testCreate()
  13. {
  14. $this->open('post/1/xyz');
  15. // verify the sample post title exists
  16. $this->assertTextPresent($this->posts['sample1']['title']);
  17. $this->assertElementPresent("name=Comment[author]");
  18. // verify validation errors
  19. $this->clickAndWait("//input[@value='Submit']");
  20. $this->assertTextPresent('Name cannot be blank.');
  21. $this->assertTextPresent('Email cannot be blank.');
  22. $this->assertTextPresent('Comment cannot be blank.');
  23. // verify commenting is successful
  24. $comment="comment 1";
  25. $this->type('name=Comment[author]','me');
  26. $this->type('name=Comment[email]','me@example.com');
  27. $this->type('name=Comment[content]',$comment);
  28. $this->clickAndWait("//input[@value='Submit']");
  29. $this->assertTextPresent('Thank you for your comment');
  30. }
  31. }