10
10
use Magento \Framework \ObjectManagerInterface ;
11
11
use Magento \Framework \Registry ;
12
12
use Magento \Framework \View \LayoutInterface ;
13
+ use Magento \Sales \Api \Data \OrderAddressInterface ;
14
+ use Magento \Sales \Api \Data \OrderInterface ;
13
15
use Magento \Sales \Api \Data \OrderInterfaceFactory ;
16
+ use Magento \TestFramework \App \Config ;
14
17
use Magento \TestFramework \Helper \Bootstrap ;
15
18
use PHPUnit \Framework \TestCase ;
16
19
@@ -46,6 +49,7 @@ protected function setUp(): void
46
49
$ this ->block = $ this ->objectManager ->get (LayoutInterface::class)->createBlock (Form::class);
47
50
$ this ->orderFactory = $ this ->objectManager ->get (OrderInterfaceFactory::class);
48
51
$ this ->registry = $ this ->objectManager ->get (Registry::class);
52
+ $ this ->objectManager ->removeSharedInstance (Config::class);
49
53
}
50
54
51
55
/**
@@ -65,11 +69,86 @@ protected function tearDown(): void
65
69
*/
66
70
public function testGetFormValues (): void
67
71
{
68
- $ this ->registry ->unregister ('order_address ' );
69
- $ order = $ this ->orderFactory ->create ()->loadByIncrementId (100000001 );
70
- $ address = $ order ->getShippingAddress ();
71
- $ this ->registry ->register ('order_address ' , $ address );
72
+ $ address = $ this ->getOrderAddress ('100000001 ' );
73
+ $ this ->prepareFormBlock ($ address );
72
74
$ formValues = $ this ->block ->getFormValues ();
73
75
$ this ->assertEquals ($ address ->getData (), $ formValues );
74
76
}
77
+
78
+ /**
79
+ * @magentoDbIsolation disabled
80
+ * @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
81
+ * @magentoDataFixture Magento/Sales/_files/order_with_customer.php
82
+ * @magentoConfigFixture default_store general/country/default US
83
+ * @magentoConfigFixture default_store general/country/allow US
84
+ * @magentoConfigFixture fixture_second_store_store general/country/default UY
85
+ * @magentoConfigFixture fixture_second_store_store general/country/allow UY
86
+ * @return void
87
+ */
88
+ public function testCountryIdInAllowedList (): void
89
+ {
90
+ $ address = $ this ->getOrderAddress ('100000001 ' );
91
+ $ this ->prepareFormBlock ($ address );
92
+ $ this ->assertEquals ('US ' , $ address ->getCountryId ());
93
+ $ this ->assertCountryField ('US ' );
94
+ }
95
+
96
+ /**
97
+ * @magentoDbIsolation disabled
98
+ * @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
99
+ * @magentoDataFixture Magento/Sales/_files/order_with_customer.php
100
+ * @magentoConfigFixture default_store general/country/default CA
101
+ * @magentoConfigFixture default_store general/country/allow CA
102
+ * @magentoConfigFixture fixture_second_store_store general/country/default UY
103
+ * @magentoConfigFixture fixture_second_store_store general/country/allow UY
104
+ * @return void
105
+ */
106
+ public function testCountryIdInNotAllowedList (): void
107
+ {
108
+ $ address = $ this ->getOrderAddress ('100000001 ' );
109
+ $ this ->prepareFormBlock ($ address );
110
+ $ this ->assertCountryField ('CA ' );
111
+ }
112
+
113
+ /**
114
+ * Prepares address edit from block.
115
+ *
116
+ * @param OrderAddressInterface $address
117
+ * @return void
118
+ */
119
+ private function prepareFormBlock (OrderAddressInterface $ address ): void
120
+ {
121
+ $ this ->registry ->unregister ('order_address ' );
122
+ $ this ->registry ->register ('order_address ' , $ address );
123
+ }
124
+
125
+ /**
126
+ * Return order billing address.
127
+ *
128
+ * @param string $orderIncrementId
129
+ * @return OrderAddressInterface
130
+ */
131
+ private function getOrderAddress (string $ orderIncrementId ): OrderAddressInterface
132
+ {
133
+ /** @var OrderInterface $order */
134
+ $ order = $ this ->orderFactory ->create ()->loadByIncrementId ($ orderIncrementId );
135
+
136
+ return $ order ->getBillingAddress ();
137
+ }
138
+
139
+ /**
140
+ * Asserts country field data.
141
+ *
142
+ * @param string $countryCode
143
+ * @return void
144
+ */
145
+ private function assertCountryField (string $ countryCode ): void
146
+ {
147
+ $ countryIdField = $ this ->block ->getForm ()->getElement ('country_id ' );
148
+ $ this ->assertEquals ($ countryCode , $ countryIdField ->getValue ());
149
+ $ options = $ countryIdField ->getValues ();
150
+ $ this ->assertCount (1 , $ options );
151
+ $ firstOption = reset ($ options );
152
+ $ this ->assertEquals ($ countryCode , $ firstOption ['value ' ]);
153
+ }
75
154
}
0 commit comments