7
7
namespace Magento \Sales \Test \Block \Adminhtml \Order \Create ;
8
8
9
9
use Magento \Mtf \Block \Block ;
10
+ use Magento \Mtf \Client \Locator ;
10
11
11
12
/**
12
- * Class Totals
13
- * Adminhtml sales order create totals block
14
- *
13
+ * Adminhtml sales order create totals block.
15
14
*/
16
15
class Totals extends Block
17
16
{
18
17
/**
19
- * 'Submit Order' button
18
+ * 'Submit Order' button.
20
19
*
21
20
* @var string
22
21
*/
23
22
protected $ submitOrder = '.order-totals-actions button ' ;
24
23
25
24
/**
26
- * Order totals table
25
+ * Order totals table.
27
26
*
28
27
* @var string
29
28
*/
30
29
protected $ totalsTable = '.data-table ' ;
31
30
32
31
/**
33
- * Click 'Submit Order' button
32
+ * Total row label selector.
33
+ *
34
+ * @var string
35
+ */
36
+ protected $ totalLabelLocator = './/tr[normalize-space(td)="%s"] ' ;
37
+
38
+ /**
39
+ * Total value selector.
40
+ *
41
+ * @var string
42
+ */
43
+ protected $ totalValueLocator = './/td/span[contains(@class,"price")] ' ;
44
+
45
+ /**
46
+ * Click 'Submit Order' button.
34
47
*/
35
48
public function submitOrder ()
36
49
{
37
50
$ this ->_rootElement ->find ($ this ->submitOrder )->click ();
38
51
}
39
52
40
53
/**
41
- * Return totals by labels
54
+ * Return totals by labels.
42
55
*
43
56
* @param $totals string[]
44
57
* @return array
@@ -50,29 +63,40 @@ public function getTotals($totals)
50
63
}
51
64
52
65
$ totalsResult = [];
53
-
54
66
$ totalsTable = $ this ->_rootElement ->find ($ this ->totalsTable );
55
- $ rawTable = $ totalsTable ->getText ();
56
- $ existingTotals = explode (PHP_EOL , $ rawTable );
67
+
57
68
foreach ($ totals as $ total ) {
58
- foreach ( $ existingTotals as $ rowTotal ) {
59
- if ( strpos ( $ rowTotal , $ total ) !== false ) {
60
- $ totalValue = trim ( str_replace ( $ total , '' , $ rowTotal ));
61
- $ totalsResult [ $ total ] = $ this -> _escapeNumericValue ( $ totalValue );
62
- }
69
+
70
+ $ totalRow = $ totalsTable -> find ( sprintf ( $ this -> totalLabelLocator , $ total ), Locator:: SELECTOR_XPATH );
71
+ if ( $ totalRow -> isVisible ()) {
72
+ $ totalValue = $ totalRow -> find ( $ this -> totalValueLocator , Locator:: SELECTOR_XPATH );
73
+ $ totalsResult [ $ total ] = $ this -> escapeNumericValue ( $ totalValue -> getText ());
63
74
}
64
75
}
65
76
66
77
return $ totalsResult ;
67
78
}
68
79
69
80
/**
70
- * Escape numeric value
81
+ * Return total presence by label.
82
+ *
83
+ * @param string $total
84
+ * @return bool
85
+ */
86
+ public function isTotalPresent ($ total )
87
+ {
88
+ $ totalsTable = $ this ->_rootElement ->find ($ this ->totalsTable );
89
+ $ totalRow = $ totalsTable ->find (sprintf ($ this ->totalLabelLocator , $ total ), Locator::SELECTOR_XPATH );
90
+ return $ totalRow ->isVisible ();
91
+ }
92
+
93
+ /**
94
+ * Escape numeric value.
71
95
*
72
96
* @param string $value
73
97
* @return mixed
74
98
*/
75
- private function _escapeNumericValue ($ value )
99
+ private function escapeNumericValue ($ value )
76
100
{
77
101
return preg_replace ("/[^-0-9 \\.]/ " , "" , $ value );
78
102
}
0 commit comments