Completed
Push — example/managing-articles ( 828ad3...a73081 )
by Loïc
02:22 queued 02:20
created

ManagingArticlesContext::iDeleteThem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace App\Behat\Context\Ui\Backend;
15
16
use App\Behat\Page\Backend\Article\IndexPage;
17
use App\Behat\Page\Backend\Article\CreatePage;
18
use App\Behat\Page\Backend\Article\UpdatePage;
19
use App\Entity\Article;
20
use Behat\Behat\Context\Context;
21
use Webmozart\Assert\Assert;
22
23
final class ManagingArticlesContext implements Context
24
{
25
    /**
26
     * @var CreatePage
27
     */
28
    private $createPage;
29
30
    /**
31
     * @var IndexPage
32
     */
33
    private $indexPage;
34
35
    /**
36
     * @var UpdatePage
37
     */
38
    private $updatePage;
39
40
    /**
41
     * @param CreatePage $createPage
42
     * @param IndexPage  $indexPage
43
     * @pram UpdatePage $updatePage
44
     */
45
    public function __construct(
46
        CreatePage $createPage,
47
        IndexPage $indexPage,
48
        UpdatePage $updatePage
49
    ) {
50
        $this->createPage = $createPage;
51
        $this->indexPage = $indexPage;
52
        $this->updatePage = $updatePage;
53
    }
54
55
    /**
56
     * @Given I want to create a new article
57
     */
58
    public function iWantToCreateANewArticle()
59
    {
60
        $this->createPage->open();
61
    }
62
63
    /**
64
     * @When I browse articles
65
     * @When I want to browse articles
66
     */
67
    public function iWantToBrowseArticles()
68
    {
69
        $this->indexPage->open();
70
    }
71
72
    /**
73
     * @Given I want to modify the :article article
74
     */
75
    public function iWantToModifyAnArticle(Article $article)
76
    {
77
        $this->updatePage->open(['id' => $article->getId()]);
78
    }
79
80
    /**
81
     * @When I specify its title as :title
82
     * @When I do not specify its title
83
     */
84
    public function iSpecifyItsEmailAs($title = null)
85
    {
86
        $this->createPage->specifyTitle($title);
87
    }
88
89
    /**
90
     * @When I rename it to :title
91
     */
92
    public function iChangeItsTitleAs($title = null)
93
    {
94
        $this->updatePage->changeTitle($title);
95
    }
96
97
    /**
98
     * @When I add it
99
     * @When I try to add it
100
     */
101
    public function iAddIt()
102
    {
103
        $this->createPage->create();
104
    }
105
106
    /**
107
     * @When I save my changes
108
     */
109
    public function iSaveMyChanges()
110
    {
111
        $this->updatePage->saveChanges();
112
    }
113
114
    /**
115
     * @When I delete article with title :title
116
     */
117
    public function iDeleteArticleWithTitle($title)
118
    {
119
        $this->indexPage->deleteResourceOnPage(['title' => $title]);
120
    }
121
122
    /**
123
     * @When I (also) check the :title article
124
     */
125
    public function iCheckTheArticle(string $title): void
126
    {
127
        $this->indexPage->checkResourceOnPage(['title' => $title]);
128
    }
129
130
    /**
131
     * @When I delete them
132
     */
133
    public function iDeleteThem(): void
134
    {
135
        $this->indexPage->bulkDelete();
136
    }
137
138
    /**
139
     * @Then I should see a single article in the list
140
     * @Then /^there should be (\d+) articles in the list$/
141
     */
142
    public function iShouldSeeArticlesInTheList(int $number = 1): void
143
    {
144
        Assert::same($this->indexPage->countItems(), (int) $number);
145
    }
146
147
    /**
148
     * @Then I should (also )see the article :title in the list
149
     * @Then the article :title should appear in the website
150
     */
151
    public function theArticleShouldAppearInTheWebsite($title)
152
    {
153
        $this->indexPage->open();
154
155
        Assert::true($this->indexPage->isSingleResourceOnPage(['title' => $title]));
156
    }
157
158
    /**
159
     * @Then there should not be :title article anymore
160
     */
161
    public function thereShouldBeNoAnymore($title)
162
    {
163
        Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $title]));
164
    }
165
166
    /**
167
     * @Then I should be notified that the title is required
168
     */
169
    public function iShouldBeNotifiedThatTitleIsRequired()
170
    {
171
        Assert::same($this->createPage->getValidationMessage('title'), 'This value should not be blank.');
172
    }
173
174
    /**
175
     * @Then this article should not be added
176
     */
177
    public function thisArticleShouldNotBeAdded()
178
    {
179
        $this->indexPage->open();
180
181
        Assert::same($this->indexPage->countItems(), 0);
182
    }
183
}
184