1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Cart; |
4
|
|
|
|
5
|
|
|
use Magium\Actions\WaitForPageLoaded; |
6
|
|
|
use Magium\Magento\AbstractMagentoTestCase; |
7
|
|
|
use Magium\Magento\Navigators\BaseMenu; |
8
|
|
|
use Magium\Magento\Navigators\Catalog\Product; |
9
|
|
|
use Magium\Magento\Themes\AbstractThemeConfiguration; |
10
|
|
|
use Magium\WebDriver\WebDriver; |
11
|
|
|
|
12
|
|
|
class AddItemToCart |
13
|
|
|
{ |
14
|
|
|
const ACTION = 'Cart\AddItemToCart'; |
15
|
|
|
|
16
|
|
|
protected $webdriver; |
17
|
|
|
protected $theme; |
18
|
|
|
protected $navigator; |
19
|
|
|
protected $testCase; |
20
|
|
|
protected $loaded; |
21
|
|
|
protected $addSimpleProductToCart; |
22
|
|
|
protected $addConfigurableProductToCart; |
23
|
|
|
protected $productNavigator; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
WebDriver $webdriver, |
27
|
|
|
AbstractThemeConfiguration $theme, |
28
|
|
|
BaseMenu $navigator, |
29
|
|
|
AbstractMagentoTestCase $testCase, |
30
|
|
|
WaitForPageLoaded $loaded, |
31
|
|
|
AddSimpleProductToCart $addSimpleProductToCart, |
32
|
|
|
AddConfigurableProductToCart $addConfigurableProductToCart, |
33
|
|
|
Product $product |
34
|
|
|
) { |
35
|
|
|
$this->webdriver = $webdriver; |
36
|
|
|
$this->theme = $theme; |
37
|
|
|
$this->navigator = $navigator; |
38
|
|
|
$this->testCase = $testCase; |
39
|
|
|
$this->loaded = $loaded; |
40
|
|
|
$this->addSimpleProductToCart = $addSimpleProductToCart; |
41
|
|
|
$this->addConfigurableProductToCart = $addConfigurableProductToCart; |
42
|
|
|
$this->productNavigator = $product; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Adds an item to the cart from its product page by navigating to the default |
47
|
|
|
* test category and adding the default test product to the cart. |
48
|
|
|
* |
49
|
|
|
* @throws \Magium\NotFoundException |
50
|
|
|
*/ |
51
|
|
|
|
52
|
|
|
public function addSimpleProductToCartFromCategoryPage($categoryNavigationPath = null, $addToCartXpath = null) |
53
|
|
|
{ |
54
|
|
|
if ($categoryNavigationPath === null) { |
55
|
|
|
$categoryNavigationPath = $this->theme->getNavigationPathToSimpleProductCategory(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->navigator->navigateTo($categoryNavigationPath); |
59
|
|
|
|
60
|
|
|
if ($addToCartXpath !== null) { |
61
|
|
|
$this->webdriver->byXpath($addToCartXpath)->click(); |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->addSimpleProductToCart->execute(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Finds a product on a category page and attempts to add it to the cart after navigating to the product page |
70
|
|
|
* @todo |
71
|
|
|
* |
72
|
|
|
* @param string $categoryNavigationPath The category path to go to |
73
|
|
|
*/ |
74
|
|
|
|
75
|
|
|
public function addSimpleItemToCartFromProductPage($categoryNavigationPath = null, $productPageXpath = null) |
76
|
|
|
{ |
77
|
|
|
if ($categoryNavigationPath === null) { |
78
|
|
|
$categoryNavigationPath = $this->theme->getNavigationPathToSimpleProductCategory(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->navigator->navigateTo($categoryNavigationPath); |
82
|
|
|
|
83
|
|
|
if ($productPageXpath) { |
84
|
|
|
$element = $this->webdriver->byXpath($productPageXpath); |
85
|
|
|
$element->click(); |
86
|
|
|
$this->loaded->execute($element); |
87
|
|
|
} else { |
88
|
|
|
$this->productNavigator->navigateTo($this->theme->getDefaultSimpleProductName()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->addSimpleProductToCart->execute(); |
92
|
|
|
|
93
|
|
|
$this->testCase->assertElementExists($this->theme->getAddToCartSuccessXpath(), 'byXpath'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Adds as configurable product to the cart from the product page. |
98
|
|
|
* |
99
|
|
|
* @param string $categoryNavigationPath The name of the category to navigate to. e.g. Accessories/Jewelry |
100
|
|
|
*/ |
101
|
|
|
|
102
|
|
|
public function addConfigurableItemToCartFromProductPage($categoryNavigationPath = null) |
103
|
|
|
{ |
104
|
|
|
if ($categoryNavigationPath === null) { |
105
|
|
|
$categoryNavigationPath = $this->theme->getNavigationPathToConfigurableProductCategory(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->navigator->navigateTo($categoryNavigationPath); |
109
|
|
|
|
110
|
|
|
$this->productNavigator->navigateTo($this->theme->getDefaultConfigurableProductName()); |
111
|
|
|
|
112
|
|
|
$this->addConfigurableProductToCart->execute(); |
113
|
|
|
|
114
|
|
|
$this->testCase->assertElementExists($this->theme->getAddToCartSuccessXpath(), 'byXpath'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function execute() |
118
|
|
|
{ |
119
|
|
|
throw new \Exception('The execute() method is not used in this class. Please consider one of the other methods.'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |