Same name in this branch
  1. 10 core/modules/content_moderation/tests/src/Functional/NodeAccessTest.php \Drupal\Tests\content_moderation\Functional\NodeAccessTest
  2. 10 core/modules/content_moderation/tests/src/Kernel/NodeAccessTest.php \Drupal\Tests\content_moderation\Kernel\NodeAccessTest
  3. 10 core/modules/node/tests/src/Kernel/NodeAccessTest.php \Drupal\Tests\node\Kernel\NodeAccessTest
Same name and namespace in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Kernel/NodeAccessTest.php \Drupal\Tests\content_moderation\Kernel\NodeAccessTest
  2. 9 core/modules/content_moderation/tests/src/Kernel/NodeAccessTest.php \Drupal\Tests\content_moderation\Kernel\NodeAccessTest

Tests with node access enabled.

@group content_moderation

Hierarchy

Expanded class hierarchy of NodeAccessTest

File

core/modules/content_moderation/tests/src/Kernel/NodeAccessTest.php, line 18

Namespace

Drupal\Tests\content_moderation\Kernel
View source
class NodeAccessTest extends KernelTestBase {
  use NodeCreationTrait;
  use UserCreationTrait;
  use ContentModerationTestTrait;

  /**
   * The moderation information service.
   *
   * @var \Drupal\content_moderation\ModerationInformationInterface
   */
  protected $moderationInformation;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'content_moderation',
    'filter',
    'node',
    'node_access_test',
    'system',
    'user',
    'workflows',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->installEntitySchema('content_moderation_state');
    $this
      ->installEntitySchema('node');
    $this
      ->installEntitySchema('user');
    $this
      ->installConfig([
      'content_moderation',
      'filter',
    ]);
    $this
      ->installSchema('node', [
      'node_access',
    ]);

    // Add a moderated node type.
    $node_type = NodeType::create([
      'type' => 'page',
      'name' => 'Page',
    ]);
    $node_type
      ->save();
    $workflow = $this
      ->createEditorialWorkflow();
    $workflow
      ->getTypePlugin()
      ->addEntityTypeAndBundle('node', 'page');
    $workflow
      ->save();
    $this->moderationInformation = \Drupal::service('content_moderation.moderation_information');
  }

  /**
   * @covers \Drupal\content_moderation\ModerationInformation::getDefaultRevisionId
   */
  public function testGetDefaultRevisionId() {

    // Create an admin user.
    $user = $this
      ->createUser([], NULL, TRUE);
    \Drupal::currentUser()
      ->setAccount($user);

    // Create a node.
    $node = $this
      ->createNode([
      'type' => 'page',
    ]);
    $this
      ->assertEquals($node
      ->getRevisionId(), $this->moderationInformation
      ->getDefaultRevisionId('node', $node
      ->id()));

    // Create a non-admin user.
    $user = $this
      ->createUser();
    \Drupal::currentUser()
      ->setAccount($user);
    $this
      ->assertEquals($node
      ->getRevisionId(), $this->moderationInformation
      ->getDefaultRevisionId('node', $node
      ->id()));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentModerationTestTrait::addEntityTypeAndBundleToWorkflow protected function Adds an entity type ID / bundle ID to the given workflow.
ContentModerationTestTrait::createEditorialWorkflow protected function Creates the editorial workflow.
NodeAccessTest::$moderationInformation protected property The moderation information service.
NodeAccessTest::$modules protected static property
NodeAccessTest::setUp protected function
NodeAccessTest::testGetDefaultRevisionId public function @covers \Drupal\content_moderation\ModerationInformation::getDefaultRevisionId
NodeCreationTrait::createNode protected function Creates a node based on default settings.
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions.
UserCreationTrait::createUser protected function Create a user with a given set of permissions.
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.