Passed
Pull Request — master (#14)
by
unknown
02:41
created

FeatureContext::getFirstVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 9.

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.

Loading history...
2
3
namespace SilverStripe\VersionedAdmin\Tests\Behat\Context;
4
5
use Behat\Mink\Element\NodeElement;
0 ignored issues
show
Bug introduced by
The type Behat\Mink\Element\NodeElement was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\BehatExtension\Context\SilverStripeContext;
0 ignored issues
show
Bug introduced by
The type SilverStripe\BehatExtens...ext\SilverStripeContext was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $firstVersion seems to be never defined.
Loading history...
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