Completed
Push — master ( 7c0075...645752 )
by Kamil
18:52
created

IndexPerTaxonPage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasProductsInOrder() 0 12 3
A setPositionOfProduct() 0 8 1
A savePositions() 0 8 1
A getDefinedElements() 0 6 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\Admin\Product;
13
14
use Behat\Mink\Driver\Selenium2Driver;
15
use Behat\Mink\Element\NodeElement;
16
use Behat\Mink\Exception\UnsupportedDriverActionException;
17
use Sylius\Behat\Page\Admin\Crud\IndexPage as CrudIndexPage;
18
use Sylius\Component\Core\Model\ProductInterface;
19
use Webmozart\Assert\Assert;
20
21
/**
22
 * @author Anna Walasek <[email protected]>
23
 */
24
class IndexPerTaxonPage extends CrudIndexPage implements IndexPerTaxonPageInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function hasProductsInOrder(array $productNames)
30
    {
31
        $productsOnPage = $this->getColumnFields('name');
32
33
        foreach ($productsOnPage as $key => $product) {
34
            if($productNames[$key] !== $product) {
35
                return false;
36
            }
37
        }
38
        
39
        return true;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function setPositionOfProduct($productName, $position)
46
    {
47
        /** @var NodeElement $productsRow */
48
        $productsRow = $this->getElement('table')->find('css', sprintf('tbody > tr:contains("%s")', $productName));
49
        Assert::notNull($productsRow, 'There are no row with given product\'s name!');
50
51
        $productsRow->find('css', '.sylius-product-taxon-position')->setValue($position);
52
    }
53
54
    public function savePositions()
55
    {
56
        $this->getElement('save_configuration_button')->press();
57
58
        $this->getDocument()->waitFor(5, function (){
59
            return false === $this->getElement('save_configuration_button')->hasClass('loading');
60
        } );
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected function getDefinedElements()
67
    {
68
        return array_merge(parent::getDefinedElements(), [
69
            'save_configuration_button' => '.sylius-save-position',
70
        ]);
71
    }
72
73
74
}
75