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
|
|
|
namespace Sylius\Behat\Page\Product; |
13
|
|
|
|
14
|
|
|
use Sylius\Behat\SymfonyPageObjectExtension\PageObject\SymfonyPage; |
15
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class ProductShowPage extends SymfonyPage |
21
|
|
|
{ |
22
|
|
|
public function addToCart() |
23
|
|
|
{ |
24
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $quantity |
29
|
|
|
*/ |
30
|
|
|
public function addToCartWithQuantity($quantity) |
31
|
|
|
{ |
32
|
|
|
$this->getDocument()->fillField('Quantity', $quantity); |
33
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $variant |
38
|
|
|
*/ |
39
|
|
|
public function addToCartWithVariant($variant) |
40
|
|
|
{ |
41
|
|
|
$item = $this->getDocument()->find('css', sprintf('#product-variants tbody tr:contains("%s")', $variant)); |
42
|
|
|
$radio = $item->find('css', 'input'); |
43
|
|
|
|
44
|
|
|
$this->getDocument()->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); |
45
|
|
|
|
46
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function getRouteName() |
53
|
|
|
{ |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
protected function getUrl(array $urlParameters = []) |
60
|
|
|
{ |
61
|
|
|
if (!isset($urlParameters['product']) || !$urlParameters['product'] instanceof ProductInterface) { |
62
|
|
|
throw new \InvalidArgumentException( |
63
|
|
|
'There should be only one url parameter passed to ProductShowPage '. |
64
|
|
|
'named "product", containing an instance of Core\'s ProductInterface' |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->router->generate($urlParameters['product'], [], true); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|