Skip to content

Commit 2a483b2

Browse files
committed
CABPI-465:Add new Default Role for imported Users with no Permissions by default Test coverage added
1 parent aae3f3e commit 2a483b2

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

app/code/Magento/AdminAdobeIms/Console/Command/AdminAdobeImsEnableCommand.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
184184
if ($clientId && $clientSecret && $organizationId && $isTwoFactorAuthEnabled) {
185185
$enabled = $this->enableModule($clientId, $clientSecret, $organizationId, $isTwoFactorAuthEnabled);
186186
if ($enabled) {
187-
$this->saveIMSAuthorizationRole();
187+
$this->saveImsAuthorizationRole();
188188
$output->writeln(__('Admin Adobe IMS integration is enabled'));
189189
return Cli::RETURN_SUCCESS;
190190
}
@@ -203,19 +203,24 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
203203
}
204204
}
205205

206-
private function saveIMSAuthorizationRole(): bool
206+
/**
207+
* Save new Adobe IMS role
208+
*
209+
* @return void
210+
* @throws \Exception
211+
*/
212+
private function saveImsAuthorizationRole(): bool
207213
{
208-
$roleCollection = $this->roleCollection->create()->addFieldToFilter('role_name', 'AdobeImsRole');
209-
214+
$roleCollection = $this->roleCollection->create()->addFieldToFilter('role_name', 'Adobe Ims');
210215
if (!$roleCollection->getSize()) {
211-
$this->role->setRoleName('AdobeImsRole')
216+
$this->role->setRoleName('Adobe Ims')
212217
->setUserType((string)UserContextInterface::USER_TYPE_ADMIN)
213218
->setUserId(0)
214219
->setRoleType(\Magento\Authorization\Model\Acl\Role\Group::ROLE_TYPE)
215220
->setParentId(0)
216221
->save();
217-
return true;
218222
}
223+
219224
return true;
220225
}
221226

app/code/Magento/AdminAdobeIms/Test/Unit/Command/AdminAdobeImsEnableCommandTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\AdminAdobeIms\Service\UpdateTokensService;
1515
use Magento\AdminAdobeIms\Service\ImsCommandOptionService;
1616
use Magento\AdminAdobeIms\Service\ImsConfig;
17+
use Magento\Authorization\Model\ResourceModel\Role\Collection as RoleCollection;
18+
use Magento\Authorization\Model\ResourceModel\Role\CollectionFactory;
19+
use Magento\Authorization\Model\Role;
1720
use Magento\Framework\App\Cache\Type\Config;
1821
use Magento\Framework\App\Cache\TypeListInterface;
1922
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
@@ -64,6 +67,16 @@ class AdminAdobeImsEnableCommandTest extends TestCase
6467
*/
6568
private $questionHelperMock;
6669

70+
/**
71+
* @var Role
72+
*/
73+
private $role;
74+
75+
/**
76+
* @var CollectionFactory
77+
*/
78+
private $roleCollection;
79+
6780
/**
6881
* @var AdminAdobeImsEnableCommand
6982
*/
@@ -78,6 +91,28 @@ protected function setUp(): void
7891
$this->imsCommandOptionService = $this->createMock(ImsCommandOptionService::class);
7992
$this->typeListInterface = $this->createMock(TypeListInterface::class);
8093
$this->updateTokensService = $this->createMock(UpdateTokensService::class);
94+
$roleCollectionMock = $this->createPartialMock(
95+
RoleCollection::class,
96+
['addFieldToFilter', 'getSize']
97+
);
98+
$roleCollectionMock->method('addFieldToFilter')->willReturnSelf();
99+
$this->roleCollection = $this->createPartialMock(
100+
CollectionFactory::class,
101+
['create']
102+
);
103+
$this->roleCollection->method('create')->willReturn(
104+
$roleCollectionMock
105+
);
106+
$this->role = $this->getMockBuilder(Role::class)
107+
->setMethods(['setParentId','setRoleType','setUserId','setRoleName','setUserType','save'])
108+
->disableOriginalConstructor()
109+
->getMock();
110+
$this->role->method('setRoleName')->willReturnSelf();
111+
$this->role->method('setUserType')->willReturnSelf();
112+
$this->role->method('setUserId')->willReturnSelf();
113+
$this->role->method('setRoleType')->willReturnSelf();
114+
$this->role->method('setParentId')->willReturnSelf();
115+
$this->role->method('save')->willReturnSelf();
81116

82117
$this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class)
83118
->disableOriginalConstructor()
@@ -90,7 +125,9 @@ protected function setUp(): void
90125
'adminImsConnection' => $this->adminImsConnectionMock,
91126
'imsCommandOptionService' => $this->imsCommandOptionService,
92127
'cacheTypeList' => $this->typeListInterface,
93-
'updateTokenService' => $this->updateTokensService
128+
'updateTokenService' => $this->updateTokensService,
129+
'role' => $this->role,
130+
'roleCollection' => $this->roleCollection
94131
]
95132
);
96133
}

0 commit comments

Comments
 (0)