Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Page;
  4.  
  5. use AcceptanceTester;
  6.  
  7. /** Он не абстрактный */
  8. abstract class BasePage {
  9.  
  10. /** Я бы сделал все поля протектед и переопределял все в конструкторе классов , которые extends делают от него */
  11. private $url = 'about:blank';
  12. private $tester = NULL;
  13. private $labels = NULL;
  14. private $inputs = NULL;
  15. private $buttons = NULL;
  16. private $checkbox = NULL;
  17. protected static $timeout = 10;
  18.  
  19. /** нет типизации для url */
  20. public function __construct(AcceptanceTester $tester, $url) {
  21. $this->tester = $tester;
  22. $this->url = $url;
  23. }
  24.  
  25. /** нет типизации */
  26. public static function setTimeout($timeout) {
  27. static::$timeout = $timeout;
  28. }
  29.  
  30. /** нет типизации */
  31. public function setLabels($labels) {
  32. if ($labels)
  33. $this->labels = $labels;
  34. }
  35.  
  36. /** нет типизации */
  37. public function setInputs($inputs) {
  38. if ($inputs)
  39. $this->inputs = $inputs;
  40. }
  41.  
  42. /** нет типизации */
  43. public function setButtons($buttons) {
  44. if ($buttons)
  45. $this->buttons = $buttons;
  46. }
  47.  
  48. /** нет типизации */
  49. public function setCheckbox($checkbox) {
  50. if ($checkbox)
  51. $this->checkbox = $checkbox;
  52. }
  53.  
  54. /** нет типизации */
  55. public function getUrl() {
  56. return $this->url;
  57. }
  58.  
  59. /** нет типизации */
  60. public function getTester() {
  61. return $this->tester;
  62. }
  63.  
  64. /** нет типизации */
  65. public function openPage() {
  66. $this->tester->amOnUrl($this->url);
  67. return $this;
  68. }
  69.  
  70. /** нет типизации */
  71. public function openAndVerifyPage() {
  72. $this->openPage();
  73. $this->verifyPage();
  74. return $this;
  75. }
  76.  
  77. public function verifyPage() {
  78.  
  79. if (!is_null($this->labels))
  80. foreach ($this->labels as $key => $value) {
  81. if ($this->checkVisibleGroup($value))
  82. $this->tester->waitForText($value[0], static::$timeout);
  83. }
  84. if (!is_null($this->inputs))
  85. foreach ($this->inputs as $key => $value) {
  86. if ($this->checkVisibleGroup($value))
  87. $this->tester->waitForElement($value[0], static::$timeout);
  88. }
  89. if (!is_null($this->buttons))
  90. foreach ($this->buttons as $key => $value) {
  91. if ($this->checkVisibleGroup($value))
  92. $this->tester->waitForElement($value[0], static::$timeout);
  93. }
  94. $this->checkUrl();
  95. }
  96.  
  97. public function checkUrl() {
  98. $actual = $this->tester->getCurrentUrl();
  99. $this->tester->assertEquals($this->url, $actual);
  100. }
  101.  
  102. /** все протектед находяться до пабликов */
  103. protected function checkVisibleGroup($array): bool {
  104. if (sizeof($array) >= 2) {
  105. $groups = $array[1];
  106. if (!is_null($groups)) {
  107. for ($i = 0; $i < sizeof($groups); $i++) {
  108. if ($this->tester->checkUserGroup(new Login\Groups($groups[$i])))
  109. return TRUE;
  110. }
  111. } else
  112. return TRUE;
  113. return FALSE;
  114. } else
  115. return TRUE;
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement