77/**
88 * Tests for customer addresses collection
99 */
10- namespace Magento \Customer \ Model \ ResourceModel \Address ;
10+ namespace Magento \Sales \ ViewModel \ Customer \Address ;
1111
12+ use Magento \Customer \Model \ResourceModel \Address \Collection ;
1213use Magento \Customer \Api \CustomerRepositoryInterface ;
1314use Magento \Framework \App \Config \ConfigResource \ConfigInterface ;
1415use Magento \Framework \App \Config \ReinitableConfigInterface ;
1516use Magento \Framework \App \Config \ScopeConfigInterface ;
1617use Magento \Framework \App \Config \Storage \Writer ;
1718use Magento \Framework \App \Config \Storage \WriterInterface ;
19+ use Magento \Framework \Exception \LocalizedException ;
20+ use Magento \Framework \Exception \NoSuchEntityException ;
21+ use Magento \Framework \Registry ;
1822use Magento \TestFramework \Helper \Bootstrap ;
1923use Magento \TestFramework \ObjectManager ;
2024use PHPUnit \Framework \TestCase ;
2327 * Assert that only relevant addresses for the allowed countries under a website/store fetch.
2428 *
2529 * @magentoDbIsolation enabled
30+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2631 */
27- class StoreAddressCollectionTest extends TestCase
32+ class AddressAttributeFilterTest extends TestCase
2833{
2934 /**
3035 * @var ObjectManager
@@ -37,24 +42,30 @@ class StoreAddressCollectionTest extends TestCase
3742 protected $ customerRepository ;
3843
3944 /**
40- * @var StoreAddressCollection
45+ * @var AddressAttributeFilter
4146 */
42- private $ storeAddressCollection ;
47+ private $ scopeFilter ;
48+
49+ /**
50+ * @var Collection
51+ */
52+ private $ collection ;
4353
4454 protected function setUp (): void
4555 {
4656 $ this ->objectManager = Bootstrap::getObjectManager ();
4757 $ this ->customerRepository = $ this ->objectManager ->get (CustomerRepositoryInterface::class);
48- $ this ->storeAddressCollection = $ this ->objectManager ->create (StoreAddressCollection::class);
58+ $ this ->collection = $ this ->objectManager ->get (Collection::class);
59+ $ this ->scopeFilter = $ this ->objectManager ->create (AddressAttributeFilter::class);
4960 }
5061
5162 /**
5263 * Ensure that config changes are deleted or restored.
5364 */
5465 protected function tearDown (): void
5566 {
56- /** @var \Magento\Framework\ Registry $registry */
57- $ registry = $ this ->objectManager ->get (\ Magento \ Framework \ Registry::class);
67+ /** @var Registry $registry */
68+ $ registry = $ this ->objectManager ->get (Registry::class);
5869 $ registry ->unregister ('isSecureArea ' );
5970 $ registry ->register ('isSecureArea ' , true );
6071
@@ -83,13 +94,14 @@ protected function tearDown(): void
8394 *
8495 * @dataProvider addressesDataProvider
8596 *
97+ * @param Collection $collection
8698 * @param $customerId
8799 * @param $allowedCountries
88100 * @return void
89- * @throws \Magento\Framework\Exception\ LocalizedException
90- * @throws \Magento\Framework\Exception\ NoSuchEntityException
101+ * @throws LocalizedException
102+ * @throws NoSuchEntityException
91103 */
92- public function testSetCustomerFilter ( $ customerId , $ allowedCountries ) : void
104+ public function testSetScopeFilter ( $ storeId , $ allowedCountries ) : void
93105 {
94106 /** @var ConfigInterface $config */
95107 $ config = $ this ->objectManager ->get (ConfigInterface::class);
@@ -102,8 +114,7 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void
102114 $ scopeConfig = $ this ->objectManager ->get (ScopeConfigInterface::class);
103115 $ scopeConfig ->clean ();
104116
105- $ customer = $ this ->customerRepository ->getById ($ customerId );
106- $ addresses = $ this ->storeAddressCollection ->setCustomerFilter ($ customer );
117+ $ addresses = $ this ->scopeFilter ->setScopeFilter ($ this ->collection , $ storeId );
107118 $ this ->assertIsArray ($ addresses ->getData ());
108119
109120 foreach ($ addresses ->getData () as $ address ) {
@@ -112,17 +123,16 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void
112123 }
113124
114125 /**
115- * Data provider for create allowed or not allowed countries .
126+ * Data provider for create allowed countries for a particular store .
116127 *
128+ * @param Collection $collection
117129 * @return array
118130 */
119131 public function addressesDataProvider (): array
120132 {
121133 return [
122134 'address_in_single_allowed_country ' => [1 , ['US ' ]],
123- 'address_not_in_single_allowed_country ' => [1 , ['FR ' ]],
124135 'address_in_multiple_allowed_countries ' => [1 , ['US ' , 'IN ' ]],
125- 'address_not_in_multiple_allowed_countries ' => [1 , ['FR ' , 'DE ' ]],
126136 ];
127137 }
128138}
0 commit comments