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
|
|
|
$page = $this->getSession()->getPage(); |
20
|
|
|
$versionsTable = $page->find('css', '.history-viewer .table'); |
21
|
|
|
assertNotNull($versionsTable, 'I should see a list of versions'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Then I should see a list of versions in descending order |
26
|
|
|
*/ |
27
|
|
|
public function iShouldSeeAListOfVersionsInDescendingOrder() |
28
|
|
|
{ |
29
|
|
|
$page = $this->getSession()->getPage(); |
30
|
|
|
$versions = $page->findAll('css', '.history-viewer .table tbody tr td:nth-of-type(1)'); |
31
|
|
|
|
32
|
|
|
$previous = null; |
33
|
|
|
foreach ($versions as $version) { |
34
|
|
|
/** @var NodeElement $version */ |
35
|
|
|
if ($previous) { |
36
|
|
|
assert($version->getValue() < $previous); |
37
|
|
|
} |
38
|
|
|
$previous = $version->getValue(); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @When I click on the first version |
44
|
|
|
*/ |
45
|
|
|
public function iClickOnTheFirstVersion() |
46
|
|
|
{ |
47
|
|
|
assertNotNull($this->getLatestVersion(), 'I should see a list of versions'); |
48
|
|
|
$this->getLatestVersion()->click(); |
49
|
|
|
|
50
|
|
|
// Wait for the form builder to load |
51
|
|
|
$this->getSession()->wait(3000); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Example: I should see the "Live" badge |
56
|
|
|
* Example: I should not see the "Live" badge |
57
|
|
|
* |
58
|
|
|
* @Then /^I should (not |)see the "([\w\s]+)" badge$/ |
59
|
|
|
* @param string $negative |
60
|
|
|
* @param string $text |
61
|
|
|
*/ |
62
|
|
|
public function iShouldSeeTheBadge($negative, $text) |
63
|
|
|
{ |
64
|
|
|
if ($negative) { |
65
|
|
|
$this->assertElementNotOnPage('.history-viewer .badge'); |
66
|
|
|
} else { |
67
|
|
|
$this->assertElementContains('.history-viewer .badge', $text); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Example: I should see "ADMIN User" in the author column in version 1 |
73
|
|
|
* |
74
|
|
|
* @Then I should see :text in the author column in version :versionNumber |
75
|
|
|
*/ |
76
|
|
|
public function iShouldSeeInTheAuthorColumn($text, $versionNumber) |
77
|
|
|
{ |
78
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
79
|
|
|
$authorColumn = $version->find('css', 'td:nth-of-type(3)'); |
80
|
|
|
|
81
|
|
|
$exists = strpos($authorColumn->getText(), $text) !== false; |
82
|
|
|
assertTrue($exists, 'Author column contains ' . $text); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Example: I should see "Saved" in the record column in version 1 |
87
|
|
|
* |
88
|
|
|
* @Then I should see :text in the record column in version :versionNumber |
89
|
|
|
*/ |
90
|
|
|
public function iShouldSeeInTheRecordColumn($text, $versionNumber) |
91
|
|
|
{ |
92
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
93
|
|
|
$recordColumn = $version->find('css', 'td:nth-of-type(2)'); |
94
|
|
|
|
95
|
|
|
$exists = strpos($recordColumn->getText(), $text) !== false; |
96
|
|
|
assertTrue($exists, 'Record column contains ' . $text); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @Then I should see :text in the version column in version :versionNumber |
101
|
|
|
*/ |
102
|
|
|
public function iShouldSeeInTheVersionColumn($text, $versionNumber) |
103
|
|
|
{ |
104
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
105
|
|
|
$versionColumn = $version->find('css', 'td'); |
106
|
|
|
|
107
|
|
|
$exists = strpos($versionColumn->getText(), $text) !== false; |
108
|
|
|
assertTrue($exists, 'Version column contains ' . $text); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns the table row that holds information on the most recent version |
113
|
|
|
*/ |
114
|
|
|
protected function getLatestVersion() |
115
|
|
|
{ |
116
|
|
|
$page = $this->getSession()->getPage(); |
117
|
|
|
return $page->find('css', '.history-viewer .table tbody tr'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the table row that holds information on the selected version. |
122
|
|
|
* |
123
|
|
|
* @param int $versionNumber |
124
|
|
|
*/ |
125
|
|
|
protected function getSpecificVersion($versionNumber) |
126
|
|
|
{ |
127
|
|
|
$versionColumns = $this->getSession()->getPage()->findAll('css', '.history-viewer tbody tr'); |
128
|
|
|
foreach ($versionColumns as $version) { |
129
|
|
|
if (strpos($version->getText(), $versionNumber) !== false) { |
130
|
|
|
return $version; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.