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

Public Member Functions

 testAcl ()
 

Data Fields

const ACL_FUNC_NAME = '_isAllowed'
 
const ACL_CONST_NAME = 'ADMIN_RESOURCE'
 
const DEFAULT_BACKEND_RESOURCE = 'Magento_Backend::admin'
 

Protected Member Functions

 setUp ()
 

Detailed Description

Definition at line 12 of file ControllerAclTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Set up before test execution.

Definition at line 46 of file ControllerAclTest.php.

47  {
48  $whitelistedClasses = [];
49  $path = sprintf('%s/_files/controller_acl_test_whitelist_*.txt', __DIR__);
50  foreach (glob($path) as $listFile) {
51  $whitelistedClasses = array_merge(
52  $whitelistedClasses,
53  file($listFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
54  );
55  }
56  foreach ($whitelistedClasses as $item) {
57  if (substr($item, 0, 1) === '#') {
58  continue;
59  }
60  $this->whiteListedBackendControllers[$item] = 1;
61  }
62  }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60

◆ testAcl()

testAcl ( )

Test ACL in the admin area by various assertions.

Definition at line 67 of file ControllerAclTest.php.

68  {
69  $errorMessages = [];
70  $pathMask = sprintf('%s/../../../_files/changed_files*', __DIR__, DIRECTORY_SEPARATOR);
72  foreach ($changedFiles as $line) {
73  $relativeFilePath = $line[0];
74  // we don't have to check tests,
75  if ($this->isItTest($relativeFilePath)) {
76  continue;
77  }
78 
79  $controllerPath = $this->getControllerPath($relativeFilePath);
80  if (!$controllerPath) {
81  continue;
82  }
83 
84  $controllerClass = $this->getClassByFilePath($controllerPath);
85  // skip whitelisted controllers.
86  if (isset($this->whiteListedBackendControllers[$controllerClass->getName()])) {
87  continue;
88  }
89  // we don't have to check abstract classes.
90  if ($controllerClass->isAbstract()) {
91  continue;
92  }
93 
94  $className = $controllerClass->getName();
95 
96  if (!$this->isClassExtendsBackendClass($controllerClass)) {
97  $inheritanceMessage = "Backend controller $className have to inherit " . AbstractAction::class;
98  $errorMessages[] = $inheritanceMessage;
99  continue;
100  };
101 
102  $isAclRedefinedInTheChildClass = $this->isConstantOverwritten($controllerClass)
103  || $this->isMethodOverwritten($controllerClass);
104  if (!$isAclRedefinedInTheChildClass) {
105  $errorMessages[] = "Backend controller $className have to overwrite _isAllowed method or "
106  . 'ADMIN_RESOURCE constant';
107  }
108 
109  $errorMessages = array_merge($errorMessages, $this->collectAclErrorsInTheXml($controllerClass));
110  }
111  sort($errorMessages);
112  $this->assertEmpty($errorMessages, implode("\n", $errorMessages));
113  }
static getPhpFiles($changedFilesList, $fileTypes=0)
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

Field Documentation

◆ ACL_CONST_NAME

const ACL_CONST_NAME = 'ADMIN_RESOURCE'

Name of the const. that contains ACL resource path.

Definition at line 22 of file ControllerAclTest.php.

◆ ACL_FUNC_NAME

const ACL_FUNC_NAME = '_isAllowed'

Default function for checking accessibility of the ACL resource.

Definition at line 17 of file ControllerAclTest.php.

◆ DEFAULT_BACKEND_RESOURCE

const DEFAULT_BACKEND_RESOURCE = 'Magento_Backend::admin'

Default value from the AbstractResource.

Definition at line 27 of file ControllerAclTest.php.


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