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

IndexPage::isPaymentWithOrderNumberInPosition()   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\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
    protected function getDefinedElements(): array
52
    {
53
        return array_merge(parent::getDefinedElements(), [
54
            'filter_state' => '#criteria_state',
55
            'payment_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%orderNumber%")',
56
        ]);
57
    }
58
59
    private function getOrderLinkForRow(int $paymentNumber): NodeElement
60
    {
61
        $tableAccessor = $this->getTableAccessor();
62
        $table = $this->getElement('table');
63
64
        $row = $tableAccessor->getRowsWithFields($table, [])[$paymentNumber];
65
66
        return $row->find('css', 'td:nth-child(2)');
67
    }
68
69
    private function getField(string $orderNumber, string $fieldName): NodeElement
70
    {
71
        $tableAccessor = $this->getTableAccessor();
72
        $table = $this->getElement('table');
73
74
        $row = $tableAccessor->getRowWithFields($table, ['number' => $orderNumber]);
75
76
        return $tableAccessor->getFieldFromRow($table, $row, $fieldName);
77
    }
78
}
79