|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\VersionedAdmin\Tests\Behat\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Mink\Element\NodeElement; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
if (!class_exists(SilverStripeContext::class)) { |
|
9
|
|
|
return; |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
class FeatureContext extends SilverStripeContext |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @Then I should see a list of versions |
|
16
|
|
|
*/ |
|
17
|
|
|
public function iShouldSeeAListOfVersions() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->getVersions(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @Then I should see a list of versions in descending order |
|
24
|
|
|
*/ |
|
25
|
|
|
public function iShouldSeeAListOfVersionsInDescendingOrder() |
|
26
|
|
|
{ |
|
27
|
|
|
$versions = $this->getVersions(); |
|
28
|
|
|
assertNotEmpty($versions, 'I see a list of versions'); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$previous = null; |
|
31
|
|
|
|
|
32
|
|
|
foreach ($versions as $version) { |
|
33
|
|
|
/** @var NodeElement $version */ |
|
34
|
|
|
if ($previous) { |
|
35
|
|
|
assert($version->getValue() < $previous); |
|
36
|
|
|
} |
|
37
|
|
|
$previous = $version->getValue(); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @When I click on the first version |
|
43
|
|
|
*/ |
|
44
|
|
|
public function iClickOnTheFirstVersion() |
|
45
|
|
|
{ |
|
46
|
|
|
assertNotNull($this->getLatestVersion(), 'I should see a list of versions'); |
|
|
|
|
|
|
47
|
|
|
$this->getLatestVersion()->click(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @When I click on version :versionNo |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iClickOnVersion($versionNo) |
|
54
|
|
|
{ |
|
55
|
|
|
$versions = $this->getVersions(' .history-viewer__version-no'); |
|
56
|
|
|
$desiredVersion = null; |
|
57
|
|
|
foreach ($versions as $version) { |
|
58
|
|
|
/** @var NodeElement $version */ |
|
59
|
|
|
if ($version->getText() == $versionNo) { |
|
60
|
|
|
$desiredVersion = $version; |
|
61
|
|
|
break; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.'); |
|
|
|
|
|
|
65
|
|
|
$this->clickVersion($desiredVersion); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @Given I open the history viewer actions menu |
|
70
|
|
|
*/ |
|
71
|
|
|
public function iOpenTheHistoryViewerActionsMenu() |
|
72
|
|
|
{ |
|
73
|
|
|
$button = $this->getSession()->getPage()->find('css', '.history-viewer__heading .history-viewer__actions .btn'); |
|
74
|
|
|
assertNotNull($button, 'History viewer actions menu not found in the page.'); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$button->click(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @Then the text :text should be deleted |
|
81
|
|
|
*/ |
|
82
|
|
|
public function theTextShouldBeDeleted($text) |
|
83
|
|
|
{ |
|
84
|
|
|
$result = $this->getSession()->getPage()->find( |
|
85
|
|
|
'xpath', |
|
86
|
|
|
sprintf('//del[contains(normalize-space(string(.)), \'%s\')]', $text) |
|
87
|
|
|
); |
|
88
|
|
|
assertNotNull($result, $text . ' was not shown as deleted'); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @Then the text :text should be added |
|
93
|
|
|
*/ |
|
94
|
|
|
public function theTextShouldBeAdded($text) |
|
95
|
|
|
{ |
|
96
|
|
|
$result = $this->getSession()->getPage()->find( |
|
97
|
|
|
'xpath', |
|
98
|
|
|
sprintf('//ins[contains(normalize-space(string(.)), \'%s\')]', $text) |
|
99
|
|
|
); |
|
100
|
|
|
assertNotNull($result, $text . ' was not shown as added'); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Click on the given version |
|
105
|
|
|
* |
|
106
|
|
|
* @param NodeElement $version |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function clickVersion(NodeElement $version) |
|
109
|
|
|
{ |
|
110
|
|
|
$version->click(); |
|
111
|
|
|
|
|
112
|
|
|
// Wait for the form builder to load |
|
113
|
|
|
$this->getSession()->wait(3000, 'window.jQuery("#Form_versionForm").length > 0'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Returns the versions from the history viewer list (table rows) |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $modifier Optional CSS selector modifier |
|
120
|
|
|
* @return NodeElement[] |
|
121
|
|
|
*/ |
|
122
|
|
|
protected function getVersions($modifier = '') |
|
123
|
|
|
{ |
|
124
|
|
|
// Wait for the list to be visible |
|
125
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".history-viewer .table").length > 0'); |
|
126
|
|
|
|
|
127
|
|
|
$versions = $this->getSession() |
|
128
|
|
|
->getPage() |
|
129
|
|
|
->findAll('css', '.history-viewer__list .history-viewer__table .history-viewer__row' . $modifier); |
|
130
|
|
|
return $versions; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Example: I should see the "Live" badge |
|
135
|
|
|
* Example: I should not see the "Live" badge |
|
136
|
|
|
* |
|
137
|
|
|
* @Then /^I should (not |)see the "([\w\s]+)" badge$/ |
|
138
|
|
|
* @param string $negative |
|
139
|
|
|
* @param string $text |
|
140
|
|
|
*/ |
|
141
|
|
|
public function iShouldSeeTheBadge($negative, $text) |
|
142
|
|
|
{ |
|
143
|
|
|
if ($negative) { |
|
144
|
|
|
$this->assertElementNotOnPage('.history-viewer .badge'); |
|
145
|
|
|
} else { |
|
146
|
|
|
$this->assertElementContains('.history-viewer .badge', $text); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Example: I should see "ADMIN User" in the author column in version 1 |
|
152
|
|
|
* |
|
153
|
|
|
* @Then I should see :text in the author column in version :versionNumber |
|
154
|
|
|
*/ |
|
155
|
|
|
public function iShouldSeeInTheAuthorColumn($text, $versionNumber) |
|
156
|
|
|
{ |
|
157
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
|
158
|
|
|
$authorColumn = $version->find('css', '.history-viewer__author'); |
|
159
|
|
|
|
|
160
|
|
|
$exists = strpos($authorColumn->getText(), $text) !== false; |
|
161
|
|
|
assertTrue($exists, 'Author column contains ' . $text); |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Example: I should see "Saved" in the record column in version 1 |
|
166
|
|
|
* |
|
167
|
|
|
* @Then I should see :text in the record column in version :versionNumber |
|
168
|
|
|
*/ |
|
169
|
|
|
public function iShouldSeeInTheRecordColumn($text, $versionNumber) |
|
170
|
|
|
{ |
|
171
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
|
172
|
|
|
$recordColumn = $version->find('css', '.history-viewer__version-state'); |
|
173
|
|
|
|
|
174
|
|
|
$exists = strpos($recordColumn->getText(), $text) !== false; |
|
175
|
|
|
assertTrue($exists, 'Record column contains ' . $text); |
|
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @Then I should see :text in the version column in version :versionNumber |
|
180
|
|
|
*/ |
|
181
|
|
|
public function iShouldSeeInTheVersionColumn($text, $versionNumber) |
|
182
|
|
|
{ |
|
183
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
|
184
|
|
|
$versionColumn = $version->find('css', '.history-viewer__version-no'); |
|
185
|
|
|
|
|
186
|
|
|
$exists = strpos($versionColumn->getText(), $text) !== false; |
|
187
|
|
|
assertTrue($exists, 'Version column contains ' . $text); |
|
|
|
|
|
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Returns the table row that holds information on the most recent version |
|
192
|
|
|
*/ |
|
193
|
|
|
protected function getLatestVersion() |
|
194
|
|
|
{ |
|
195
|
|
|
$versions = $this->getVersions(); |
|
196
|
|
|
return current($versions); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Returns the table row that holds information on the selected version. |
|
201
|
|
|
* |
|
202
|
|
|
* @param int $versionNumber |
|
203
|
|
|
* @return NodeElement |
|
204
|
|
|
*/ |
|
205
|
|
|
protected function getSpecificVersion($versionNumber) |
|
206
|
|
|
{ |
|
207
|
|
|
$versions = $this->getVersions(); |
|
208
|
|
|
foreach ($versions as $version) { |
|
209
|
|
|
/** @var NodeElement $version */ |
|
210
|
|
|
if (strpos($version->getText(), $versionNumber) !== false) { |
|
211
|
|
|
return $version; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths