1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Codeception\Page; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class AbstractPage |
7
|
|
|
* @package ByTIC\Codeception\Page |
8
|
|
|
*/ |
9
|
|
|
abstract class AbstractPage |
10
|
|
|
{ |
11
|
|
|
public static $URL = null; |
12
|
|
|
|
13
|
|
|
// incl_Abstractude url of current page |
14
|
|
|
public static $basePath = ''; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Basic route example for your current URL |
18
|
|
|
* You can append any additional parameter to URL |
19
|
|
|
* and use it in tests like: Page\Edit::route('/123-post'); |
20
|
|
|
* |
21
|
|
|
* @param $param |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public static function route($param) |
25
|
|
|
{ |
26
|
|
|
return static::$URL.$param; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Codeception\Actor; |
31
|
|
|
*/ |
32
|
|
|
protected $acceptanceTester; |
33
|
|
|
|
34
|
|
|
public function __construct(\Codeception\Actor $I) |
35
|
|
|
{ |
36
|
|
|
$this->acceptanceTester = $I; |
37
|
|
|
|
38
|
|
|
$this->init(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function init() |
42
|
|
|
{ |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return \Codeception\Actor; |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
protected function getTester() |
49
|
|
|
{ |
50
|
|
|
return $this->acceptanceTester; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function haveErrorMessage() |
54
|
|
|
{ |
55
|
|
|
$this->getTester()->see('', 'div.alert-danger'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function getURL() |
59
|
|
|
{ |
60
|
|
|
return static::$basePath.static::$URL; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function loadPage() |
65
|
|
|
{ |
66
|
|
|
$this->getTester()->amOnPage(self::getURL()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function checkOnURL() |
73
|
|
|
{ |
74
|
|
|
$I = $this->getTester(); |
75
|
|
|
|
76
|
|
|
$pageURI = self::getURL(); |
77
|
|
|
$browserURI = $I->getCurrentUri(); |
78
|
|
|
$I->comment(" compare page [".$pageURI."][".$browserURI."]"); |
79
|
|
|
if (strlen($pageURI) == strlen($browserURI)) { |
80
|
|
|
$I->seeCurrentUrlEquals($pageURI); |
81
|
|
|
} else { |
82
|
|
|
$I->seeCurrentUrlMatches('~'.preg_quote($pageURI).'~'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function checkElements() |
89
|
|
|
{ |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testPage() |
93
|
|
|
{ |
94
|
|
|
$this->loadPage(); |
95
|
|
|
$this->checkPage(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function checkPage() |
99
|
|
|
{ |
100
|
|
|
$this->checkOnURL(); |
101
|
|
|
$this->checkElements(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param $name |
106
|
|
|
* @param $value |
107
|
|
|
*/ |
108
|
|
|
public function addURLQueryParams($name, $value) |
109
|
|
|
{ |
110
|
|
|
$urlParts = parse_url(static::$URL); |
111
|
|
|
if (isset($urlParts['query'])) { |
112
|
|
|
parse_str($urlParts['query'], $params); |
113
|
|
|
} else { |
114
|
|
|
$params = []; |
115
|
|
|
} |
116
|
|
|
$params[$name] = $value; |
117
|
|
|
static::$URL = $urlParts['path'].'?'.http_build_query($params); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.