Completed
Push — master ( 9a4fa3...1bdebc )
by Kamil
31:53 queued 20:23
created

UpdatePage::hasAttributeValue()   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\Element\NodeElement;
17
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
18
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
19
use Webmozart\Assert\Assert;
20
21
/**
22
 * @author Anna Walasek <[email protected]>
23
 */
24
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
25
{
26
    use ChecksCodeImmutability;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function changeName($name, $language)
32
    {
33
        $this->getDocument()->fillField(sprintf('sylius_product_attribute_translations_%s_name', $language), $name);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function isTypeDisabled()
40
    {
41
        return 'disabled' === $this->getElement('type')->getAttribute('disabled');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function getCodeElement()
48
    {
49
        return $this->getElement('code');
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function changeAttributeValue(string $oldValue, string $newValue): void
56
    {
57
        $this->getElement('attribute_choice_list_element', ['%value%' => $oldValue])->setValue($newValue);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function hasAttributeValue(string $value): bool
64
    {
65
        return null !== $this->getElement('attribute_choice_list_element', ['%value%' => $value]);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function addAttributeValue(string $value): void
72
    {
73
        $this->getDocument()->clickLink('Add');
74
        $this->getLastAttributeChoiceElement()->find('css', 'input')->setValue($value);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    protected function getDefinedElements()
81
    {
82
        return array_merge(parent::getDefinedElements(), [
83
            'attribute_choice_list_element' => 'input[value="%value%"]',
84
            'attribute_choices' => '#sylius_product_attribute_configuration_choices',
85
            'code' => '#sylius_product_attribute_code',
86
            'type' => '#sylius_product_attribute_type',
87
            'name' => '#sylius_product_attribute_translations_en_US_name',
88
        ]);
89
    }
90
91
    /**
92
     * @return NodeElement[]
93
     */
94
    private function getAttributeChoiceElements(): array
95
    {
96
        $attributeChoices = $this->getElement('attribute_choices');
97
98
        return $attributeChoices->findAll('css', 'div[data-form-collection="item"]');
99
    }
100
101
    /**
102
     * @return NodeElement
103
     */
104
    private function getLastAttributeChoiceElement(): NodeElement
105
    {
106
        $elements = $this->getAttributeChoiceElements();
107
108
        Assert::notEmpty($elements);
109
110
        return end($elements);
111
    }
112
}
113