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
|
|
|
$page = $this->getSession()->getPage(); |
29
|
|
|
$versions = $page->findAll('css', '.history-viewer .table tbody tr td:nth-of-type(1)'); |
30
|
|
|
|
31
|
|
|
$previous = null; |
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->getFirstVersion(), 'I should see a list of versions'); |
47
|
|
|
$firstVersion->click(); |
|
|
|
|
48
|
|
|
|
49
|
|
|
// Wait for the form builder to load |
50
|
|
|
$this->getSession()->wait(3000); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Then I should see the :arg1 badge |
56
|
|
|
*/ |
57
|
|
|
public function iShouldSeeTheBadge($arg1) |
58
|
|
|
{ |
59
|
|
|
$this->assertElementContains('.history-viewer .badge', $arg1); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
protected function getFirstVersion() |
64
|
|
|
{ |
65
|
|
|
$page = $this->getSession()->getPage(); |
66
|
|
|
return $page->find('css', '.history-viewer .table tbody tr'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function getSpecificVersion($versionNumber) |
70
|
|
|
{ |
71
|
|
|
$versionColumns = $this->getSession()->getPage()->findAll('css', '.history-viewer tbody tr'); |
72
|
|
|
foreach($versionColumns as $version) { |
73
|
|
|
if (strpos($version->getText(), $versionNumber) !== false) { |
74
|
|
|
return $version; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @Then I should see :text in the author column in version :versionNumber |
81
|
|
|
*/ |
82
|
|
|
public function iShouldSeeInTheAuthorColumn($text, $versionNumber) |
83
|
|
|
{ |
84
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
85
|
|
|
$authorColumn = $version->find('css', 'td:nth-of-type(3)'); |
86
|
|
|
|
87
|
|
|
$exists = strpos($authorColumn->getText(), $text) !== false; |
88
|
|
|
assertTrue($exists, 'Author column contains ' . $text); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Then I should see :text in the record column in version :versionNumber |
93
|
|
|
*/ |
94
|
|
|
public function iShouldSeeInTheRecordColumn($text, $versionNumber) |
95
|
|
|
{ |
96
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
97
|
|
|
$recordColumn = $version->find('css', 'td:nth-of-type(2)'); |
98
|
|
|
|
99
|
|
|
$exists = strpos($recordColumn->getText(), $text) !== false; |
100
|
|
|
assertTrue($exists, 'Record column contains ' . $text); |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Then I should see :text in the version column in version :versionNumber |
106
|
|
|
*/ |
107
|
|
|
public function iShouldSeeInTheVersionColumn($text, $versionNumber) |
108
|
|
|
{ |
109
|
|
|
$version = $this->getSpecificVersion($versionNumber); |
110
|
|
|
$versionColumn = $version->find('css', 'td'); |
111
|
|
|
|
112
|
|
|
$exists = strpos($versionColumn->getText(), $text) !== false; |
113
|
|
|
assertTrue($exists, 'Version column contains ' . $text); } |
114
|
|
|
} |
115
|
|
|
|
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.