Completed
Push — master ( 3ff7e6...cf5edc )
by Kamil
96:30 queued 63:14
created

CreatePage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteName() 0 4 1
A fillAddressData() 0 9 1
A selectCountry() 0 8 1
A addAddress() 0 4 1
A hasProvinceValidationMessage() 0 4 1
A countValidationMessages() 0 4 1
A getDefinedElements() 0 12 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 Sylius\Behat\Page\SymfonyPage;
15
use Sylius\Component\Core\Model\AddressInterface;
16
17
/**
18
 * @author Anna Walasek <[email protected]>
19
 */
20
class CreatePage extends SymfonyPage implements CreatePageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getRouteName()
26
    {
27
        return 'sylius_shop_account_address_book_create';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function fillAddressData(AddressInterface $address)
34
    {
35
        $this->getElement('first_name')->setValue($address->getFirstName());
36
        $this->getElement('last_name')->setValue($address->getLastName());
37
        $this->getElement('street')->setValue($address->getStreet());
38
        $this->getElement('country')->selectOption($address->getCountryCode());
39
        $this->getElement('city')->setValue($address->getCity());
40
        $this->getElement('postcode')->setValue($address->getPostcode());
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function selectCountry($name)
47
    {
48
        $this->getElement('country')->selectOption($name);
49
50
        $this->getDocument()->waitFor(5, function () {
51
            return false;
52
        });
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function addAddress()
59
    {
60
        $this->getElement('add_button')->press();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function hasProvinceValidationMessage()
67
    {
68
        return null !== $this->getDocument()->find('css', '.sylius-validation-error:contains("province")');
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function countValidationMessages()
75
    {
76
        return count($this->getDocument()->findAll('css', '.sylius-validation-error'));
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    protected function getDefinedElements()
83
    {
84
        return array_merge(parent::getDefinedElements(), [
85
            'add_button' => 'button:contains("Add")',
86
            'city' => '#sylius_address_city',
87
            'country' => '#sylius_address_countryCode',
88
            'first_name' => '#sylius_address_firstName',
89
            'last_name' => '#sylius_address_lastName',
90
            'postcode' => '#sylius_address_postcode',
91
            'street' => '#sylius_address_street',
92
        ]);
93
    }
94
}
95