Completed
Push — master ( 4f34c8...2960e8 )
by Kamil
23:03 queued 15:59
created

IndexPage::isShipmentWithOrderNumberInPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 isShipmentWithOrderNumberInPosition(string $orderNumber, int $position): bool
27
    {
28
        $result = $this->getElement('shipment_in_given_position', [
29
                '%position%' => $position,
30
                '%orderNumber%' => $orderNumber,
31
            ]);
32
33
        return $result !== null;
34
    }
35
36
    public function shipShipmentOfOrderWithNumber(string $orderNumber): void
37
    {
38
        $this->getField($orderNumber, 'actions')->pressButton('Ship');
39
    }
40
41
    public function getShipmentStatusByOrderNumber(string $orderNumber): string
42
    {
43
        return $this->getField($orderNumber, 'state')->getText();
44
    }
45
46
    private function getField(string $orderNumber, string $fieldName): NodeElement
47
    {
48
        $tableAccessor = $this->getTableAccessor();
49
        $table = $this->getElement('table');
50
51
        $row = $tableAccessor->getRowWithFields($table, ['number' => $orderNumber]);
52
53
        return $tableAccessor->getFieldFromRow($table, $row, $fieldName);
54
    }
55
56
    public function showOrderPageForNthShipment(int $position): void
57
    {
58
        $this->getOrderLinkForRow($position)->clickLink('#');
59
    }
60
61
    protected function getDefinedElements(): array
62
    {
63
        return array_merge(parent::getDefinedElements(), [
64
            'filter_state' => '#criteria_state',
65
            'shipment_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%orderNumber%")',
66
        ]);
67
    }
68
69
    private function getOrderLinkForRow(int $shipmentNumber): NodeElement
70
    {
71
        $tableAccessor = $this->getTableAccessor();
72
        $table = $this->getElement('table');
73
74
        $row = $tableAccessor->getRowsWithFields($table, [])[$shipmentNumber];
75
76
        return $row->find('css', 'td:nth-child(2)');
77
    }
78
}
79