Completed
Push — master ( 84981d...080a22 )
by Kamil
05:57
created

IndexPage::chooseChannelFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Page\Admin\Shipment;
15
16
use Behat\Mink\Element\NodeElement;
17
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;
18
19
class IndexPage extends BaseIndexPage implements IndexPageInterface
20
{
21
    public function chooseStateToFilter(string $shipmentState): void
22
    {
23
        $this->getElement('filter_state')->selectOption($shipmentState);
24
    }
25
26
    public function chooseChannelFilter(string $channelName): void
27
    {
28
        $this->getElement('filter_channel')->selectOption($channelName);
29
    }
30
31
    public function isShipmentWithOrderNumberInPosition(string $orderNumber, int $position): bool
32
    {
33
        $result = $this->getElement('shipment_in_given_position', [
34
                '%position%' => $position,
35
                '%orderNumber%' => $orderNumber,
36
            ]);
37
38
        return $result !== null;
39
    }
40
41
    public function shipShipmentOfOrderWithNumber(string $orderNumber): void
42
    {
43
        $this->getField($orderNumber, 'actions')->pressButton('Ship');
44
    }
45
46
    public function getShipmentStatusByOrderNumber(string $orderNumber): string
47
    {
48
        return $this->getField($orderNumber, 'state')->getText();
49
    }
50
51
    private function getField(string $orderNumber, string $fieldName): NodeElement
52
    {
53
        $tableAccessor = $this->getTableAccessor();
54
        $table = $this->getElement('table');
55
56
        $row = $tableAccessor->getRowWithFields($table, ['number' => $orderNumber]);
57
58
        return $tableAccessor->getFieldFromRow($table, $row, $fieldName);
59
    }
60
61
    public function showOrderPageForNthShipment(int $position): void
62
    {
63
        $this->getOrderLinkForRow($position)->clickLink('#');
64
    }
65
66
    protected function getDefinedElements(): array
67
    {
68
        return array_merge(parent::getDefinedElements(), [
69
            'filter_channel' => '#criteria_channel',
70
            'filter_state' => '#criteria_state',
71
            'shipment_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%orderNumber%")',
72
        ]);
73
    }
74
75
    private function getOrderLinkForRow(int $shipmentNumber): NodeElement
76
    {
77
        $tableAccessor = $this->getTableAccessor();
78
        $table = $this->getElement('table');
79
80
        $row = $tableAccessor->getRowsWithFields($table, [])[$shipmentNumber];
81
82
        return $row->find('css', 'td:nth-child(2)');
83
    }
84
}
85