Completed
Push — symfony3-travis-logs ( 5d92be )
by Kamil
36:50 queued 19:53
created

ShowPage::resetPassword()   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 hasVerifiedEmail()
108
    {
109
        $verifiedEmail = $this->getElement('verified_email');
110
        if ($verifiedEmail->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) $verifiedE...find('css', 'i.green');.
Loading history...
111
            return true;
112
        }
113
114
        return false;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function getGroupName()
121
    {
122
        $group = $this->getElement('group');
123
124
        Assert::notNull($group, 'There should be element group on page.');
125
126
        list($text, $groupName) = explode(':', $group->getText());
0 ignored issues
show
Unused Code introduced by
The assignment to $text is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
127
128
        return trim($groupName);
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function hasEmailVerificationInformation()
135
    {
136
        return null === $this->getDocument()->find('css', '#verified-email');
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142
    public function hasImpersonateButton()
143
    {
144
        return $this->hasElement('impersonate_button');
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150
    public function impersonate()
151
    {
152
        $this->getElement('impersonate_button')->click();
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function getSuccessFlashMessage()
159
    {
160
        return trim($this->getElement('flash_message')->getText());
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    public function getRouteName()
167
    {
168
        return 'sylius_admin_customer_show';
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174
    protected function getDefinedElements()
175
    {
176
        return array_merge(parent::getDefinedElements(), [
177
            'customer_email' => '#info .content.extra > a',
178
            'customer_name' => '#info .content > a',
179
            'default_address' => '#defaultAddress address',
180
            'delete_account_button' => '#actions',
181
            'flash_message' => '.ui.icon.positive.message .content p',
182
            'group' => '.group',
183
            'impersonate_button' => '#impersonate',
184
            'no_account' => '#no-account',
185
            'registration_date' => '#info .content .date',
186
            'subscribed_to_newsletter' => '#subscribed-to-newsletter',
187
            'verified_email' => '#verified-email',
188
        ]);
189
    }
190
}
191