Completed
Push — master ( a9aa0c...602f1d )
by Kamil
26:22 queued 09:35
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\Payment;
15
16
use Behat\Mink\Element\NodeElement;
17
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;
18
19
final class IndexPage extends BaseIndexPage implements IndexPageInterface
20
{
21
    public function completePaymentOfOrderWithNumber(string $orderNumber): void
22
    {
23
        $this->getField($orderNumber, 'actions')->pressButton('Complete');
24
    }
25
26
    public function chooseStateToFilter(string $paymentState): void
27
    {
28
        $this->getElement('filter_state')->selectOption($paymentState);
29
    }
30
31
    public function getPaymentStateByOrderNumber(string $orderNumber): string
32
    {
33
        return $this->getField($orderNumber, 'state')->getText();
34
    }
35
36
    public function isPaymentWithOrderNumberInPosition(string $orderNumber, int $position): bool
37
    {
38
        $result = $this->getElement('payment_in_given_position', [
39
            '%position%' => $position,
40
            '%orderNumber%' => $orderNumber,
41
        ]);
42
43
        return $result !== null;
44
    }
45
46
    public function showOrderPageForNthPayment(int $position): void
47
    {
48
        $this->getOrderLinkForRow($position)->clickLink('#');
49
    }
50
51
    public function chooseChannelFilter(string $channelName): void
52
    {
53
        $this->getElement('filter_channel')->selectOption($channelName);
54
    }
55
56
    protected function getDefinedElements(): array
57
    {
58
        return array_merge(parent::getDefinedElements(), [
59
            'filter_channel' => '#criteria_channel',
60
            'filter_state' => '#criteria_state',
61
            'payment_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%orderNumber%")',
62
        ]);
63
    }
64
65
    private function getOrderLinkForRow(int $paymentNumber): NodeElement
66
    {
67
        $tableAccessor = $this->getTableAccessor();
68
        $table = $this->getElement('table');
69
70
        $row = $tableAccessor->getRowsWithFields($table, [])[$paymentNumber];
71
72
        return $row->find('css', 'td:nth-child(2)');
73
    }
74
75
    private function getField(string $orderNumber, string $fieldName): NodeElement
76
    {
77
        $tableAccessor = $this->getTableAccessor();
78
        $table = $this->getElement('table');
79
80
        $row = $tableAccessor->getRowWithFields($table, ['number' => $orderNumber]);
81
82
        return $tableAccessor->getFieldFromRow($table, $row, $fieldName);
83
    }
84
}
85