Completed
Push — pagerfanta-fix ( 187c46...923c07 )
by Kamil
25:06 queued 03:45
created

ManagingCurrenciesContext::theCurrencyShouldStillHaveExchangeRateEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 9
nop 2
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
     * @When I specify its exchange rate as :exchangeRate
92
     */
93
    public function iSpecifyExchangeRate($exchangeRate)
94
    {
95
        $this->createPage->specifyExchangeRate($exchangeRate);
96
    }
97
98
    /**
99
     * @Then the currency :currency should appear in the store
100
     * @Then I should see the currency :currency in the list
101
     */
102
    public function currencyShouldAppearInTheStore(CurrencyInterface $currency)
103
    {
104
        $this->indexPage->open();
105
106
        Assert::true(
107
            $this->indexPage->isSingleResourceOnPage(['code' => $currency->getCode()]),
108
            sprintf('Currency %s should exist but it does not.', $currency->getCode())
109
        );
110
    }
111
112
    /**
113
     * @Given /^I want to edit (this currency)$/
114
     */
115
    public function iWantToEditThisCurrency(CurrencyInterface $currency)
116
    {
117
        $this->updatePage->open(['id' => $currency->getId()]);
118
    }
119
120
    /**
121
     * @When I enable it
122
     */
123
    public function iEnableIt()
124
    {
125
        $this->updatePage->enable();
126
    }
127
128
    /**
129
     * @When I disable it
130
     */
131
    public function iDisableIt()
132
    {
133
        $this->updatePage->disable();
134
    }
135
136
    /**
137
     * @Then I should not be able to disable this currency
138
     */
139
    public function iCannotDisableIt()
140
    {
141
        Assert::true(
142
            $this->updatePage->canBeDisabled(),
143
            'I should not be able to disable this currency.'
144
        );
145
    }
146
147
    /**
148
     * @When I save my changes
149
     * @When I try to save my changes
150
     */
151
    public function iSaveMyChanges()
152
    {
153
        $this->updatePage->saveChanges();
154
    }
155
156
    /**
157
     * @Then /^(this currency) should be disabled$/
158
     */
159
    public function thisCurrencyShouldBeDisabled(CurrencyInterface $currency)
160
    {
161
        $this->indexPage->open();
162
163
        Assert::true(
164
            $this->indexPage->isCurrencyDisabled($currency),
165
            sprintf('Currency %s should be disabled but it is not.', $currency->getCode())
166
        );
167
    }
168
169
    /**
170
     * @Then /^(this currency) should be enabled$/
171
     */
172
    public function thisCurrencyShouldBeEnabled(CurrencyInterface $currency)
173
    {
174
        $this->indexPage->open();
175
176
        Assert::true(
177
            $this->indexPage->isCurrencyEnabled($currency),
178
            sprintf('Currency %s should be enabled but it is not.', $currency->getCode())
179
        );
180
    }
181
182
    /**
183
     * @Then the code field should be disabled
184
     */
185
    public function theCodeFiledShouldBeDisabled()
186
    {
187
        Assert::eq(
188
            'disabled',
189
            $this->updatePage->getCodeDisabledAttribute(),
190
            'Code field should be disabled but is not.'
191
        );
192
    }
193
194
    /**
195
     * @Then I should be notified that currency code must be unique
196
     */
197
    public function iShouldBeNotifiedThatCurrencyCodeMustBeUnique()
198
    {
199
        Assert::same($this->createPage->getValidationMessage('code'), 'Currency code must be unique.');
200
    }
201
202
    /**
203
     * @Then there should still be only one currency with :element :code
204
     */
205
    public function thereShouldStillBeOnlyOneCurrencyWithCode($element, $codeValue)
206
    {
207
        $this->indexPage->open();
208
209
        Assert::true(
210
            $this->indexPage->isSingleResourceOnPage([$element => $codeValue]),
211
            sprintf('Currency with %s %s cannot be found.', $element, $codeValue)
212
        );
213
    }
214
215
    /**
216
     * @Then the currency :currencyName should not be added
217
     */
218
    public function theCurrencyShouldNotBeAdded($currencyName)
219
    {
220
        $this->indexPage->open();
221
222
        Assert::false(
223
            $this->indexPage->isSingleResourceOnPage(['name' => $currencyName]),
224
            sprintf('Currency with name %s was created, but it should not.', $currencyName)
225
        );
226
    }
227
228
    /**
229
     * @Given I want to browse currencies of the store
230
     */
231
    public function iWantToSeeAllCurrenciesInStore()
232
    {
233
        $this->indexPage->open();
234
    }
235
236
    /**
237
     * @Then /^I should see (\d+) currencies in the list$/
238
     */
239
    public function iShouldSeeCurrenciesInTheList($amountOfCurrencies)
240
    {
241
        Assert::same(
242
            (int) $amountOfCurrencies,
243
            $this->indexPage->countItems(),
244
            sprintf(
245
                'Amount of currencies should be equal %d, but was %d.',
246
                $amountOfCurrencies,
247
                $this->indexPage->countItems()
248
            )
249
        );
250
    }
251
}
252