7
7
/**
8
8
* Tests for customer addresses collection
9
9
*/
10
- namespace Magento \Customer \ Model \ ResourceModel \Address ;
10
+ namespace Magento \Sales \ ViewModel \ Customer \Address ;
11
11
12
+ use Magento \Customer \Model \ResourceModel \Address \Collection ;
12
13
use Magento \Customer \Api \CustomerRepositoryInterface ;
13
14
use Magento \Framework \App \Config \ConfigResource \ConfigInterface ;
14
15
use Magento \Framework \App \Config \ReinitableConfigInterface ;
15
16
use Magento \Framework \App \Config \ScopeConfigInterface ;
16
17
use Magento \Framework \App \Config \Storage \Writer ;
17
18
use Magento \Framework \App \Config \Storage \WriterInterface ;
19
+ use Magento \Framework \Exception \LocalizedException ;
20
+ use Magento \Framework \Exception \NoSuchEntityException ;
21
+ use Magento \Framework \Registry ;
18
22
use Magento \TestFramework \Helper \Bootstrap ;
19
23
use Magento \TestFramework \ObjectManager ;
20
24
use PHPUnit \Framework \TestCase ;
23
27
* Assert that only relevant addresses for the allowed countries under a website/store fetch.
24
28
*
25
29
* @magentoDbIsolation enabled
30
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
31
*/
27
- class StoreAddressCollectionTest extends TestCase
32
+ class AddressAttributeFilterTest extends TestCase
28
33
{
29
34
/**
30
35
* @var ObjectManager
@@ -37,24 +42,30 @@ class StoreAddressCollectionTest extends TestCase
37
42
protected $ customerRepository ;
38
43
39
44
/**
40
- * @var StoreAddressCollection
45
+ * @var AddressAttributeFilter
41
46
*/
42
- private $ storeAddressCollection ;
47
+ private $ scopeFilter ;
48
+
49
+ /**
50
+ * @var Collection
51
+ */
52
+ private $ collection ;
43
53
44
54
protected function setUp (): void
45
55
{
46
56
$ this ->objectManager = Bootstrap::getObjectManager ();
47
57
$ 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);
49
60
}
50
61
51
62
/**
52
63
* Ensure that config changes are deleted or restored.
53
64
*/
54
65
protected function tearDown (): void
55
66
{
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);
58
69
$ registry ->unregister ('isSecureArea ' );
59
70
$ registry ->register ('isSecureArea ' , true );
60
71
@@ -83,13 +94,14 @@ protected function tearDown(): void
83
94
*
84
95
* @dataProvider addressesDataProvider
85
96
*
97
+ * @param Collection $collection
86
98
* @param $customerId
87
99
* @param $allowedCountries
88
100
* @return void
89
- * @throws \Magento\Framework\Exception\ LocalizedException
90
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
101
+ * @throws LocalizedException
102
+ * @throws NoSuchEntityException
91
103
*/
92
- public function testSetCustomerFilter ( $ customerId , $ allowedCountries ) : void
104
+ public function testSetScopeFilter ( $ storeId , $ allowedCountries ) : void
93
105
{
94
106
/** @var ConfigInterface $config */
95
107
$ config = $ this ->objectManager ->get (ConfigInterface::class);
@@ -102,8 +114,7 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void
102
114
$ scopeConfig = $ this ->objectManager ->get (ScopeConfigInterface::class);
103
115
$ scopeConfig ->clean ();
104
116
105
- $ customer = $ this ->customerRepository ->getById ($ customerId );
106
- $ addresses = $ this ->storeAddressCollection ->setCustomerFilter ($ customer );
117
+ $ addresses = $ this ->scopeFilter ->setScopeFilter ($ this ->collection , $ storeId );
107
118
$ this ->assertIsArray ($ addresses ->getData ());
108
119
109
120
foreach ($ addresses ->getData () as $ address ) {
@@ -112,17 +123,16 @@ public function testSetCustomerFilter($customerId, $allowedCountries) : void
112
123
}
113
124
114
125
/**
115
- * Data provider for create allowed or not allowed countries .
126
+ * Data provider for create allowed countries for a particular store .
116
127
*
128
+ * @param Collection $collection
117
129
* @return array
118
130
*/
119
131
public function addressesDataProvider (): array
120
132
{
121
133
return [
122
134
'address_in_single_allowed_country ' => [1 , ['US ' ]],
123
- 'address_not_in_single_allowed_country ' => [1 , ['FR ' ]],
124
135
'address_in_multiple_allowed_countries ' => [1 , ['US ' , 'IN ' ]],
125
- 'address_not_in_multiple_allowed_countries ' => [1 , ['FR ' , 'DE ' ]],
126
136
];
127
137
}
128
138
}
0 commit comments