Skip to content

Commit d27cef9

Browse files
committed
ACP2E-668: replaced legacy data fixtures with parametrized data fixtures
1 parent c87e2c9 commit d27cef9

File tree

2 files changed

+21
-56
lines changed

2 files changed

+21
-56
lines changed

app/code/Magento/Authorization/Test/Fixture/Role.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Role implements RevertibleDataFixtureInterface
3030
'user_type' => UserContextInterface::USER_TYPE_ADMIN
3131
];
3232

33+
private const DEFAULT_DATA_RULES = [
34+
'id' => null,
35+
'role_id' => null,
36+
'resources' => ['Magento_Backend::all']
37+
];
38+
3339
/**
3440
* @var RoleFactory
3541
*/
@@ -45,18 +51,26 @@ class Role implements RevertibleDataFixtureInterface
4551
*/
4652
private $roleResourceModel;
4753

54+
/**
55+
* @var RulesFactory
56+
*/
57+
private $rulesFactory;
58+
4859
/**
4960
* @param RoleFactory $roleFactory
5061
* @param RoleResource $roleResourceModel
62+
* @param RulesFactory $rulesFactory
5163
* @param ProcessorInterface $dataProcessor
5264
*/
5365
public function __construct(
5466
RoleFactory $roleFactory,
5567
RoleResource $roleResourceModel,
68+
RulesFactory $rulesFactory,
5669
ProcessorInterface $dataProcessor
5770
) {
5871
$this->roleFactory = $roleFactory;
5972
$this->roleResourceModel = $roleResourceModel;
73+
$this->rulesFactory = $rulesFactory;
6074
$this->dataProcessor = $dataProcessor;
6175
}
6276

@@ -66,9 +80,15 @@ public function __construct(
6680
public function apply(array $data = []): ?DataObject
6781
{
6882
$role = $this->roleFactory->create();
69-
$role->setData($this->prepareData($data));
83+
$role->setData($this->prepareData(array_diff_key($data, self::DEFAULT_DATA_RULES)));
7084
$this->roleResourceModel->save($role);
7185

86+
$rules = $this->rulesFactory->create();
87+
$data = array_diff_key($data, self::DEFAULT_DATA);
88+
$rules->setRoleId($role->getId() ?? null);
89+
$rules->setResources($data['resources'] ?? []);
90+
$rules->saveRel();
91+
7292
return $role;
7393
}
7494

app/code/Magento/Authorization/Test/Fixture/Rules.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)