Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

iShouldSeeProductShowPageWithVariants()   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 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\Element\Product\ShowPage\AssociationsElementInterface;
18
use Sylius\Behat\Element\Product\ShowPage\AttributesElementInterface;
19
use Sylius\Behat\Element\Product\ShowPage\DetailsElementInterface;
20
use Sylius\Behat\Element\Product\ShowPage\MediaElementInterface;
21
use Sylius\Behat\Element\Product\ShowPage\MoreDetailsElementInterface;
22
use Sylius\Behat\Element\Product\ShowPage\OptionsElementInterface;
23
use Sylius\Behat\Element\Product\ShowPage\PricingElementInterface;
24
use Sylius\Behat\Element\Product\ShowPage\ShippingElementInterface;
25
use Sylius\Behat\Element\Product\ShowPage\TaxonomyElementIterface;
26
use Sylius\Behat\Element\Product\ShowPage\VariantsElementInterface;
27
use Sylius\Behat\Page\Admin\Product\IndexPageInterface;
28
use Sylius\Behat\Page\Admin\Product\ShowPageInterface;
29
use Sylius\Component\Core\Model\ProductInterface;
30
use Webmozart\Assert\Assert;
31
32
final class ProductShowPageContext implements Context
33
{
34
    /** @var IndexPageInterface */
35
    private $indexPage;
36
37
    /** @var ShowPageInterface */
38
    private $productShowPage;
39
40
    /** @var AssociationsElementInterface */
41
    private $associationsElement;
42
43
    /** @var AttributesElementInterface */
44
    private $attributesElement;
45
46
    /** @var DetailsElementInterface */
47
    private $detailsElement;
48
49
    /** @var MediaElementInterface */
50
    private $mediaElement;
51
52
    /** @var MoreDetailsElementInterface */
53
    private $moreDetailsElement;
54
55
    /** @var PricingElementInterface */
56
    private $pricingElement;
57
58
    /** @var ShippingElementInterface */
59
    private $shippingElement;
60
61
    /** @var TaxonomyElementIterface */
62
    private $taxonomyElement;
63
64
    /** @var OptionsElementInterface */
65
    private $optionsElement;
66
67
    /** @var VariantsElementInterface */
68
    private $variantsElement;
69
70
    public function __construct(
71
        IndexPageInterface $indexPage,
72
        ShowPageInterface $productShowPage,
73
        AssociationsElementInterface $associationsElement,
74
        AttributesElementInterface $attributesElement,
75
        DetailsElementInterface $detailsElement,
76
        MediaElementInterface $mediaElement,
77
        MoreDetailsElementInterface $moreDetailsElement,
78
        PricingElementInterface $pricingElement,
79
        ShippingElementInterface $shippingElement,
80
        TaxonomyElementIterface $taxonomyElement,
81
        OptionsElementInterface $optionsElement,
82
        VariantsElementInterface $variantsElement
83
    ) {
84
        $this->indexPage = $indexPage;
85
        $this->productShowPage = $productShowPage;
86
        $this->associationsElement = $associationsElement;
87
        $this->attributesElement = $attributesElement;
88
        $this->detailsElement = $detailsElement;
89
        $this->mediaElement = $mediaElement;
90
        $this->moreDetailsElement = $moreDetailsElement;
91
        $this->pricingElement = $pricingElement;
92
        $this->shippingElement = $shippingElement;
93
        $this->taxonomyElement = $taxonomyElement;
94
        $this->optionsElement = $optionsElement;
95
        $this->variantsElement = $variantsElement;
96
    }
97
98
    /**
99
     * @Given I am browsing products
100
     */
101
    public function iAmBrowsingProducts(): void
102
    {
103
        $this->indexPage->open();
104
    }
105
106
    /**
107
     * @When I access :product product page
108
     */
109
    public function iAccessProductPage(ProductInterface $product): void
110
    {
111
        $this->indexPage->showProductPage($product->getName());
112
    }
113
114
    /**
115
     * @Then I should see this product's product page
116
     */
117
    public function iShouldSeeThisProductPage(ProductInterface $product): void
118
    {
119
        Assert::true($this->productShowPage->isOpen(['id' => $product->getId()]));
120
    }
121
122
    /**
123
     * @Then I should see product show page without variants
124
     */
125
    public function iShouldSeeProductShowPageWithoutVariants(): void
126
    {
127
        Assert::true($this->productShowPage->isSimpleProductPage());
128
    }
129
130
    /**
131
     * @Then I should see product show page with variants
132
     */
133
    public function iShouldSeeProductShowPageWithVariants(): void
134
    {
135
        Assert::false($this->productShowPage->isSimpleProductPage());
136
    }
137
138
    /**
139
     * @Then I should see product name :productName
140
     */
141
    public function iShouldSeeProductName(string $productName): void
142
    {
143
        Assert::same($productName, $this->productShowPage->getName());
144
    }
145
146
    /**
147
     * @Then I should see price :price for channel :channelName
148
     */
149
    public function iShouldSeePriceForChannel(string $price, string $channelName): void
150
    {
151
        Assert::same($this->pricingElement->getPriceForChannel($channelName), $price);
152
    }
153
154
    /**
155
     * @Then I should see original price :price for channel :channelName
156
     */
157
    public function iShouldSeeOrginalPriceForChannel(string $orginalPrice, string $channelName): void
158
    {
159
        Assert::same($this->pricingElement->getOriginalPriceForChannel($channelName), $orginalPrice);
160
    }
161
162
    /**
163
     * @Then I should see product's code is :code
164
     */
165
    public function iShouldSeeProductCodeIs(string $code): void
166
    {
167
        Assert::same($this->detailsElement->getProductCode(), $code);
168
    }
169
170
    /**
171
     * @Then I should see the product is enabled for channel :channel
172
     */
173
    public function iShouldSeeProductIsEnabledForChannels(string $channel): void
174
    {
175
        Assert::true($this->detailsElement->hasChannel($channel));
176
    }
177
178
    /**
179
     * @Then I should see :currentStock as a current stock of this product
180
     */
181
    public function iShouldSeeAsACurrentStockOfThisProduct(int $currentStock): void
182
    {
183
        Assert::same($this->detailsElement->getProductCurrentStock(), $currentStock);
184
    }
185
186
    /**
187
     * @Then I should see product's tax category is :taxCategory
188
     */
189
    public function iShouldSeeProductTaxCategoryIs(string $taxCategory): void
190
    {
191
        Assert::same($this->detailsElement->getProductTaxCategory(), $taxCategory);
192
    }
193
194
    /**
195
     * @Then I should see main taxon is :mainTaxonName
196
     */
197
    public function iShouldSeeMainTaxonIs(string $mainTaxonName): void
198
    {
199
        Assert::same($this->taxonomyElement->getProductMainTaxon(), $mainTaxonName);
200
    }
201
202
    /**
203
     * @Then I should see product taxon is :taxonName
204
     */
205
    public function iShouldSeeProductTaxonIs(string $taxonName): void
206
    {
207
        Assert::true($this->taxonomyElement->hasProductTaxon($taxonName));
208
    }
209
210
    /**
211
     * @Then I should see product's shipping category is :shippingCategory
212
     */
213
    public function iShouldSeeProductShippingCategoryIs(string $shippingCategory): void
214
    {
215
        Assert::same($this->shippingElement->getProductShippingCategory(), $shippingCategory);
216
    }
217
218
    /**
219
     * @Then I should see product's width is :width
220
     */
221
    public function iShouldSeeProductWidthIs(float $width): void
222
    {
223
        Assert::same($this->shippingElement->getProductWidth(), $width);
224
    }
225
226
    /**
227
     * @Then I should see product's height is :height
228
     */
229
    public function iShouldSeeProductHeightIs(float $height): void
230
    {
231
        Assert::same($this->shippingElement->getProductHeight(), $height);
232
    }
233
234
    /**
235
     * @Then I should see product's depth is :depth
236
     */
237
    public function iShouldSeeProductDepthIs(float $depth): void
238
    {
239
        Assert::same($this->shippingElement->getProductDepth(), $depth);
240
    }
241
242
    /**
243
     * @Then I should see product's weight is :weight
244
     */
245
    public function iShouldSeeProductWeightIs(float $weight): void
246
    {
247
        Assert::same($this->shippingElement->getProductWeight(), $weight);
248
    }
249
250
    /**
251
     * @Then I should see an image related to this product
252
     */
253
    public function iShouldSeeImageRelatedToThisProduct(): void
254
    {
255
        Assert::true($this->mediaElement->isImageDisplayed());
256
    }
257
258
    /**
259
     * @Then I should see product name is :name
260
     */
261
    public function iShouldSeeProductNameIs(string $name): void
262
    {
263
        Assert::same($this->moreDetailsElement->getName(), $name);
264
    }
265
266
    /**
267
     * @Then I should see product slug is :slug
268
     */
269
    public function iShouldSeeProductSlugIs(string $slug): void
270
    {
271
        Assert::same($this->moreDetailsElement->getSlug(), $slug);
272
    }
273
274
    /**
275
     * @Then I should see product's description is :description
276
     */
277
    public function iShouldSeeProductSDescriptionIs(string $description): void
278
    {
279
        Assert::same($this->moreDetailsElement->getDescription(), $description);
280
    }
281
282
    /**
283
     * @Then I should see product's meta keyword(s) is/are :metaKeywords
284
     */
285
    public function iShouldSeeProductMetaKeywordsAre(string $metaKeywords): void
286
    {
287
        Assert::same($this->moreDetailsElement->getProductMetaKeywords(), $metaKeywords);
288
    }
289
290
    /**
291
     * @Then I should see product's short description is :shortDescription
292
     */
293
    public function iShouldSeeProductShortDescriptionIs(string $shortDescription): void
294
    {
295
        Assert::same($this->moreDetailsElement->getShortDescription(), $shortDescription);
296
    }
297
298
    /**
299
     * @Then I should see product association :association with :productName
300
     */
301
    public function iShouldSeeProductAssociationWith(string $association, string $productName): void
302
    {
303
        Assert::true($this->associationsElement->isProductAssociated($association, $productName));
304
    }
305
306
    /**
307
     * @Then I should see option :optionName
308
     */
309
    public function iShouldSeeOption(string $optionName): void
310
    {
311
        Assert::true($this->optionsElement->isOptionDefined($optionName));
312
    }
313
314
    /**
315
     * @Then I should see :count variants
316
     */
317
    public function iShouldSeeVariants(int $count): void
318
    {
319
        Assert::same($this->variantsElement->countVariantsOnPage(), $count);
320
    }
321
322
    /**
323
     * @Then I should see :variantName variant with code :code, priced :price and current stock :currentStock
324
     */
325
    public function iShouldSeeVariantWithCodePriceAndCurrentStock(string $variantName, string $code, string $price, string $currentStock): void
326
    {
327
        Assert::true($this->variantsElement->hasProductVariantWithCodePriceAndCurrentStock($variantName, $code, $price, $currentStock));
328
    }
329
330
    /**
331
     * @Then I should see attribute :attribute with value :value in :locale locale
332
     */
333
    public function iShouldSeeAttributeWithValueInLocale(string $attribute, string $value, string $locale): void
334
    {
335
        Assert::true($this->attributesElement->hasAttributeInLocale($attribute, $locale, $value));
336
    }
337
}
338