Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Page;
- use AcceptanceTester;
- /** Он не абстрактный */
- abstract class BasePage {
- /** Я бы сделал все поля протектед и переопределял все в конструкторе классов , которые extends делают от него */
- private $url = 'about:blank';
- private $tester = NULL;
- private $labels = NULL;
- private $inputs = NULL;
- private $buttons = NULL;
- private $checkbox = NULL;
- protected static $timeout = 10;
- /** нет типизации для url */
- public function __construct(AcceptanceTester $tester, $url) {
- $this->tester = $tester;
- $this->url = $url;
- }
- /** нет типизации */
- public static function setTimeout($timeout) {
- static::$timeout = $timeout;
- }
- /** нет типизации */
- public function setLabels($labels) {
- if ($labels)
- $this->labels = $labels;
- }
- /** нет типизации */
- public function setInputs($inputs) {
- if ($inputs)
- $this->inputs = $inputs;
- }
- /** нет типизации */
- public function setButtons($buttons) {
- if ($buttons)
- $this->buttons = $buttons;
- }
- /** нет типизации */
- public function setCheckbox($checkbox) {
- if ($checkbox)
- $this->checkbox = $checkbox;
- }
- /** нет типизации */
- public function getUrl() {
- return $this->url;
- }
- /** нет типизации */
- public function getTester() {
- return $this->tester;
- }
- /** нет типизации */
- public function openPage() {
- $this->tester->amOnUrl($this->url);
- return $this;
- }
- /** нет типизации */
- public function openAndVerifyPage() {
- $this->openPage();
- $this->verifyPage();
- return $this;
- }
- public function verifyPage() {
- if (!is_null($this->labels))
- foreach ($this->labels as $key => $value) {
- if ($this->checkVisibleGroup($value))
- $this->tester->waitForText($value[0], static::$timeout);
- }
- if (!is_null($this->inputs))
- foreach ($this->inputs as $key => $value) {
- if ($this->checkVisibleGroup($value))
- $this->tester->waitForElement($value[0], static::$timeout);
- }
- if (!is_null($this->buttons))
- foreach ($this->buttons as $key => $value) {
- if ($this->checkVisibleGroup($value))
- $this->tester->waitForElement($value[0], static::$timeout);
- }
- $this->checkUrl();
- }
- public function checkUrl() {
- $actual = $this->tester->getCurrentUrl();
- $this->tester->assertEquals($this->url, $actual);
- }
- /** все протектед находяться до пабликов */
- protected function checkVisibleGroup($array): bool {
- if (sizeof($array) >= 2) {
- $groups = $array[1];
- if (!is_null($groups)) {
- for ($i = 0; $i < sizeof($groups); $i++) {
- if ($this->tester->checkUserGroup(new Login\Groups($groups[$i])))
- return TRUE;
- }
- } else
- return TRUE;
- return FALSE;
- } else
- return TRUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement