1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Extractors\Checkout; |
4
|
|
|
|
5
|
|
|
use Magium\AbstractTestCase; |
6
|
|
|
use Magium\Extractors\AbstractExtractor; |
7
|
|
|
use Magium\Magento\Actions\Checkout\Steps\StepInterface; |
8
|
|
|
use Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration; |
9
|
|
|
use Magium\WebDriver\ExpectedCondition; |
10
|
|
|
use Magium\WebDriver\WebDriver; |
11
|
|
|
|
12
|
|
|
class CartSummary extends AbstractExtractor implements StepInterface |
13
|
|
|
{ |
14
|
|
|
const EXTRACTOR = 'Checkout\CartSummary'; |
15
|
|
|
/** |
16
|
|
|
* Redefined here has a code completion helper |
17
|
|
|
* |
18
|
|
|
* @var \Magium\Magento\Themes\OnePageCheckout\AbstractThemeConfiguration |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
protected $theme; |
22
|
|
|
|
23
|
|
|
const VALUE_PRODUCTS = 'products'; |
24
|
|
|
const VALUE_SUBTOTAL = 'subtotal'; |
25
|
|
|
const VALUE_SnH = 'ship-handle'; |
26
|
|
|
const VALUE_TAX = 'tax'; |
27
|
|
|
const VALUE_GRAND_TOTAL = 'grand-total'; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
WebDriver $webDriver, |
31
|
|
|
AbstractTestCase $testCase, |
32
|
|
|
AbstractThemeConfiguration $theme |
33
|
|
|
) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($webDriver, $testCase, $theme); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return ProductIterator |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
public function getProducts() |
43
|
|
|
{ |
44
|
|
|
return $this->getValue(self::VALUE_PRODUCTS); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getSubTotal() |
48
|
|
|
{ |
49
|
|
|
return $this->getValue(self::VALUE_SUBTOTAL); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getShippingAndHandling() |
53
|
|
|
{ |
54
|
|
|
return $this->getValue(self::VALUE_SnH); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getTax() |
58
|
|
|
{ |
59
|
|
|
return $this->getValue(self::VALUE_TAX); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getGrandTotal() |
63
|
|
|
{ |
64
|
|
|
return $this->getValue(self::VALUE_GRAND_TOTAL); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function extract() |
68
|
|
|
{ |
69
|
|
|
$productIterator = new ProductIterator(); |
70
|
|
|
$this->values[self::VALUE_PRODUCTS] = $productIterator; |
71
|
|
|
$count = 1; |
72
|
|
|
|
73
|
|
|
$testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count); |
74
|
|
|
$this->webDriver->wait()->until(ExpectedCondition::elementExists($testProductXpath, WebDriver::BY_XPATH)); |
|
|
|
|
75
|
|
|
|
76
|
|
|
while ($this->webDriver->elementExists($testProductXpath, WebDriver::BY_XPATH)) { |
77
|
|
|
|
78
|
|
|
$xpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath($count); |
79
|
|
|
$nameElement = $this->webDriver->byXpath($xpath); |
80
|
|
|
$name = trim($nameElement->getText()); |
81
|
|
|
|
82
|
|
|
$xpath = $this->theme->getCartSummaryCheckoutProductLoopPriceXpath($count); |
83
|
|
View Code Duplication |
if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
|
|
|
84
|
|
|
$priceElement = $this->webDriver->byXpath($xpath); |
85
|
|
|
$price = trim($priceElement->getText()); // We do not extract the number value so currency checks can be done |
86
|
|
|
} else { |
87
|
|
|
$price = 0; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$xpath = $this->theme->getCartSummaryCheckoutProductLoopQtyXpath($count); |
91
|
|
View Code Duplication |
if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
|
|
|
92
|
|
|
$qtyElement = $this->webDriver->byXpath($xpath); |
93
|
|
|
$qty = trim($qtyElement->getText()); |
94
|
|
|
} else { |
95
|
|
|
$qty = 0; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$xpath = $this->theme->getCartSummaryCheckoutProductLoopSubtotalXpath($count); |
99
|
|
View Code Duplication |
if ($this->webDriver->elementExists($xpath, WebDriver::BY_XPATH)) { |
|
|
|
|
100
|
|
|
$subtotalElement = $this->webDriver->byXpath($xpath); |
101
|
|
|
$subtotal = trim($subtotalElement->getText()); |
102
|
|
|
} else { |
103
|
|
|
$subtotal = 0; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$product = new Product($name, $qty, $price, $subtotal); |
107
|
|
|
$productIterator->addProduct($product); |
108
|
|
|
$testProductXpath = $this->theme->getCartSummaryCheckoutProductLoopNameXpath(++$count); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// Tax and shipping may not be displayed |
112
|
|
|
|
113
|
|
View Code Duplication |
if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutTax(), WebDriver::BY_XPATH)) { |
|
|
|
|
114
|
|
|
$this->values[self::VALUE_TAX] |
115
|
|
|
= trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutTax())->getText()); |
116
|
|
|
} |
117
|
|
View Code Duplication |
if ($this->webDriver->elementDisplayed($this->theme->getCartSummaryCheckoutShippingTotal(), WebDriver::BY_XPATH)) { |
|
|
|
|
118
|
|
|
$this->values[self::VALUE_SnH] |
119
|
|
|
= trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutShippingTotal())->getText()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
$this->values[self::VALUE_GRAND_TOTAL] |
125
|
|
|
= trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutGrandTotal())->getText()); |
126
|
|
|
$this->values[self::VALUE_SUBTOTAL] |
127
|
|
|
= trim($this->webDriver->byXpath($this->theme->getCartSummaryCheckoutSubTotal())->getText()); |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function execute() |
132
|
|
|
{ |
133
|
|
|
$this->extract(); |
134
|
|
|
return true; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function nextAction() |
138
|
|
|
{ |
139
|
|
|
return true; |
140
|
|
|
} |
141
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: