Completed
Push — 1.2 ( 084ecf...54735a )
by Kamil
40:25 queued 22:44
created

ContactContext::assertFieldValidationMessage()   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 3
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Shop;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Shop\Contact\ContactPageInterface;
19
use Sylius\Behat\Service\NotificationCheckerInterface;
20
use Webmozart\Assert\Assert;
21
22
final class ContactContext implements Context
23
{
24
    /**
25
     * @var ContactPageInterface
26
     */
27
    private $contactPage;
28
29
    /**
30
     * @var NotificationCheckerInterface
31
     */
32
    private $notificationChecker;
33
34
    /**
35
     * @param ContactPageInterface $contactPage
36
     * @param NotificationCheckerInterface $notificationChecker
37
     */
38
    public function __construct(
39
        ContactPageInterface $contactPage,
40
        NotificationCheckerInterface $notificationChecker
41
    ) {
42
        $this->contactPage = $contactPage;
43
        $this->notificationChecker = $notificationChecker;
44
    }
45
46
    /**
47
     * @When I want to request contact
48
     */
49
    public function iWantToRequestContact()
50
    {
51
        $this->contactPage->open();
52
    }
53
54
    /**
55
     * @When I specify the email as :email
56
     * @When I do not specify the email
57
     */
58
    public function iSpecifyTheEmail($email = null)
59
    {
60
        $this->contactPage->specifyEmail($email);
61
    }
62
63
    /**
64
     * @When I specify the message as :message
65
     * @When I do not specify the message
66
     */
67
    public function iSpecifyTheMessage($message = null)
68
    {
69
        $this->contactPage->specifyMessage($message);
70
    }
71
72
    /**
73
     * @When I send it
74
     * @When I try to send it
75
     */
76
    public function iSendIt()
77
    {
78
        $this->contactPage->send();
79
    }
80
81
    /**
82
     * @Then I should be notified that the contact request has been submitted successfully
83
     */
84
    public function iShouldBeNotifiedThatTheContactRequestHasBeenSubmittedSuccessfully()
85
    {
86
        $this->notificationChecker->checkNotification(
87
            'Your contact request has been submitted successfully.',
88
            NotificationType::success()
89
        );
90
    }
91
92
    /**
93
     * @Then /^I should be notified that the (email|message) is required$/
94
     */
95
    public function iShouldBeNotifiedThatElementIsRequired($element)
96
    {
97
        Assert::same($this->contactPage->getValidationMessageFor($element), sprintf('Please enter your %s.', $element));
98
    }
99
100
    /**
101
     * @Then I should be notified that the email is invalid
102
     */
103
    public function iShouldBeNotifiedThatEmailIsInvalid()
104
    {
105
        Assert::same($this->contactPage->getValidationMessageFor('email'), 'This email is invalid.');
106
    }
107
108
    /**
109
     * @Then I should be notified that a problem occurred while sending the contact request
110
     */
111
    public function iShouldBeNotifiedThatAProblemOccurredWhileSendingTheContactRequest()
112
    {
113
        $this->notificationChecker->checkNotification(
114
            'A problem occurred while sending the contact request. Please try again later.',
115
            NotificationType::failure()
116
        );
117
    }
118
}
119