Completed
Push — master ( c66308...141223 )
by Kamil
28:38 queued 09:41
created

UpdatePage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 84
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteName() 0 4 1
A fillField() 0 5 1
A specifyProvince() 0 7 1
A selectProvince() 0 7 1
A selectCountry() 0 5 1
A saveChanges() 0 4 1
A getDefinedElements() 0 14 1
A waitForElement() 0 6 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
namespace Sylius\Behat\Page\Shop\Account\AddressBook;
13
14
use Behat\Mink\Element\NodeElement;
15
use Sylius\Behat\Page\SymfonyPage;
16
17
/**
18
 * @author Jan Góralski <[email protected]>
19
 */
20
final class UpdatePage extends SymfonyPage implements UpdatePageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getRouteName()
26
    {
27
        return 'sylius_shop_account_address_book_update';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function fillField($field, $value)
34
    {
35
        $field = $this->getElement(str_replace(' ', '_',strtolower($field)));
36
        $field->setValue($value);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function specifyProvince($name)
43
    {
44
        $this->waitForElement(5, 'province_name');
45
46
        $province = $this->getElement('province_name');
47
        $province->setValue($name);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function selectProvince($name)
54
    {
55
        $this->waitForElement(5, 'province_code');
56
57
        $province = $this->getElement('province_code');
58
        $province->selectOption($name);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function selectCountry($name)
65
    {
66
        $country = $this->getElement('country');
67
        $country->selectOption($name);
68
    }
69
70
    public function saveChanges()
71
    {
72
        $this->getElement('save_button')->press();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    protected function getDefinedElements()
79
    {
80
        return array_merge(parent::getDefinedElements(), [
81
            'city' => '#sylius_address_city',
82
            'country' => '#sylius_address_countryCode',
83
            'first_name' => '#sylius_address_firstName',
84
            'last_name' => '#sylius_address_lastName',
85
            'postcode' => '#sylius_address_postcode',
86
            'province_name' => 'input[name="sylius_address[provinceName]"]',
87
            'province_code' => 'select[name="sylius_address[provinceCode]"]',
88
            'save_button' => 'button:contains("Save changes")',
89
            'street' => '#sylius_address_street',
90
        ]);
91
    }
92
93
    /**
94
     * @param int $timeout
95
     * @param string $elementName
96
     */
97
    private function waitForElement($timeout, $elementName)
98
    {
99
        $this->getDocument()->waitFor($timeout, function () use ($elementName){
100
            return $this->hasElement($elementName);
101
        });
102
    }
103
}
104