6
6
7
7
namespace Magento \Customer \Test \Constraint ;
8
8
9
+ use Magento \Customer \Test \Block \Address \Renderer ;
9
10
use Magento \Customer \Test \Fixture \Address ;
10
- use Magento \Customer \Test \Page \CustomerAccountIndex ;
11
11
use Magento \Customer \Test \Page \CustomerAccountAddress ;
12
+ use Magento \Customer \Test \Page \CustomerAccountIndex ;
12
13
use Magento \Mtf \Constraint \AbstractConstraint ;
13
14
14
15
/**
@@ -20,25 +21,32 @@ class AssertCustomerDefaultAddressFrontendAddressBook extends AbstractConstraint
20
21
* Asserts that Default Billing Address and Default Shipping Address equal to data from fixture.
21
22
*
22
23
* @param CustomerAccountIndex $customerAccountIndex
23
- * @param CustomerAccountAddress $customerAccountAddress
24
- * @param Address $address
24
+ * @param CustomerAccountAddress $customerAddress
25
+ * @param Address|null $shippingAddress
26
+ * @param Address|null $billingAddress
25
27
* @return void
26
28
*/
27
29
public function processAssert (
28
30
CustomerAccountIndex $ customerAccountIndex ,
29
- CustomerAccountAddress $ customerAccountAddress ,
30
- Address $ address
31
+ CustomerAccountAddress $ customerAddress ,
32
+ Address $ shippingAddress ,
33
+ Address $ billingAddress = null
31
34
) {
35
+ $ customerAccountIndex ->open ();
32
36
$ customerAccountIndex ->getAccountMenuBlock ()->openMenuItem ('Address Book ' );
33
- $ addressRenderer = $ this ->objectManager ->create (
34
- \Magento \Customer \Test \Block \Address \Renderer::class,
35
- ['address ' => $ address , 'type ' => 'html ' ]
36
- );
37
- $ addressToVerify = $ addressRenderer ->render ();
37
+
38
+ $ shippingAddressRendered = $ this ->createAddressRenderer ($ shippingAddress )->render ();
39
+ $ validated =
40
+ $ shippingAddressRendered == $ customerAddress ->getDefaultAddressBlock ()->getDefaultShippingAddress ();
41
+
42
+ if (null !== $ billingAddress ) {
43
+ $ billingAddressRendered = $ customerAddress ->getDefaultAddressBlock ()->getDefaultBillingAddress ();
44
+ $ validated =
45
+ $ validated && ($ billingAddressRendered == $ this ->createAddressRenderer ($ billingAddress )->render ());
46
+ }
38
47
39
48
\PHPUnit_Framework_Assert::assertTrue (
40
- $ addressToVerify == $ customerAccountAddress ->getDefaultAddressBlock ()->getDefaultBillingAddress ()
41
- && $ addressToVerify == $ customerAccountAddress ->getDefaultAddressBlock ()->getDefaultShippingAddress (),
49
+ $ validated ,
42
50
'Customer default address on address book tab is not matching the fixture. '
43
51
);
44
52
}
@@ -52,4 +60,18 @@ public function toString()
52
60
{
53
61
return 'Default billing and shipping address form is correct. ' ;
54
62
}
63
+
64
+ /**
65
+ * Instantiate Renderer object.
66
+ *
67
+ * @param Address $address
68
+ * @return Renderer
69
+ */
70
+ private function createAddressRenderer (Address $ address )
71
+ {
72
+ return $ this ->objectManager ->create (
73
+ Renderer::class,
74
+ ['address ' => $ address , 'type ' => 'html ' ]
75
+ );
76
+ }
55
77
}
0 commit comments