-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathShowPage.php
More file actions
195 lines (166 loc) · 6.2 KB
/
ShowPage.php
File metadata and controls
195 lines (166 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
declare(strict_types=1);
namespace Tests\Sylius\InvoicingPlugin\Behat\Page\Admin\Invoice;
use Behat\Mink\Session;
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Sylius\Behat\Service\Accessor\TableAccessorInterface;
use Symfony\Component\Routing\RouterInterface;
final class ShowPage extends SymfonyPage implements ShowPageInterface
{
private TableAccessorInterface $tableAccessor;
public function __construct(
Session $session,
$parameters,
RouterInterface $router,
TableAccessorInterface $tableAccessor
) {
parent::__construct($session, $parameters, $router);
$this->tableAccessor = $tableAccessor;
}
public function getIssuedAtDate(): \DateTimeInterface
{
// Jun 19, 2018, 2:17:29 PM
return \DateTimeImmutable::createFromFormat('M j, Y, g:i:s A', $this->getElement('issued_at')->getText());
}
public function getRouteName(): string
{
return 'sylius_invoicing_admin_invoice_show';
}
public function hasBillingData(
string $customerName,
string $street,
string $postcode,
string $city,
string $countryName
): bool {
$billingDataText = $this->getElement('billing_address')->getText();
return
(stripos($billingDataText, $customerName) !== false) &&
(stripos($billingDataText, $street) !== false) &&
(stripos($billingDataText, $city) !== false) &&
(stripos($billingDataText, $countryName . ' ' . $postcode) !== false)
;
}
public function hasShopBillingData(
string $company,
string $taxId,
string $countryName,
string $street,
string $city,
string $postcode
): bool {
$billingDataText = $this->getElement('shop_billing_data')->getText();
return
(stripos($billingDataText, $company) !== false) &&
(stripos($billingDataText, $taxId) !== false) &&
(stripos($billingDataText, $city) !== false) &&
(stripos($billingDataText, $street) !== false) &&
(stripos($billingDataText, $countryName . ' ' . $postcode) !== false)
;
}
public function countItems(): int
{
return $this->tableAccessor->countTableBodyRows($this->getElement('table'));
}
public function hasItemWithData(
string $name,
string $unitNetPrice,
string $discountedUnitNetPrice,
int $quantity,
string $taxTotal,
string $total,
string $currencyCode = null,
string $netValue = null
): bool {
$row = $this->tableAccessor->getRowsWithFields($this->getElement('table'), [
'name' => $name,
'unit-net-price' => $unitNetPrice,
'discounted-unit-net-price' => $discountedUnitNetPrice,
'quantity' => $quantity,
'tax_total' => $taxTotal,
'total' => $total,
])[0];
return null !== $row;
}
public function hasTaxItem(string $label, string $amount, string $currencyCode): bool
{
foreach ($this->getDocument()->findAll('css', '[data-test-invoice-tax-item]') as $item) {
if (
$item->find('css', '[data-test-invoice-tax-item-label]')->getText() === $label &&
$item->find('css', '[data-test-invoice-tax-item-amount]')->getText() === $amount &&
$item->find('css', '[data-test-invoice-tax-item-currency-code]')->getText() === $currencyCode
) {
return true;
}
}
return false;
}
public function hasNetTotal(string $netTotal, string $currencyCode): bool
{
return
$this->getElement('invoice_net_total')->getText() === $netTotal &&
$this->getElement('invoice_net_total_currency_code')->getText() === $currencyCode
;
}
public function hasTaxTotal(string $taxTotal, string $currencyCode): bool
{
return
$this->getElement('invoice_taxes_total')->getText() === $taxTotal &&
$this->getElement('invoice_taxes_total_currency_code')->getText() === $currencyCode
;
}
public function hasTotal(string $total, string $currencyCode): bool
{
return
$this->getElement('invoice_total')->getText() === $total &&
$this->getElement('invoice_total_currency_code')->getText() === $currencyCode
;
}
public function getChannel(): string
{
return $this->getElement('channel')->getText();
}
public function download(): void
{
$this->getElement('download_button')->click();
}
public function resend(): void
{
$this->getDocument()->clickLink('Resend');
}
public function goBack(): void
{
$this->getElement('back')->click();
}
public function isPaid(): bool
{
return str_contains($this->getElement('paid')->getHtml(), 'Yes');
}
public function hasDownloadButton(): bool
{
return $this->hasElement('download_button');
}
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'back' => '[data-test-back]',
'billing_address' => '[data-test-billing-data]',
'channel' => '[data-test-channel]',
'invoice_net_total' => '[data-test-invoice-net-total]',
'invoice_net_total_currency_code' => '[data-test-invoice-net-total-currency-code]',
'invoice_taxes_total' => '[data-test-invoice-taxes-total]',
'invoice_taxes_total_currency_code' => '[data-test-invoice-taxes-total-currency-code]',
'invoice_total' => '[data-test-invoice-total]',
'invoice_total_currency_code' => '[data-test-invoice-total-currency-code]',
'issued_at' => '[data-test-issued-at]',
'paid' => '[data-test-invoice-is-paid]',
'shop_billing_data' => '[data-test-shop-billing-data]',
'table' => '[data-test-invoice-items]',
'download_button' => '[data-test-download-button]',
]);
}
private function getTableElements(): array
{
return $this->getDocument()->findAll('css', '[data-test-line-item]');
}
}