Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443205
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
drupal-3443205
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
No related merge requests found
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
<?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\user\Plugin\views\access\Permission
;
use
Drupal\views\Plugin\views\display\DisplayPluginBase
;
use
Drupal\views\Plugin\views\display\DisplayPluginBase
;
use
Drupal\views\Tests\ViewTestData
;
use
Drupal\views\Views
;
use
Drupal\views\Views
;
/**
/**
...
@@ -12,15 +15,59 @@
...
@@ -12,15 +15,59 @@
* @group user
* @group user
* @see \Drupal\user\Plugin\views\access\Permission
* @see \Drupal\user\Plugin\views\access\Permission
*/
*/
class
AccessPermissionTest
extends
AccessTestBase
{
class
AccessPermissionTest
extends
KernelTestBase
{
use
UserCreationTrait
;
/**
/**
* Views used by this test.
* {@inheritdoc}
*
*/
* @var array
protected
static
$modules
=
[
'node'
,
'system'
,
'user'
,
'user_test_views'
,
'views'
,
'views_test_data'
,
];
/**
* {@inheritdoc}
*/
*/
public
static
$testViews
=
[
'test_access_perm'
];
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.
* Tests perm access plugin.
*/
*/
...
@@ -29,8 +76,8 @@ public function testAccessPerm() {
...
@@ -29,8 +76,8 @@ public function testAccessPerm() {
$view
->
setDisplay
();
$view
->
setDisplay
();
$access_plugin
=
$view
->
display_handler
->
getPlugin
(
'access'
);
$access_plugin
=
$view
->
display_handler
->
getPlugin
(
'access'
);
$this
->
assert
True
(
$access_plugin
i
nstance
of
Permission
,
'Make sure the right class got instantiated.'
);
$this
->
assert
I
nstance
Of
(
Permission
::
class
,
$access_plugin
);
$this
->
assertEqual
(
$access_plugin
->
pluginTitle
()
,
t
(
'Permission'
)
);
$this
->
assertEqual
s
(
'Permission'
,
$access_plugin
->
pluginTitle
());
$this
->
assertFalse
(
$view
->
display_handler
->
access
(
$this
->
webUser
));
$this
->
assertFalse
(
$view
->
display_handler
->
access
(
$this
->
webUser
));
$this
->
assertTrue
(
$view
->
display_handler
->
access
(
$this
->
normalUser
));
$this
->
assertTrue
(
$view
->
display_handler
->
access
(
$this
->
normalUser
));
...
@@ -46,22 +93,18 @@ public function testRenderCaching() {
...
@@ -46,22 +93,18 @@ public function testRenderCaching() {
'type'
=>
'tag'
,
'type'
=>
'tag'
,
];
];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$renderer
=
\Drupal
::
service
(
'renderer'
);
$account_switcher
=
$this
->
container
->
get
(
'account_switcher'
);
/** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
$account_switcher
=
\Drupal
::
service
(
'account_switcher'
);
// First access as user without access.
// First access as user without access.
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$account_switcher
->
switchTo
(
$this
->
normalUser
);
$account_switcher
->
switchTo
(
$this
->
webUser
);
$result
=
$renderer
->
renderPlain
(
$build
);
$this
->
assertEmpty
(
$renderer
->
renderPlain
(
$build
));
$this
->
assertNotEqual
(
$result
,
''
);
// Then with access.
// Then with access.
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$build
=
DisplayPluginBase
::
buildBasicRenderable
(
'test_access_perm'
,
'default'
);
$account_switcher
->
switchTo
(
$this
->
webUser
);
$account_switcher
->
switchTo
(
$this
->
normalUser
);
$result
=
$renderer
->
renderPlain
(
$build
);
$this
->
assertNotEmpty
(
$renderer
->
renderPlain
(
$build
));
$this
->
assertEqual
(
$result
,
''
);
}
}
}
}
This diff is collapsed.
Click to expand it.
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