|
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\Element\Product\ShowPage; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Mink\Element\NodeElement; |
|
17
|
|
|
use FriendsOfBehat\PageObjectExtension\Element\Element; |
|
18
|
|
|
|
|
19
|
|
|
final class VariantsElement extends Element implements VariantsElementInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public function countVariantsOnPage(): int |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var NodeElement $variants|array */ |
|
24
|
|
|
$variants = $this->getDocument()->findAll('css', '#variants .variant'); |
|
25
|
|
|
|
|
26
|
|
|
return \count($variants); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function hasProductVariantWithCodePriceAndCurrentStock(string $name, string $code, string $price, string $currentStock): bool |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var NodeElement $variantRow */ |
|
32
|
|
|
$variantRows = $this->getDocument()->findAll('css', '#variants .variant'); |
|
33
|
|
|
|
|
34
|
|
|
/** @var NodeElement $variant */ |
|
35
|
|
|
foreach ($variantRows as $variant) { |
|
36
|
|
|
if ( |
|
37
|
|
|
$this->hasProductWithGivenNameCodePriceAndCurrentStock($variant, $name, $code, $price, $currentStock) |
|
38
|
|
|
) { |
|
39
|
|
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function hasProductWithGivenNameCodePriceAndCurrentStock(NodeElement $variant, string $name, string $code, string $price, string $currentStock): bool |
|
47
|
|
|
{ |
|
48
|
|
|
if ( |
|
|
|
|
|
|
49
|
|
|
$variant->find('css', '.title span.variant-name')->getText() === $name && |
|
50
|
|
|
$variant->find('css', '.title span.variant-code')->getText() === $code && |
|
51
|
|
|
$variant->find('css', '.content .pricing tr:contains("WEB-US") td:nth-child(2)')->getText() === $price && |
|
52
|
|
|
$variant->find('css', '.content span.current-stock-label span.current-stock')->getText() === $currentStock |
|
53
|
|
|
) { |
|
54
|
|
|
return true; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|