Completed
Push — unused-definitions ( d9908f )
by Kamil
18:33
created

ManagingCurrenciesContext::iCannotDisableIt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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\Page\Admin\Currency\CreatePageInterface;
16
use Sylius\Behat\Page\Admin\Currency\IndexPageInterface;
17
use Sylius\Behat\Page\Admin\Currency\UpdatePageInterface;
18
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
19
use Sylius\Component\Currency\Model\CurrencyInterface;
20
use Webmozart\Assert\Assert;
21
22
/**
23
 * @author Anna Walasek <[email protected]>
24
 */
25
final class ManagingCurrenciesContext implements Context
26
{
27
    /**
28
     * @var IndexPageInterface
29
     */
30
    private $indexPage;
31
32
    /**
33
     * @var CreatePageInterface
34
     */
35
    private $createPage;
36
37
    /**
38
     * @var UpdatePageInterface
39
     */
40
    private $updatePage;
41
42
    /**
43
     * @var CurrentPageResolverInterface
44
     */
45
    private $currentPageResolver;
46
47
    /**
48
     * @param IndexPageInterface $indexPage
49
     * @param CreatePageInterface $createPage
50
     * @param UpdatePageInterface $updatePage
51
     * @param CurrentPageResolverInterface $currentPageResolver
52
     */
53
    public function __construct(
54
        IndexPageInterface $indexPage,
55
        CreatePageInterface $createPage,
56
        UpdatePageInterface $updatePage,
57
        CurrentPageResolverInterface $currentPageResolver
58
    ) {
59
        $this->createPage = $createPage;
60
        $this->indexPage = $indexPage;
61
        $this->updatePage = $updatePage;
62
        $this->currentPageResolver = $currentPageResolver;
63
    }
64
65
    /**
66
     * @Given I want to add a new currency
67
     */
68
    public function iWantToAddNewCurrency()
69
    {
70
        $this->createPage->open();
71
    }
72
73
    /**
74
     * @When I choose :currencyName
75
     */
76
    public function iChoose($currencyName)
77
    {
78
        $this->createPage->chooseName($currencyName);
79
    }
80
81
    /**
82
     * @When I add it
83
     * @When I try to add it
84
     */
85
    public function iAddIt()
86
    {
87
        $this->createPage->create();
88
    }
89
90
    /**
91
     * @Then the currency :currency should appear in the store
92
     * @Then I should see the currency :currency in the list
93
     */
94
    public function currencyShouldAppearInTheStore(CurrencyInterface $currency)
95
    {
96
        $this->indexPage->open();
97
98
        Assert::true(
99
            $this->indexPage->isSingleResourceOnPage(['code' => $currency->getCode()]),
100
            sprintf('Currency %s should exist but it does not.', $currency->getCode())
101
        );
102
    }
103
104
    /**
105
     * @Given /^I want to edit (this currency)$/
106
     */
107
    public function iWantToEditThisCurrency(CurrencyInterface $currency)
108
    {
109
        $this->updatePage->open(['id' => $currency->getId()]);
110
    }
111
112
    /**
113
     * @When I enable it
114
     */
115
    public function iEnableIt()
116
    {
117
        $this->updatePage->enable();
118
    }
119
120
    /**
121
     * @When I disable it
122
     */
123
    public function iDisableIt()
124
    {
125
        $this->updatePage->disable();
126
    }
127
128
    /**
129
     * @When I save my changes
130
     * @When I try to save my changes
131
     */
132
    public function iSaveMyChanges()
133
    {
134
        $this->updatePage->saveChanges();
135
    }
136
137
    /**
138
     * @Then the code field should be disabled
139
     */
140
    public function theCodeFiledShouldBeDisabled()
141
    {
142
        Assert::eq(
143
            'disabled',
144
            $this->updatePage->getCodeDisabledAttribute(),
145
            'Code field should be disabled but is not.'
146
        );
147
    }
148
149
    /**
150
     * @Then I should be notified that currency code must be unique
151
     */
152
    public function iShouldBeNotifiedThatCurrencyCodeMustBeUnique()
153
    {
154
        Assert::same($this->createPage->getValidationMessage('code'), 'Currency code must be unique.');
155
    }
156
157
    /**
158
     * @Then there should still be only one currency with :element :code
159
     */
160
    public function thereShouldStillBeOnlyOneCurrencyWithCode($element, $codeValue)
161
    {
162
        $this->indexPage->open();
163
164
        Assert::true(
165
            $this->indexPage->isSingleResourceOnPage([$element => $codeValue]),
166
            sprintf('Currency with %s %s cannot be found.', $element, $codeValue)
167
        );
168
    }
169
170
    /**
171
     * @Given I want to browse currencies of the store
172
     */
173
    public function iWantToSeeAllCurrenciesInStore()
174
    {
175
        $this->indexPage->open();
176
    }
177
178
    /**
179
     * @Then /^I should see (\d+) currencies in the list$/
180
     */
181
    public function iShouldSeeCurrenciesInTheList($amountOfCurrencies)
182
    {
183
        Assert::same(
184
            (int) $amountOfCurrencies,
185
            $this->indexPage->countItems(),
186
            sprintf(
187
                'Amount of currencies should be equal %d, but was %d.',
188
                $amountOfCurrencies,
189
                $this->indexPage->countItems()
190
            )
191
        );
192
    }
193
}
194