Completed
Push — master ( b31cd6...60f5be )
by Kamil
43:45
created

ShippingPage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 8
c 3
b 1
f 2
lcom 1
cbo 3
dl 0
loc 66
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRouteName() 0 4 1
A selectShippingMethod() 0 7 1
A hasShippingMethod() 0 10 2
A hasNoShippingMethodsMessage() 0 10 2
A nextStep() 0 4 1
A getDefinedElements() 0 8 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\Checkout;
13
14
use Behat\Mink\Exception\ElementNotFoundException;
15
use Sylius\Behat\Page\SymfonyPage;
16
17
/**
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
class ShippingPage extends SymfonyPage implements ShippingPageInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getRouteName()
26
    {
27
        return 'sylius_shop_checkout_shipping';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function selectShippingMethod($shippingMethod)
34
    {
35
        $shippingMethodElement = $this->getElement('shipping_method');
36
        $shippingMethodValue = $this->getElement('shipping_method_option', ['%shipping_method%' => $shippingMethod])->getValue();
37
38
        $shippingMethodElement->selectOption($shippingMethodValue);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function hasShippingMethod($shippingMethod)
45
    {
46
        try {
47
            $this->getElement('shipping_method_option', ['%shipping_method%' => $shippingMethod]);
48
        } catch (ElementNotFoundException $exception) {
49
            return false;
50
        }
51
52
        return true;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function hasNoShippingMethodsMessage()
59
    {
60
        try {
61
            $this->getElement('order_cannot_be_shipped_message');
62
        } catch (ElementNotFoundException $exception) {
63
            return false;
64
        }
65
66
        return true;
67
    }
68
69
    public function nextStep()
70
    {
71
        $this->getDocument()->pressButton('Next');
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    protected function getDefinedElements()
78
    {
79
        return array_merge(parent::getDefinedElements(), [
80
            'order_cannot_be_shipped_message' => '#sylius-order-cannot-be-shipped',
81
            'shipping_method' => '[name="sylius_shop_checkout_shipping[shipments][0][method]"]',
82
            'shipping_method_option' => '.item:contains("%shipping_method%") input',
83
        ]);
84
    }
85
}
86