Advertisement
Guest User

commentsDao

a guest
Apr 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author Rich Murphy
  4. *
  5. * Unit tests for CommentsDAO.php
  6. *
  7. */
  8. class CommentsDAOTests extends UnitTestCase {
  9. private $pdoDbManager;
  10. private $commentsDAO;
  11. public function setUp() {
  12. require_once '../app/DB/pdoDbManager.php';
  13. require_once '../app/DB/DAOs/CommentsDAO.php';
  14.  
  15. $this->pdoDbManager = new pdoDbManager ();
  16. $this->pdoDbManager->openConnection ();
  17.  
  18. $this->commentsDAO = new CommentsDAO ( $this->pdoDbManager );
  19. }
  20.  
  21. /*
  22. * Test to create new comment
  23. *
  24. * eval: 1 new row should be created
  25. */
  26. public function testCreateComment() {
  27. $params = [
  28. "commented_date" => "2002-01-02",
  29. "content" => "Comment ID: " . $this->id,
  30. "user_id" => "1",
  31. "post_id" => "1"
  32. ];
  33.  
  34. $id = $this->commentsDAO->insert ( $params );
  35.  
  36. $this->assertNotEqual ( $id, 0 );
  37.  
  38. $this->commentsDAO->delete ( $id );
  39. }
  40.  
  41. /*
  42. * Test to read comment
  43. */
  44. public function testReadComment() {
  45. $params = [
  46. "commented_date" => "2002-01-02",
  47. "content" => "Comment ID: " . $this->id,
  48. "user_id" => "1",
  49. "post_id" => "1"
  50. ];
  51.  
  52. $id = $this->commentsDAO->insert ( $params );
  53.  
  54. // get comment by ID
  55. $resultComment = $this->commentsDAO->get ( $id );
  56.  
  57. $result = $resultComment [0] ["comment_id"];
  58.  
  59. $this->assertEqual ( $result, $id );
  60.  
  61. $this->commentsDAO->delete ( $id );
  62. }
  63.  
  64. /*
  65. * Test to update comment
  66. */
  67. public function testUpdateComment() {
  68. $userParams = [
  69. "user_id" => "1",
  70. "post_id" => "1",
  71. "commented_date" => "2013-01-04",
  72. "content" => "Firetrucks are better than tirefrucks."
  73. ];
  74.  
  75. $id = $this->commentsDAO->insert ( $userParams );
  76.  
  77. $params = [
  78. "commented_date" => "2012-01-02",
  79. "content" => "Updated content text again",
  80. "user_id" => "1",
  81. "post_id" => "1"
  82. ];
  83.  
  84. $result = $this->commentsDAO->update ( $params, $id );
  85.  
  86. $this->assertEqual ( $result, 1 );
  87.  
  88. $this->commentsDAO->delete ( $id );
  89. }
  90. /*
  91. * Test to delete comment
  92. */
  93. public function testDeleteComment() {
  94. $userParams = [
  95. "user_id" => "1",
  96. "post_id" => "1",
  97. "commented_date" => "2013-01-04",
  98. "content" => "Firetrucks are better than tirefrucks."
  99. ];
  100.  
  101. $id = $this->commentsDAO->insert ( $userParams );
  102.  
  103. $result = $this->commentsDAO->delete ( $id );
  104.  
  105. // expect delete to delete 0 rows
  106. $this->assertEqual ( $result, 1 );
  107. }
  108. public function tearDown() {
  109. $this->pdoDbManager->closeConnection ();
  110. $this->commentsDAO = NULL;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement