Completed
Push — master ( 011918...3a8b9a )
by Paweł
31:19 queued 19:29
created

ProductReviewContext   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 17
lcom 2
cbo 5
dl 0
loc 183
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A iWantToReviewProduct() 0 4 1
A iLeaveACommentTitled() 0 9 2
A iTitleItWithVeryLongTitle() 0 4 1
A iRateItWithPoints() 0 4 1
A iDoNotRateIt() 0 4 1
A iAddIt() 0 4 1
A iShouldBeNotifiedThatMyReviewIsWaitingForTheAcceptation() 0 7 1
A iShouldBeNotifiedThatIMustCheckReviewRating() 0 8 1
A iShouldBeNotifiedThatTitleIsRequired() 0 8 1
A iShouldBeNotifiedThatTitleMustHaveAtLeast2Characters() 0 8 1
A iShouldBeNotifiedThatTitleMustHaveAtMost255Characters() 0 8 1
A iShouldBeNotifiedThatCommentIsRequired() 0 8 1
A iShouldBeNotifiedThatIMustEnterMyEmail() 0 8 1
A iShouldBeNotifiedThatThisEmailIsAlreadyRegistered() 0 8 1
A getVeryLongTitle() 0 4 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\Shop;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Page\Shop\ProductReview\CreatePageInterface;
17
use Sylius\Behat\Service\NotificationCheckerInterface;
18
use Sylius\Component\Core\Model\ProductInterface;
19
use Webmozart\Assert\Assert;
20
21
/**
22
 * @author Mateusz Zalewski <[email protected]>
23
 */
24
final class ProductReviewContext implements Context
25
{
26
    /**
27
     * @var CreatePageInterface
28
     */
29
    private $createPage;
30
31
    /**
32
     * @var NotificationCheckerInterface
33
     */
34
    private $notificationChecker;
35
36
    /**
37
     * @param CreatePageInterface $createPage
38
     * @param NotificationCheckerInterface $notificationChecker
39
     */
40
    public function __construct(
41
        CreatePageInterface $createPage,
42
        NotificationCheckerInterface $notificationChecker
43
    ) {
44
        $this->createPage = $createPage;
45
        $this->notificationChecker = $notificationChecker;
46
    }
47
48
    /**
49
     * @Given I want to review product :product
50
     */
51
    public function iWantToReviewProduct(ProductInterface $product)
52
    {
53
        $this->createPage->open(['slug' => $product->getSlug()]);
54
    }
55
56
    /**
57
     * @When I leave a comment :comment as :author
58
     * @When I leave a comment :comment, titled :title
59
     * @When I leave a comment :comment, titled :title as :author
60
     * @When I leave a review titled :title as :author
61
     */
62
    public function iLeaveACommentTitled($comment = null, $title = null, $author = null)
63
    {
64
        $this->createPage->titleReview($title);
65
        $this->createPage->setComment($comment);
66
67
        if (null !== $author) {
68
            $this->createPage->setAuthor($author);
69
        }
70
    }
71
72
    /**
73
     * @When I title it with very long title
74
     */
75
    public function iTitleItWithVeryLongTitle()
76
    {
77
        $this->createPage->titleReview($this->getVeryLongTitle());
78
    }
79
80
    /**
81
     * @When I rate it with :rate point(s)
82
     */
83
    public function iRateItWithPoints($rate)
84
    {
85
        $this->createPage->rateReview($rate);
86
    }
87
88
    /**
89
     * @When I do not rate it
90
     */
91
    public function iDoNotRateIt()
92
    {
93
        // intentionally left blank, as review rate is not selected by default
94
    }
95
96
    /**
97
     * @When I add it
98
     */
99
    public function iAddIt()
100
    {
101
        $this->createPage->submitReview();
102
    }
103
104
    /**
105
     * @Then I should be notified that my review is waiting for the acceptation
106
     */
107
    public function iShouldBeNotifiedThatMyReviewIsWaitingForTheAcceptation()
108
    {
109
        $this->notificationChecker->checkNotification(
110
            'Your review is waiting for the acceptation.',
111
            NotificationType::success()
112
        );
113
    }
114
115
    /**
116
     * @Then I should be notified that I must check review rating
117
     */
118
    public function iShouldBeNotifiedThatIMustCheckReviewRating()
119
    {
120
        Assert::same(
121
            $this->createPage->getRateValidationMessage(),
122
            'You must check review rating.',
123
            'There should be rate validation error, but there is not.'
124
        );
125
    }
126
127
    /**
128
     * @Then I should be notified that title is required
129
     */
130
    public function iShouldBeNotifiedThatTitleIsRequired()
131
    {
132
        Assert::same(
133
            $this->createPage->getTitleValidationMessage(),
134
            'Review title should not be blank.',
135
            'There should be title validation error, but there is not.'
136
        );
137
    }
138
139
    /**
140
     * @Then I should be notified that title must have at least 2 characters
141
     */
142
    public function iShouldBeNotifiedThatTitleMustHaveAtLeast2Characters()
143
    {
144
        Assert::same(
145
            'Review title must have at least 2 characters.',
146
            $this->createPage->getTitleValidationMessage(),
147
            'There should be title length validation error, but there is not.'
148
        );
149
    }
150
151
    /**
152
     * @Then I should be notified that title must have at most 255 characters
153
     */
154
    public function iShouldBeNotifiedThatTitleMustHaveAtMost255Characters()
155
    {
156
        Assert::same(
157
            'Review title must have at most 255 characters.',
158
            $this->createPage->getTitleValidationMessage(),
159
            'There should be title length validation error, but there is not.'
160
        );
161
    }
162
163
    /**
164
     * @Then I should be notified that comment is required
165
     */
166
    public function iShouldBeNotifiedThatCommentIsRequired()
167
    {
168
        Assert::same(
169
            $this->createPage->getCommentValidationMessage(),
170
            'Review comment should not be blank.',
171
            'There should be comment validation error, but there is not.'
172
        );
173
    }
174
175
    /**
176
     * @Then I should be notified that I must enter my email
177
     */
178
    public function iShouldBeNotifiedThatIMustEnterMyEmail()
179
    {
180
        Assert::same(
181
            $this->createPage->getAuthorValidationMessage(),
182
            'Please enter your email.',
183
            'There should be author validation error, but there is not.'
184
        );
185
    }
186
187
    /**
188
     * @Then I should be notified that this email is already registered
189
     */
190
    public function iShouldBeNotifiedThatThisEmailIsAlreadyRegistered()
191
    {
192
        Assert::same(
193
            $this->createPage->getAuthorValidationMessage(),
194
            'This email is already registered, please login or use forgotten password.',
195
            'There should be author validation error, but there is not.'
196
        );
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    private function getVeryLongTitle()
203
    {
204
        return 'Exegi monumentum aere perennius regalique situ pyramidum altius, quod non imber edax, non Aquilo inpotens possit diruere aut innumerabilis annorum series et fuga temporum. Non omnis moriar multaque pars mei vitabit Libitinam; usque ego postera crescam laude recens, dum Capitoliumscandet cum tacita virgine pontifex.Dicar, qua violens obstrepit Aufiduset qua pauper aquae Daunus agrestiumregnavit populorum, ex humili potensprinceps Aeolium carmen ad Italosdeduxisse modos. Sume superbiamquaesitam meritis et mihi Delphicalauro cinge volens, Melpomene, comam.';
205
    }
206
}
207