Completed
Push — master ( ec9928...7e945e )
by Paweł
56:53 queued 42:10
created

iShouldSeeTheProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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
namespace Sylius\Behat\Context\Ui\Admin;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Page\Admin\ProductReview\IndexPageInterface;
17
use Sylius\Behat\Page\Admin\ProductReview\UpdatePageInterface;
18
use Sylius\Behat\Service\NotificationCheckerInterface;
19
use Sylius\Component\Review\Model\ReviewInterface;
20
use Webmozart\Assert\Assert;
21
22
/**
23
 * @author Grzegorz Sadowski <[email protected]>
24
 */
25
final class ManagingProductReviewsContext implements Context
26
{
27
    /**
28
     * @var IndexPageInterface
29
     */
30
    private $indexPage;
31
32
    /**
33
     * @var UpdatePageInterface
34
     */
35
    private $updatePage;
36
37
    /**
38
     * @var NotificationCheckerInterface
39
     */
40
    private $notificationChecker;
41
42
    /**
43
     * @param IndexPageInterface $indexPage
44
     * @param UpdatePageInterface $updatePage
45
     * @param NotificationCheckerInterface $notificationChecker
46
     */
47
    public function __construct(
48
        IndexPageInterface $indexPage,
49
        UpdatePageInterface $updatePage,
50
        NotificationCheckerInterface $notificationChecker
51
    ) {
52
        $this->indexPage = $indexPage;
53
        $this->updatePage = $updatePage;
54
        $this->notificationChecker = $notificationChecker;
55
    }
56
57
    /**
58
     * @When I want to browse product reviews
59
     */
60
    public function iWantToBrowseProductReviews()
61
    {
62
        $this->indexPage->open();
63
    }
64
65
    /**
66
     * @Then I should (also) see the product review :title in the list
67
     */
68
    public function iShouldSeeTheProductReviewTitleInTheList($title)
69
    {
70
        Assert::true(
71
            $this->indexPage->isSingleResourceOnPage(['title' => $title]),
72
            sprintf('Product review with a title %s should exist but it does not.', $title)
73
        );
74
    }
75
76
    /**
77
     * @Then I should see :amount product reviews in the list
78
     */
79
    public function iShouldSeeProductReviewsInTheList($amount)
80
    {
81
        Assert::same(
82
            (int) $amount,
83
            $this->indexPage->countItems(),
84
            '%2$s rows with product reviews should appear on page, %s rows has been found'
85
        );
86
    }
87
88
    /**
89
     * @When I want to modify the :productReview product review
90
     */
91
    public function iWantToModifyTheProductReview(ReviewInterface $productReview)
92
    {
93
        $this->updatePage->open(['id' => $productReview->getId()]);
94
    }
95
96
    /**
97
     * @When I change its title to :title
98
     * @When I remove its title
99
     */
100
    public function iChangeItsTitleTo($title = null)
101
    {
102
        $this->updatePage->specifyTitle($title);
103
    }
104
105
    /**
106
     * @When I change its comment to :comment
107
     * @When I remove its comment
108
     */
109
    public function iChangeItsCommentTo($comment = null)
110
    {
111
        $this->updatePage->specifyComment($comment);
112
    }
113
114
    /**
115
     * @When I save my changes
116
     * @When I try to save my changes
117
     */
118
    public function iSaveMyChanges()
119
    {
120
        $this->updatePage->saveChanges();
121
    }
122
123
    /**
124
     * @Then /^this product review (comment|title) should be "([^"]+)"$/
125
     */
126
    public function thisProductReviewElementShouldBeValue($element, $value)
127
    {
128
        $this->assertElementValue($element, $value);
129
    }
130
131
    /**
132
     * @Then this product review rating should be :rating
133
     */
134
    public function thisProductReviewRatingShouldBe($rating)
135
    {
136
        Assert::same(
137
            $rating,
138
            $this->updatePage->getRating(),
139
            'Product review should have rating %s, but it has %s'
140
        );
141
    }
142
143
    /**
144
     * @When I choose :rating as its rating
145
     */
146
    public function iChooseAsItsRating($rating)
147
    {
148
        $this->updatePage->chooseRating($rating);
149
    }
150
151
    /**
152
     * @Then I should see the product :productName
153
     */
154
    public function iShouldSeeTheProduct($productName)
155
    {
156
        Assert::same(
157
            $productName,
158
            $this->updatePage->getProductName(),
159
            'Product should have name %s, but it has %s'
160
        );
161
    }
162
163
    /**
164
     * @Then I should see the customer's name :customerName
165
     */
166
    public function iShouldSeeTheCustomerSName($customerName)
167
    {
168
        Assert::same(
169
            $customerName,
170
            $this->updatePage->getCustomerName(),
171
            'Customer should have name %s, but they have %s'
172
        );
173
    }
174
175
    /**
176
     * @When I accept the :productReview product review
177
     */
178
    public function iAcceptTheProductReview(ReviewInterface $productReview)
179
    {
180
        $this->indexPage->accept(['title' => $productReview->getTitle()]);
181
    }
182
183
    /**
184
     * @When I reject the :productReview product review
185
     */
186
    public function iRejectTheProductReview(ReviewInterface $productReview)
187
    {
188
        $this->indexPage->reject(['title' => $productReview->getTitle()]);
189
    }
190
191
    /**
192
     * @Then /^(this product review) status should be "([^"]+)"$/
193
     */
194
    public function thisProductReviewStatusShouldBe(ReviewInterface $productReview, $status)
195
    {
196
        Assert::true(
197
            $this->indexPage->isSingleResourceOnPage(['title' => $productReview->getTitle(), 'status' => $status]),
198
            sprintf(
199
                'Product review with title "%s" and status "%s" is not in the list.',
200
                $productReview->getTitle(),
201
                $status
202
            )
203
        );
204
    }
205
206
    /**
207
     * @Then /^I should be notified that it has been successfully (accepted|rejected)$/
208
     */
209
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyUpdated($action)
210
    {
211
        $this->notificationChecker->checkNotification(
212
            sprintf('Product review has been successfully %s.', $action), NotificationType::success()
213
        );
214
    }
215
216
    /**
217
     * @When I delete the :productReview product review
218
     */
219
    public function iDeleteTheProductReview(ReviewInterface $productReview)
220
    {
221
        $this->indexPage->open();
222
        $this->indexPage->deleteResourceOnPage(['title' => $productReview->getTitle()]);
223
    }
224
225
    /**
226
     * @Then /^(this product review) should no longer exist in the registry$/
227
     */
228
    public function thisProductReviewShouldNoLongerExistInTheRegistry(ReviewInterface $productReview)
229
    {
230
        Assert::false(
231
            $this->indexPage->isSingleResourceOnPage(['title' => $productReview->getTitle()]),
232
            sprintf('Product review with title "%s" should no longer exist in the registry.', $productReview->getTitle())
233
        );
234
    }
235
236
    /**
237
     * @Then I should be notified that :element is required
238
     */
239
    public function iShouldBeNotifiedThatElementIsRequired($element)
240
    {
241
        $this->assertFieldValidationMessage($element, sprintf('Review %s should not be blank.', $element));
242
    }
243
244
    /**
245
     * @Then /^(this product review) should still be titled "([^"]+)"$/
246
     */
247
    public function thisProductReviewTitleShouldBeTitled(ReviewInterface $productReview, $productReviewTitle)
0 ignored issues
show
Unused Code introduced by
The parameter $productReview is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
248
    {
249
        $this->iWantToBrowseProductReviews();
250
251
        Assert::true(
252
            $this->indexPage->isSingleResourceOnPage(['title' => $productReviewTitle]),
253
            sprintf('Product review title %s has not been assigned properly.', $productReviewTitle)
254
        );
255
    }
256
257
    /**
258
     * @Then /^(this product review) should still have a comment "([^"]+)"$/
259
     */
260
    public function thisProductReviewShouldStillHaveAComment(ReviewInterface $productReview, $comment)
261
    {
262
        $this->iWantToModifyTheProductReview($productReview);
263
264
        $this->assertElementValue('comment', $comment);
265
    }
266
267
    /**
268
     * @param string $element
269
     * @param string $value
270
     */
271
    private function assertElementValue($element, $value)
272
    {
273
        Assert::true(
274
            $this->updatePage->hasResourceValues([$element => $value]),
275
            sprintf('Product review should have %s with %s value.', $element, $value)
276
        );
277
    }
278
279
    /**
280
     * @param string $element
281
     * @param string $expectedMessage
282
     */
283
    private function assertFieldValidationMessage($element, $expectedMessage)
284
    {
285
        Assert::same(
286
            $this->updatePage->getValidationMessage($element),
287
            $expectedMessage
288
        );
289
    }
290
}
291