Completed
Push — master ( 71b70e...42cf72 )
by Kamil
19:08
created

ProductShowPage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addToCart() 0 4 1
A addToCartWithQuantity() 0 5 1
A addToCartWithVariant() 0 9 1
A getRouteName() 0 3 1
A getUrl() 0 11 3
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\Product;
13
14
use Sylius\Behat\SymfonyPageObjectExtension\PageObject\SymfonyPage;
15
use Sylius\Component\Core\Model\ProductInterface;
16
17
/**
18
 * @author Arkadiusz Krakowiak <[email protected]>
19
 */
20
class ProductShowPage extends SymfonyPage
21
{
22
    public function addToCart()
23
    {
24
        $this->getDocument()->pressButton('Add to cart');
25
    }
26
27
    /**
28
     * @param string $quantity
29
     */
30
    public function addToCartWithQuantity($quantity)
31
    {
32
        $this->getDocument()->fillField('Quantity', $quantity);
33
        $this->getDocument()->pressButton('Add to cart');
34
    }
35
36
    /**
37
     * @param string $variant
38
     */
39
    public function addToCartWithVariant($variant)
40
    {
41
        $item = $this->getDocument()->find('css', sprintf('#product-variants tbody tr:contains("%s")', $variant));
42
        $radio = $item->find('css', 'input');
43
44
        $this->getDocument()->fillField($radio->getAttribute('name'), $radio->getAttribute('value'));
45
46
        $this->getDocument()->pressButton('Add to cart');
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function getRouteName()
53
    {
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function getUrl(array $urlParameters = [])
60
    {
61
        if (!isset($urlParameters['product']) || !$urlParameters['product'] instanceof ProductInterface) {
62
            throw new \InvalidArgumentException(
63
                'There should be only one url parameter passed to ProductShowPage '.
64
                'named "product", containing an instance of Core\'s ProductInterface'
65
            );
66
        }
67
68
        return $this->router->generate($urlParameters['product'], [], true);
69
    }
70
}
71