Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
a85b1ec7
Commit
a85b1ec7
authored
Jul 24, 2018
by
catch
Browse files
Issue
#2987084
by amateescu: Convert EntityReferenceSelectionAccessTest to a kernel test
parent
e8c9956d
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
View file @
a85b1ec7
...
...
@@ -6,9 +6,11 @@
use
Drupal\Component\Utility\Html
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\comment\CommentInterface
;
use
Drupal\KernelTests\KernelTestBase
;
use
Drupal\node\Entity\Node
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\node\NodeInterface
;
use
Drupal\Tests\node\Traits\ContentTypeCreationTrait
;
use
Drupal\Tests\user\Traits\UserCreationTrait
;
use
Drupal\user\Entity\User
;
use
Drupal\comment\Entity\Comment
;
...
...
@@ -17,22 +19,46 @@
*
* @group entity_reference
*/
class
EntityReferenceSelectionAccessTest
extends
Browser
TestBase
{
class
EntityReferenceSelectionAccessTest
extends
Kernel
TestBase
{
use
CommentTestTrait
;
use
ContentTypeCreationTrait
;
use
UserCreationTrait
;
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
[
'
node'
,
'comment
'
];
public
static
$modules
=
[
'
comment'
,
'field'
,
'node'
,
'system'
,
'text'
,
'user
'
];
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
// Create an Article node type.
$this
->
drupalCreateContentType
([
'type'
=>
'article'
,
'name'
=>
'Article'
]);
$this
->
installSchema
(
'system'
,
'sequences'
);
$this
->
installSchema
(
'comment'
,
[
'comment_entity_statistics'
]);
$this
->
installEntitySchema
(
'comment'
);
$this
->
installEntitySchema
(
'node'
);
$this
->
installEntitySchema
(
'user'
);
$this
->
installConfig
([
'comment'
,
'field'
,
'node'
,
'user'
]);
// Create the anonymous and the admin users.
$anonymous_user
=
User
::
create
([
'uid'
=>
0
,
'name'
=>
''
,
]);
$anonymous_user
->
save
();
$admin_user
=
User
::
create
([
'uid'
=>
1
,
'name'
=>
'admin'
,
'status'
=>
1
,
]);
$admin_user
->
save
();
}
/**
...
...
@@ -110,8 +136,8 @@ public function testNodeHandler() {
}
// Test as a non-admin.
$normal_user
=
$this
->
drupalC
reateUser
([
'access content'
]);
\
Drupal
::
currentUser
()
->
setAccount
(
$normal_user
);
$normal_user
=
$this
->
c
reateUser
([
'access content'
]);
$this
->
setCurrentUser
(
$normal_user
);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -162,8 +188,8 @@ public function testNodeHandler() {
$this
->
assertReferenceable
(
$selection_options
,
$referenceable_tests
,
'Node handler'
);
// Test as an admin.
$admin
_user
=
$this
->
drupalC
reateUser
([
'access content'
,
'bypass node access'
]);
\
Drupal
::
currentUser
()
->
setAccount
(
$admin_user
);
$
content_
admin
=
$this
->
c
reateUser
([
'access content'
,
'bypass node access'
]);
$this
->
setCurrentUser
(
$content_admin
);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -239,7 +265,7 @@ public function testUserHandler() {
}
// Test as a non-admin.
\
Drupal
::
currentUser
()
->
setAccount
(
$users
[
'non_admin'
]);
$this
->
setCurrentUser
(
$users
[
'non_admin'
]);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -278,7 +304,7 @@ public function testUserHandler() {
];
$this
->
assertReferenceable
(
$selection_options
,
$referenceable_tests
,
'User handler'
);
\
Drupal
::
currentUser
()
->
setAccount
(
$users
[
'admin'
]);
$this
->
setCurrentUser
(
$users
[
'admin'
]);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -361,6 +387,7 @@ public function testCommentHandler() {
];
// Build a set of test data.
$this
->
createContentType
([
'type'
=>
'article'
,
'name'
=>
'Article'
]);
$node_values
=
[
'published'
=>
[
'type'
=>
'article'
,
...
...
@@ -431,8 +458,8 @@ public function testCommentHandler() {
}
// Test as a non-admin.
$normal_user
=
$this
->
drupalC
reateUser
([
'access content'
,
'access comments'
]);
\
Drupal
::
currentUser
()
->
setAccount
(
$normal_user
);
$normal_user
=
$this
->
c
reateUser
([
'access content'
,
'access comments'
]);
$this
->
setCurrentUser
(
$normal_user
);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -470,8 +497,8 @@ public function testCommentHandler() {
$this
->
assertReferenceable
(
$selection_options
,
$referenceable_tests
,
'Comment handler'
);
// Test as a comment admin.
$admin_user
=
$this
->
drupalC
reateUser
([
'access content'
,
'access comments'
,
'administer comments'
]);
\
Drupal
::
currentUser
()
->
setAccount
(
$admin_user
);
$admin_user
=
$this
->
c
reateUser
([
'access content'
,
'access comments'
,
'administer comments'
]);
$this
->
setCurrentUser
(
$admin_user
);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
@@ -488,8 +515,8 @@ public function testCommentHandler() {
$this
->
assertReferenceable
(
$selection_options
,
$referenceable_tests
,
'Comment handler (comment admin)'
);
// Test as a node and comment admin.
$admin_user
=
$this
->
drupalC
reateUser
([
'access content'
,
'access comments'
,
'administer comments'
,
'bypass node access'
]);
\
Drupal
::
currentUser
()
->
setAccount
(
$admin_user
);
$admin_user
=
$this
->
c
reateUser
([
'access content'
,
'access comments'
,
'administer comments'
,
'bypass node access'
]);
$this
->
setCurrentUser
(
$admin_user
);
$referenceable_tests
=
[
[
'arguments'
=>
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment