Completed
Push — master ( 85508a...fbb5f8 )
by Kamil
24:40
created

ShowPage::getDefaultAddress()   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\Admin\Customer;
13
14
use Sylius\Behat\Page\SymfonyPage;
15
use Webmozart\Assert\Assert;
16
17
/**
18
 * @author Magdalena Banasiak <[email protected]>
19
 */
20
class ShowPage extends SymfonyPage implements ShowPageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function isRegistered()
26
    {
27
        $username = $this->getDocument()->find('css', '#username');
28
29
        return null !== $username;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function deleteAccount()
36
    {
37
        $deleteButton = $this->getElement('delete_account_button');
38
        $deleteButton->pressButton('Delete');
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getCustomerEmail()
45
    {
46
        return $this->getElement('customer_email')->getText();
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getCustomerName()
53
    {
54
        return $this->getElement('customer_name')->getText();
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getRegistrationDate()
61
    {
62
        return new \DateTime(str_replace('Customer since ', '', $this->getElement('registration_date')->getText()));
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getDefaultAddress()
69
    {
70
        return $this->getElement('default_address')->getText();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function hasAccount()
77
    {
78
        return $this->hasElement('no_account');
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function isSubscribedToNewsletter()
85
    {
86
        $subscribedToNewsletter = $this->getElement('subscribed_to_newsletter');
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $subscribedToNewsletter exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
87
        if ($subscribedToNewsletter->find('css', 'i.green')) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return (bool) $subscribe...find('css', 'i.green');.
Loading history...
88
            return true;
89
        }
90
91
        return false;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function hasDefaultAddressProvinceName($provinceName)
98
    {
99
        $defaultAddressProvince = $this->getElement('default_address')->getText();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $defaultAddressProvince exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
100
101
        return false !== stripos($defaultAddressProvince, $provinceName);
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function getRouteName()
108
    {
109
        return 'sylius_admin_customer_show';
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    protected function getDefinedElements()
116
    {
117
        return array_merge(parent::getDefinedElements(), [
118
            'customer_email' => '#info .content.extra > a',
119
            'customer_name' => '#info .content > a',
120
            'default_address' => '#defaultAddress address',
121
            'delete_account_button' => '#actions',
122
            'no_account' => '#no-account',
123
            'registration_date' => '#info .content .date',
124
            'subscribed_to_newsletter' => '#subscribed-to-newsletter',
125
        ]);
126
    }
127
}
128