Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
41c24295
Unverified
Commit
41c24295
authored
5 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3042536
by claudiu.cristea, Lendude: Convert AccessPermissionTest into a Kernel test
parent
5aa09075
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php
+110
-0
110 additions, 0 deletions
...ules/user/tests/src/Kernel/Views/AccessPermissionTest.php
with
110 additions
and
0 deletions
core/modules/user/tests/src/
Functiona
l/Views/AccessPermissionTest.php
→
core/modules/user/tests/src/
Kerne
l/Views/AccessPermissionTest.php
+
110
−
0
View file @
41c24295
<?php
namespace
Drupal\Tests\user\
Functiona
l\Views
;
namespace
Drupal\Tests\user\
Kerne
l\Views
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\Tests\user\Traits\UserCreationTrait
;
use
Drupal\user\Plugin\views\access\Permission
;
use
Drupal\views\Plugin\views\display\DisplayPluginBase
;
use
Drupal\views\Tests\ViewTestData
;
use
Drupal\views\Views
;
/**
...
...
@@ -12,15 +15,59 @@
* @group user
* @see \Drupal\user\Plugin\views\access\Permission
*/
class
AccessPermissionTest
extends
AccessTestBase
{
class
AccessPermissionTest
extends
KernelTestBase
{
use
UserCreationTrait
;
/**
* Views used by this test.
*
* @var array
* {@inheritdoc}
*/
protected
static
$modules
=
[
'node'
,
'system'
,
'user'
,
'user_test_views'
,
'views'
,
'views_test_data'
,
];
/**
* {@inheritdoc}
*/
public
static
$testViews
=
[
'test_access_perm'
];
/**
* A user with no special permissions.
*
* @var \Drupal\user\UserInterface
*/
protected
$webUser
;
/**
* A user with 'views_test_data test permission' permission.
*
* @var \Drupal\user\UserInterface
*/
protected
$normalUser
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
installSchema
(
'system'
,
[
'sequences'
]);
$this
->
installEntitySchema
(
'user'
);
$this
->
installEntitySchema
(
'node'
);
// Create first UID1 so, the other users are not super-admin.
$this
->
createUser
([],
NULL
,
FALSE
,
[
'uid'
=>
1
]);
$this
->
webUser
=
$this
->
createUser
();
$this
->
normalUser
=
$this
->
createUser
([
'views_test_data test permission'
]);
ViewTestData
::
createTestViews
(
get_class
(
$this
),
[
'user_test_views'
]);
}
/**
* Tests perm access plugin.
*/
...
...
@@ -29,8 +76,8 @@ public function testAccessPerm() {
$view
->
setDisplay
();
$access_plugin
=
$view
->
display_handler
->
getPlugin
(
'access'
);
$this
->
assert
True
(
$access_plugin
i
nstance
of
Permission
,
'Make sure the right class got instantiated.'
);
$this
->
assertEqual
(
$access_plugin
->
pluginTitle
()
,
t
(
'Permission'
)
);
$this
->
assert
I
nstance
Of
(
Permission
::
class
,
$access_plugin
);
$this
->
assertEqual
s
(
'Permission'
,
$access_plugin
->
pluginTitle
());
$this
->
assertFalse
(
$view
->
display_handler
->
access
(
$this
->
webUser
));
$this
->
assertTrue
(
$view
->
display_handler
->
access
(
$this
->
normalUser
));
...
...
@@ -46,22 +93,18 @@ public function testRenderCaching() {
'type'
=>
'tag'
,
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
\Drupal
::
service
(
'renderer'
);
/** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher
=
\Drupal
::
service
(
'account_switcher'
);
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$account_switcher
=
$this
->
container
->
get
(
'account_switcher'
);
// First access as user without access.
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$account_switcher
->
switchTo
(
$this
->
normalUser
);
$result
=
$renderer
->
renderPlain
(
$build
);
$this
->
assertNotEqual
(
$result
,
''
);
$account_switcher
->
switchTo
(
$this
->
webUser
);
$this
->
assertEmpty
(
$renderer
->
renderPlain
(
$build
));
// Then with access.
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$account_switcher
->
switchTo
(
$this
->
webUser
);
$result
=
$renderer
->
renderPlain
(
$build
);
$this
->
assertEqual
(
$result
,
''
);
$account_switcher
->
switchTo
(
$this
->
normalUser
);
$this
->
assertNotEmpty
(
$renderer
->
renderPlain
(
$build
));
}
}
This diff is collapsed.
Click to expand it.
Alex Pott
@alexpott
mentioned in commit
4c8bdc11
·
5 years ago
mentioned in commit
4c8bdc11
mentioned in commit 4c8bdc11b55121e16c66f29cacaa56b733735094
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment