Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
RulesTest Class Reference
Inheritance diagram for RulesTest:

Public Member Functions

 testCRUD ()
 
 testInitialUserPermissions ()
 
 testSetAllowForAllResources ()
 

Protected Member Functions

 setUp ()
 
 _checkExistingPermissions ($expectedDefaultPermissions)
 

Protected Attributes

 $_model
 
 $user
 

Detailed Description

@magentoAppArea adminhtml

Definition at line 11 of file RulesTest.php.

Member Function Documentation

◆ _checkExistingPermissions()

_checkExistingPermissions (   $expectedDefaultPermissions)
protected

Ensure that only expected permissions are set.

Definition at line 76 of file RulesTest.php.

77  {
78  $connection = $this->_model->getResource()->getConnection();
79  $this->user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
80  $roleId = $this->user->getRole()->getRoleId();
81  $ruleSelect = $connection->select()
82  ->from($this->_model->getResource()->getMainTable())
83  ->where('role_id = ?', $roleId);
84 
85  $rules = $ruleSelect->query()->fetchAll();
86  $actualPermissions = [];
87  foreach ($rules as $rule) {
88  $actualPermissions[] = $rule['resource_id'];
89  $this->assertEquals(
90  'allow',
91  $rule['permission'],
92  "Permission for '{$rule['resource_id']}' resource should be 'allow'"
93  );
94  }
95  $this->assertEquals($expectedDefaultPermissions, $actualPermissions, 'Default permissions are invalid');
96  }
$roleId
Definition: webapi_user.php:22
$connection
Definition: bulk.php:13

◆ setUp()

setUp ( )
protected

Definition at line 23 of file RulesTest.php.

24  {
26  \Magento\Authorization\Model\Rules::class
27  );
29  \Magento\User\Model\User::class
30  );
31  }

◆ testCRUD()

testCRUD ( )

@magentoDbIsolation enabled

Definition at line 36 of file RulesTest.php.

37  {
38  $this->_model
39  ->setRoleType('G')
40  ->setResourceId('Magento_Backend::all')
41  ->setPrivileges("")
42  ->setAssertId(0)
43  ->setRoleId(1)
44  ->setPermission('allow');
45 
46  $crud = new \Magento\TestFramework\Entity($this->_model, ['permission' => 'deny']);
47  $crud->testCrud();
48  }

◆ testInitialUserPermissions()

testInitialUserPermissions ( )

@magentoDbIsolation enabled

Definition at line 53 of file RulesTest.php.

54  {
55  $expectedDefaultPermissions = ['Magento_Backend::all'];
56  $this->_checkExistingPermissions($expectedDefaultPermissions);
57  }
_checkExistingPermissions($expectedDefaultPermissions)
Definition: RulesTest.php:76

◆ testSetAllowForAllResources()

testSetAllowForAllResources ( )

@covers \Magento\Authorization\Model\Rules::saveRel @magentoDbIsolation enabled

Definition at line 63 of file RulesTest.php.

64  {
65  $resources = ['Magento_Backend::all'];
66  $this->user->loadByUsername(\Magento\TestFramework\Bootstrap::ADMIN_NAME);
67  $roleId = $this->user->getRole()->getRoleId();
68  $this->_model->setRoleId($roleId)->setResources($resources)->saveRel();
69  $expectedPermissions = ['Magento_Backend::all'];
70  $this->_checkExistingPermissions($expectedPermissions);
71  }
_checkExistingPermissions($expectedDefaultPermissions)
Definition: RulesTest.php:76
$roleId
Definition: webapi_user.php:22

Field Documentation

◆ $_model

$_model
protected

Definition at line 16 of file RulesTest.php.

◆ $user

$user
protected

Definition at line 21 of file RulesTest.php.


The documentation for this class was generated from the following file: