1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test for Magento\Customer\Model\GroupManagement
*/
class GroupManagementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;
/**
* @var \Magento\Customer\Api\GroupManagementInterface
*/
protected $groupManagement;
protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->groupManagement = $this->objectManager->get(\Magento\Customer\Api\GroupManagementInterface::class);
}
/**
* @param $testGroup
* @param $storeId
*
* @dataProvider getDefaultGroupDataProvider
*/
public function testGetDefaultGroupWithStoreId($testGroup, $storeId)
{
$this->assertDefaultGroupMatches($testGroup, $storeId);
}
/**
* @magentoDataFixture Magento/Store/_files/core_second_third_fixturestore.php
*/
public function testGetDefaultGroupWithNonDefaultStoreId()
{
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class);
$nonDefaultStore = $storeManager->getStore('secondstore');
$nonDefaultStoreId = $nonDefaultStore->getId();
/** @var \Magento\Framework\App\MutableScopeConfig $scopeConfig */
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\MutableScopeConfig::class);
$scopeConfig->setValue(
\Magento\Customer\Model\GroupManagement::XML_PATH_DEFAULT_ID,
2,
ScopeInterface::SCOPE_STORE,
'secondstore'
);
$testGroup = ['id' => 2, 'code' => 'Wholesale', 'tax_class_id' => 3, 'tax_class_name' => 'Retail Customer'];
$this->assertDefaultGroupMatches($testGroup, $nonDefaultStoreId);
}
/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
*/
public function testGetDefaultGroupWithInvalidStoreId()
{
$storeId = 1234567;
$this->groupManagement->getDefaultGroup($storeId);
}
public function testIsReadonlyWithGroupId()
{
$testGroup = ['id' => 3, 'code' => 'General', 'tax_class_id' => 3, 'tax_class_name' => 'Retail Customer'];
$this->assertEquals(false, $this->groupManagement->isReadonly($testGroup['id']));
}
/**
* @expectedException \Magento\Framework\Exception\NoSuchEntityException
*/
public function testIsReadonlyWithInvalidGroupId()
{
$testGroup = ['id' => 4, 'code' => 'General', 'tax_class_id' => 3, 'tax_class_name' => 'Retail Customer'];
$this->groupManagement->isReadonly($testGroup['id']);
}
public function testGetNotLoggedInGroup()
{
$notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
$this->assertEquals(GroupManagement::NOT_LOGGED_IN_ID, $notLoggedInGroup->getId());
}
public function testGetLoggedInGroups()
{
$loggedInGroups = $this->groupManagement->getLoggedInGroups();
foreach ($loggedInGroups as $group) {
$this->assertNotEquals(GroupManagement::NOT_LOGGED_IN_ID, $group->getId());
$this->assertNotEquals(GroupManagement::CUST_GROUP_ALL, $group->getId());
}
}
public function testGetAllGroup()
{
$allGroup = $this->groupManagement->getAllCustomersGroup();
$this->assertEquals(32000, $allGroup->getId());
}
/**
* @return array
*/
public function getDefaultGroupDataProvider()
{
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class);
$defaultStoreId = $storeManager->getStore()->getId();
return [
'no store id' => [
['id' => 1, 'code' => 'General', 'tax_class_id' => 3, 'tax_class_name' => 'Retail Customer'],
null,
],
'default store id' => [
['id' => 1, 'code' => 'General', 'tax_class_id' => 3, 'tax_class_name' => 'Retail Customer'],
$defaultStoreId,
],
];
}
/**
* @param $testGroup
* @param $storeId
*/
private function assertDefaultGroupMatches($testGroup, $storeId)
{
$group = $this->groupManagement->getDefaultGroup($storeId);
$this->assertEquals($testGroup['id'], $group->getId());
$this->assertEquals($testGroup['code'], $group->getCode());
$this->assertEquals($testGroup['tax_class_id'], $group->getTaxClassId());
$this->assertEquals($testGroup['tax_class_name'], $group->getTaxClassName());
}
}