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
|
|
|
* @When I click on the first version |
26
|
|
|
*/ |
27
|
|
|
public function iClickOnTheFirstVersion() |
28
|
|
|
{ |
29
|
|
|
$versions = $this->getVersions(); |
30
|
|
|
$this->clickVersion(current($versions)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @When I click on version :versionNo |
35
|
|
|
*/ |
36
|
|
|
public function iClickOnVersion($versionNo) |
37
|
|
|
{ |
38
|
|
|
$versions = $this->getVersions(' td:first-child'); |
39
|
|
|
$desiredVersion = null; |
40
|
|
|
foreach ($versions as $version) { |
41
|
|
|
/** @var NodeElement $version */ |
42
|
|
|
if ($version->getText() == $versionNo) { |
43
|
|
|
$desiredVersion = $version; |
44
|
|
|
break; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.'); |
48
|
|
|
$this->clickVersion($desiredVersion); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Click on the given version |
53
|
|
|
* |
54
|
|
|
* @param NodeElement $version |
55
|
|
|
*/ |
56
|
|
|
protected function clickVersion(NodeElement $version) |
57
|
|
|
{ |
58
|
|
|
$version->click(); |
59
|
|
|
|
60
|
|
|
// Wait for the form builder to load |
61
|
|
|
$this->getSession()->wait(3000, 'window.jQuery("#Form_versionForm").length > 0'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns the versions from the history viewer list (table rows) |
66
|
|
|
* |
67
|
|
|
* @param string $modifier Optional CSS selector modifier |
68
|
|
|
* @return NodeElement[] |
69
|
|
|
*/ |
70
|
|
|
protected function getVersions($modifier = '') |
71
|
|
|
{ |
72
|
|
|
$versions = $this |
73
|
|
|
->getSession() |
74
|
|
|
->getPage() |
75
|
|
|
->findAll('css', '.history-viewer .table tbody tr' . $modifier); |
76
|
|
|
|
77
|
|
|
assertNotEmpty($versions, 'I see a list of versions'); |
78
|
|
|
return $versions; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.