Completed
Push — master ( a752ac...3b9af8 )
by Kamil
41:58 queued 31:09
created

CreatePage::specifyMaxValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Page\Admin\ProductAttribute;
15
16
use Behat\Mink\Exception\ElementNotFoundException;
17
use Sylius\Behat\Behaviour\SpecifiesItsCode;
18
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
19
20
/**
21
 * @author Anna Walasek <[email protected]>
22
 */
23
class CreatePage extends BaseCreatePage implements CreatePageInterface
24
{
25
    use SpecifiesItsCode;
26
27
    /**
28
     * @var int
29
     */
30
    private $choiceListIndex = 0;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function nameIt($name, $language)
36
    {
37
        $this->getDocument()->fillField(sprintf('sylius_product_attribute_translations_%s_name', $language), $name);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function isTypeDisabled()
44
    {
45
        return 'disabled' === $this->getElement('type')->getAttribute('disabled');
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function addAttributeValue($value)
52
    {
53
        $this->getDocument()->clickLink('Add');
54
        $this->getElement('attribute_choice_list_element', ['%index%' => $this->choiceListIndex])->setValue($value);
55
        ++$this->choiceListIndex;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function specifyMinValue(int $min): void
62
    {
63
        $this->getElement('min')->setValue($min);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function specifyMaxValue(int $max): void
70
    {
71
        $this->getElement('max')->setValue($max);
72
    }
73
74
    public function checkMultiple(): void
75
    {
76
        $this->getElement('multiple')->click();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getValidationErrors(): string
83
    {
84
        $validationMessage = $this->getDocument()->find('css', '.sylius-validation-error');
85
        if (null === $validationMessage) {
86
            throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error');
87
        }
88
89
        return $validationMessage->getText();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    protected function getDefinedElements()
96
    {
97
        return array_merge(parent::getDefinedElements(), [
98
            'attribute_choice_list' => 'div[data-form-collection="list"]',
99
            'attribute_choice_list_element' => '#sylius_product_attribute_configuration_choices_%index%',
100
            'code' => '#sylius_product_attribute_code',
101
            'max' => '#sylius_product_attribute_configuration_max',
102
            'min' => '#sylius_product_attribute_configuration_min',
103
            'multiple' => 'label[for=sylius_product_attribute_configuration_multiple]',
104
            'name' => '#sylius_product_attribute_translations_en_US_name',
105
            'type' => '#sylius_product_attribute_type',
106
        ]);
107
    }
108
}
109