Skip to content
Snippets Groups Projects
Commit a85b1ec7 authored by catch's avatar catch
Browse files

Issue #2987084 by amateescu: Convert EntityReferenceSelectionAccessTest to a kernel test

parent e8c9956d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface; use Drupal\comment\CommentInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\Comment;
...@@ -17,22 +19,46 @@ ...@@ -17,22 +19,46 @@
* *
* @group entity_reference * @group entity_reference
*/ */
class EntityReferenceSelectionAccessTest extends BrowserTestBase { class EntityReferenceSelectionAccessTest extends KernelTestBase {
use CommentTestTrait; use CommentTestTrait;
use ContentTypeCreationTrait;
use UserCreationTrait;
/** /**
* Modules to enable. * Modules to enable.
* *
* @var array * @var array
*/ */
public static $modules = ['node', 'comment']; public static $modules = ['comment', 'field', 'node', 'system', 'text', 'user'];
/**
* {@inheritdoc}
*/
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
// Create an Article node type. $this->installSchema('system', 'sequences');
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']); $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() { ...@@ -110,8 +136,8 @@ public function testNodeHandler() {
} }
// Test as a non-admin. // Test as a non-admin.
$normal_user = $this->drupalCreateUser(['access content']); $normal_user = $this->createUser(['access content']);
\Drupal::currentUser()->setAccount($normal_user); $this->setCurrentUser($normal_user);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -162,8 +188,8 @@ public function testNodeHandler() { ...@@ -162,8 +188,8 @@ public function testNodeHandler() {
$this->assertReferenceable($selection_options, $referenceable_tests, 'Node handler'); $this->assertReferenceable($selection_options, $referenceable_tests, 'Node handler');
// Test as an admin. // Test as an admin.
$admin_user = $this->drupalCreateUser(['access content', 'bypass node access']); $content_admin = $this->createUser(['access content', 'bypass node access']);
\Drupal::currentUser()->setAccount($admin_user); $this->setCurrentUser($content_admin);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -239,7 +265,7 @@ public function testUserHandler() { ...@@ -239,7 +265,7 @@ public function testUserHandler() {
} }
// Test as a non-admin. // Test as a non-admin.
\Drupal::currentUser()->setAccount($users['non_admin']); $this->setCurrentUser($users['non_admin']);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -278,7 +304,7 @@ public function testUserHandler() { ...@@ -278,7 +304,7 @@ public function testUserHandler() {
]; ];
$this->assertReferenceable($selection_options, $referenceable_tests, 'User handler'); $this->assertReferenceable($selection_options, $referenceable_tests, 'User handler');
\Drupal::currentUser()->setAccount($users['admin']); $this->setCurrentUser($users['admin']);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -361,6 +387,7 @@ public function testCommentHandler() { ...@@ -361,6 +387,7 @@ public function testCommentHandler() {
]; ];
// Build a set of test data. // Build a set of test data.
$this->createContentType(['type' => 'article', 'name' => 'Article']);
$node_values = [ $node_values = [
'published' => [ 'published' => [
'type' => 'article', 'type' => 'article',
...@@ -431,8 +458,8 @@ public function testCommentHandler() { ...@@ -431,8 +458,8 @@ public function testCommentHandler() {
} }
// Test as a non-admin. // Test as a non-admin.
$normal_user = $this->drupalCreateUser(['access content', 'access comments']); $normal_user = $this->createUser(['access content', 'access comments']);
\Drupal::currentUser()->setAccount($normal_user); $this->setCurrentUser($normal_user);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -470,8 +497,8 @@ public function testCommentHandler() { ...@@ -470,8 +497,8 @@ public function testCommentHandler() {
$this->assertReferenceable($selection_options, $referenceable_tests, 'Comment handler'); $this->assertReferenceable($selection_options, $referenceable_tests, 'Comment handler');
// Test as a comment admin. // Test as a comment admin.
$admin_user = $this->drupalCreateUser(['access content', 'access comments', 'administer comments']); $admin_user = $this->createUser(['access content', 'access comments', 'administer comments']);
\Drupal::currentUser()->setAccount($admin_user); $this->setCurrentUser($admin_user);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
...@@ -488,8 +515,8 @@ public function testCommentHandler() { ...@@ -488,8 +515,8 @@ public function testCommentHandler() {
$this->assertReferenceable($selection_options, $referenceable_tests, 'Comment handler (comment admin)'); $this->assertReferenceable($selection_options, $referenceable_tests, 'Comment handler (comment admin)');
// Test as a node and comment admin. // Test as a node and comment admin.
$admin_user = $this->drupalCreateUser(['access content', 'access comments', 'administer comments', 'bypass node access']); $admin_user = $this->createUser(['access content', 'access comments', 'administer comments', 'bypass node access']);
\Drupal::currentUser()->setAccount($admin_user); $this->setCurrentUser($admin_user);
$referenceable_tests = [ $referenceable_tests = [
[ [
'arguments' => [ 'arguments' => [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment