Completed
Push — pull-request/7087 ( 0e723b )
by Kamil
35:51 queued 08:28
created

CreatePage::getDefinedElements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
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\Page\Admin\ProductVariant;
13
14
use Behat\Mink\Exception\ElementNotFoundException;
15
use Sylius\Behat\Behaviour\SpecifiesItsCode;
16
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
17
use Sylius\Component\Core\Model\ChannelInterface;
18
use Sylius\Component\Currency\Model\CurrencyInterface;
19
20
/**
21
 * @author Łukasz Chruściel <[email protected]>
22
 * @author Gorka Laucirica <[email protected]>
23
 */
24
class CreatePage extends BaseCreatePage implements CreatePageInterface
25
{
26
    use SpecifiesItsCode;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function specifyPrice($price, $channelName)
32
    {
33
        $this->getElement('price', ['%channelName%' => $channelName])->setValue($price);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function specifyOriginalPrice($originalPrice, $channelName)
40
    {
41
        $this->getElement('original_price', ['%channelName%' => $channelName])->setValue($originalPrice);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function specifyCurrentStock($currentStock)
48
    {
49
        $this->getDocument()->fillField('Current stock', $currentStock);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function specifyHeightWidthDepthAndWeight($height, $width, $depth, $weight)
56
    {
57
        $this->getDocument()->fillField('Height', $height);
58
        $this->getDocument()->fillField('Width', $width);
59
        $this->getDocument()->fillField('Depth', $depth);
60
        $this->getDocument()->fillField('Weight', $weight);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function nameItIn($name, $language)
67
    {
68
        $this->getDocument()->fillField(
69
            sprintf('sylius_product_variant_translations_%s_name', $language), $name
70
        );
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function selectOption($optionName, $optionValue)
77
    {
78
        $optionName = strtoupper($optionName);
79
        $this->getElement('option_select', ['%option-name%' => $optionName])->selectOption($optionValue);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function choosePricingCalculator($name)
86
    {
87
        $this->getElement('price_calculator')->selectOption($name);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function specifyPriceForChannelAndCurrency($price, ChannelInterface $channel, CurrencyInterface $currency)
94
    {
95
        $calculatorElement = $this->getElement('calculator');
96
        $calculatorElement
97
            ->waitFor(5, function () use ($channel, $currency) {
98
                return $this->getElement('calculator')->hasField(sprintf('%s %s', $channel->getName(), $currency->getCode()));
99
            })
100
        ;
101
102
        $calculatorElement->fillField(sprintf('%s %s', $channel->getName(), $currency->getCode()), $price);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getValidationMessageForForm()
109
    {
110
        $formElement = $this->getDocument()->find('css', 'form[name="sylius_product_variant"]');
111
        if (null === $formElement) {
112
            throw new ElementNotFoundException($this->getSession(), 'Field element');
113
        }
114
115
        $validationMessage = $formElement->find('css', '.sylius-validation-error');
116
        if (null === $validationMessage) {
117
            throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
118
        }
119
120
        return $validationMessage->getText();
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function selectShippingCategory($shippingCategoryName)
127
    {
128
        $this->getElement('shipping_category')->selectOption($shippingCategoryName);
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function getPricesValidationMessage()
135
    {
136
        return $this->getElement('prices_validation_message')->getText();
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    protected function getDefinedElements()
143
    {
144
        return array_merge(parent::getDefinedElements(), [
145
            'calculator' => '#sylius_calculator_container',
146
            'code' => '#sylius_product_variant_code',
147
            'depth' => '#sylius_product_variant_depth',
148
            'form' => 'form[name="sylius_product_variant"]',
149
            'height' => '#sylius_product_variant_height',
150
            'on_hand' => '#sylius_product_variant_onHand',
151
            'option_select' => '#sylius_product_variant_optionValues_%option-name%',
152
            'price_calculator' => '#sylius_product_variant_pricingCalculator',
153
            'shipping_category' => '#sylius_product_variant_shippingCategory',
154
            'original_price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[originalPrice]"]',
155
            'price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[price]"]',
156
            'prices_validation_message' => '#sylius_product_variant_channelPricings ~ .sylius-validation-error, #sylius_product_variant_channelPricings .sylius-validation-error',
157
            'weight' => '#sylius_product_variant_weight',
158
            'width' => '#sylius_product_variant_width',
159
        ]);
160
    }
161
}
162