1010use Magento \Framework \ObjectManagerInterface ;
1111use Magento \Framework \Registry ;
1212use Magento \Framework \View \LayoutInterface ;
13+ use Magento \Sales \Api \Data \OrderAddressInterface ;
14+ use Magento \Sales \Api \Data \OrderInterface ;
1315use Magento \Sales \Api \Data \OrderInterfaceFactory ;
16+ use Magento \TestFramework \App \Config ;
1417use Magento \TestFramework \Helper \Bootstrap ;
1518use PHPUnit \Framework \TestCase ;
1619
@@ -46,6 +49,7 @@ protected function setUp(): void
4649 $ this ->block = $ this ->objectManager ->get (LayoutInterface::class)->createBlock (Form::class);
4750 $ this ->orderFactory = $ this ->objectManager ->get (OrderInterfaceFactory::class);
4851 $ this ->registry = $ this ->objectManager ->get (Registry::class);
52+ $ this ->objectManager ->removeSharedInstance (Config::class);
4953 }
5054
5155 /**
@@ -65,11 +69,86 @@ protected function tearDown(): void
6569 */
6670 public function testGetFormValues (): void
6771 {
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 );
7274 $ formValues = $ this ->block ->getFormValues ();
7375 $ this ->assertEquals ($ address ->getData (), $ formValues );
7476 }
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+ }
75154}
0 commit comments