/phpmyadmin/test/selenium/PmaSeleniumDbEventsTest.php

https://gitlab.com/luyxtran264/myproject · PHP · 212 lines · 129 code · 33 blank · 50 comment · 0 complexity · 22a38571591d3db8a8100e82f5474684 MD5 · raw file

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Selenium TestCase for table related tests
  5. *
  6. * @package PhpMyAdmin-test
  7. * @subpackage Selenium
  8. */
  9. require_once 'TestBase.php';
  10. /**
  11. * PmaSeleniumDbEventsTest class
  12. *
  13. * @package PhpMyAdmin-test
  14. * @subpackage Selenium
  15. * @group selenium
  16. */
  17. class PMA_SeleniumDbEventsTest extends PMA_SeleniumBase
  18. {
  19. /**
  20. * Setup the browser environment to run the selenium test case
  21. *
  22. * @return void
  23. */
  24. public function setUp()
  25. {
  26. parent::setUp();
  27. $this->dbQuery(
  28. "CREATE TABLE `test_table` ("
  29. . " `id` int(11) NOT NULL AUTO_INCREMENT,"
  30. . " `val` int(11) NOT NULL,"
  31. . " PRIMARY KEY (`id`)"
  32. . ")"
  33. );
  34. $this->dbQuery(
  35. "INSERT INTO `test_table` (val) VALUES (2);"
  36. );
  37. }
  38. /**
  39. * setUp function that can use the selenium session (called before each test)
  40. *
  41. * @return void
  42. */
  43. public function setUpPage()
  44. {
  45. $this->login();
  46. $this->waitForElement('byLinkText', $this->database_name)->click();
  47. $this->waitForElement(
  48. "byXPath", "//a[contains(., 'test_table')]"
  49. );
  50. $this->expandMore();
  51. }
  52. /**
  53. * Creates procedure for tests
  54. *
  55. * @return void
  56. */
  57. private function _eventSQL()
  58. {
  59. $start = date('Y-m-d H:i:s', strtotime('-1 day'));
  60. $end = date('Y-m-d H:i:s', strtotime('+1 day'));
  61. $this->dbQuery(
  62. "CREATE EVENT `test_event` ON SCHEDULE EVERY 2 MINUTE_SECOND STARTS "
  63. . "'$start' ENDS '$end' ON COMPLETION NOT PRESERVE ENABLE "
  64. . "DO UPDATE `" . $this->database_name
  65. . "`.`test_table` SET val = val + 1"
  66. );
  67. }
  68. /**
  69. * Create an event
  70. *
  71. * @return void
  72. *
  73. * @group large
  74. */
  75. public function testAddEvent()
  76. {
  77. $ele = $this->waitForElement("byPartialLinkText", "Events");
  78. $ele->click();
  79. $ele = $this->waitForElement("byLinkText", "Add event");
  80. $ele->click();
  81. $this->waitForElement("byClassName", "rte_form");
  82. $this->byName("item_name")->value("test_event");
  83. $this->select($this->byName("item_type"))
  84. ->selectOptionByLabel("RECURRING");
  85. $this->byName("item_interval_value")->value("1");
  86. $this->select($this->byName("item_interval_field"))
  87. ->selectOptionByLabel("MINUTE_SECOND");
  88. $this->byName("item_starts")
  89. ->value(date('Y-m-d H:i:s', strtotime('-1 day')));
  90. $this->byName("item_ends")
  91. ->value(date('Y-m-d H:i:s', strtotime('+1 day')));
  92. $proc = "UPDATE " . $this->database_name . ".`test_table` SET val=val+1";
  93. $this->typeInTextArea($proc);
  94. $this->byXPath("//button[contains(., 'Go')]")->click();
  95. $ele = $this->waitForElement(
  96. "byXPath",
  97. "//div[@class='success' and contains(., "
  98. . "'Event `test_event` has been created')]"
  99. );
  100. $this->assertTrue(
  101. $this->isElementPresent(
  102. 'byXPath',
  103. "//td[contains(., 'test_event')]"
  104. )
  105. );
  106. $result = $this->dbQuery(
  107. "SHOW EVENTS WHERE Db='" . $this->database_name
  108. . "' AND Name='test_event'"
  109. );
  110. $this->assertEquals(1, $result->num_rows);
  111. usleep(2200000);
  112. $result = $this->dbQuery(
  113. "SELECT val FROM `" . $this->database_name . "`.`test_table`"
  114. );
  115. $row = $result->fetch_assoc();
  116. $this->assertGreaterThan(2, $row['val']);
  117. }
  118. /**
  119. * Test for editing events
  120. *
  121. * @return void
  122. *
  123. * @group large
  124. */
  125. public function testEditEvents()
  126. {
  127. $this->_eventSQL();
  128. $ele = $this->waitForElement("byPartialLinkText", "Events");
  129. $ele->click();
  130. $this->waitForElement(
  131. "byXPath",
  132. "//legend[contains(., 'Events')]"
  133. );
  134. $this->byLinkText("Edit")->click();
  135. $this->waitForElement("byClassName", "rte_form");
  136. $this->byName("item_interval_value")->clear();
  137. $this->byName("item_interval_value")->value("1");
  138. $this->typeInTextArea("00");
  139. $this->byXPath("//button[contains(., 'Go')]")->click();
  140. $ele = $this->waitForElement(
  141. "byXPath",
  142. "//div[@class='success' and contains(., "
  143. . "'Event `test_event` has been modified')]"
  144. );
  145. usleep(2000000);
  146. $result = $this->dbQuery(
  147. "SELECT val FROM `" . $this->database_name . "`.`test_table`"
  148. );
  149. $row = $result->fetch_assoc();
  150. $this->assertGreaterThan(100, $row['val']);
  151. }
  152. /**
  153. * Test for dropping event
  154. *
  155. * @return void
  156. *
  157. * @group large
  158. */
  159. public function testDropEvent()
  160. {
  161. $this->_eventSQL();
  162. $this->waitForElement("byPartialLinkText", "Events")->click();
  163. $this->waitForElement(
  164. "byXPath",
  165. "//legend[contains(., 'Events')]"
  166. );
  167. $this->byLinkText("Drop")->click();
  168. $this->waitForElement(
  169. "byXPath", "//button[contains(., 'OK')]"
  170. )->click();
  171. $this->waitForElement("byId", "nothing2display");
  172. usleep(1000000);
  173. $result = $this->dbQuery(
  174. "SHOW EVENTS WHERE Db='" . $this->database_name
  175. . "' AND Name='test_event'"
  176. );
  177. $this->assertEquals(0, $result->num_rows);
  178. }
  179. }