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

CreatePage::getRouteName()   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 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\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