Completed
Push — master ( 6d05bc...71ecc8 )
by Kamil
25:05
created

IndexPage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteName() 0 4 1
A isSingleAddressOnList() 0 4 1
A hasAddressFullName() 0 4 1
A hasNoAddresses() 0 4 1
A deleteAddress() 0 5 1
A getAddressOf() 0 4 1
A getDefinedElements() 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 Anna Walasek <[email protected]>
19
 * @author Jan Góralski <[email protected]>
20
 */
21
class IndexPage extends SymfonyPage implements IndexPageInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getRouteName()
27
    {
28
        return 'sylius_shop_account_address_book_index';
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function isSingleAddressOnList()
35
    {
36
        return 1 === count($this->getElement('addresses')->findAll('css', 'address'));
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function hasAddressFullName($fullName)
43
    {
44
        return null !== $this->getAddressOf($fullName);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function hasNoAddresses()
51
    {
52
        return $this->getDocument()->hasContent('You have no addresses defined');
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function deleteAddress($fullName)
59
    {
60
        $addressToDelete = $this->getAddressOf($fullName);
61
        $addressToDelete->pressButton('Delete');
62
    }
63
64
    /**
65
     * @param string $fullName
66
     *
67
     * @return NodeElement|null
68
     */
69
    private function getAddressOf($fullName)
70
    {
71
        return $this->getElement('addresses')->find('css', sprintf('div:contains("%s")', $fullName));
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    protected function getDefinedElements()
78
    {
79
        return array_merge(parent::getDefinedElements(), [
80
            'addresses' => '#sylius-addresses',
81
        ]);
82
    }
83
}
84