Completed
Push — 1.3-php-7.3 ( e95dc4 )
by Kamil
45:30 queued 31:53
created

ShowPage::getNumberOfItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Page\Shop\Order;
15
16
use Behat\Mink\Element\NodeElement;
17
use Sylius\Behat\Page\SymfonyPage;
18
19
class ShowPage extends SymfonyPage implements ShowPageInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function hasPayAction()
25
    {
26
        return $this->hasElement('pay_link');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function pay()
33
    {
34
        $this->getElement('pay_link')->click();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getNotifications()
41
    {
42
        /** @var NodeElement[] $notificationElements */
43
        $notificationElements = $this->getDocument()->findAll('css', '.message > .content > p');
44
        $notifications = [];
45
46
        foreach ($notificationElements as $notificationElement) {
47
            $notifications[] = $notificationElement->getText();
48
        }
49
50
        return $notifications;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function choosePaymentMethod($paymentMethodName)
57
    {
58
        $paymentMethodElement = $this->getElement('payment_method', ['%name%' => $paymentMethodName]);
59
        $paymentMethodElement->selectOption($paymentMethodElement->getAttribute('value'));
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getRouteName()
66
    {
67
        return 'sylius_shop_order_show';
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getNumberOfItems(): int
74
    {
75
        $itemsText = trim($this->getElement('items_text')->getText());
76
        $itemsTextWords = explode(' ', $itemsText);
77
78
        return (int) $itemsTextWords[0];
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    protected function getDefinedElements()
85
    {
86
        return array_merge(parent::getDefinedElements(), [
87
            'instructions' => '#sylius-payment-method-instructions',
88
            'items_text' => 'div.sub.header div.item:nth-child(3)',
89
            'pay_link' => '#sylius-pay-link',
90
            'payment_method' => '.item:contains("%name%") input',
91
            'thank_you' => '#sylius-thank-you',
92
        ]);
93
    }
94
}
95