You are here

public function NodeEditTest::testNodeFormWithOverridePremiumAnyContentTypePermission in Node Option Premium 8

Tests with an editor that may set premium for any content type.

File

tests/src/Functional/NodeEditTest.php, line 51

Class

NodeEditTest
Tests editing nodes.

Namespace

Drupal\Tests\nopremium\Functional

Code

public function testNodeFormWithOverridePremiumAnyContentTypePermission() {

  // Create a user who may create/edit articles and set premium for all
  // content types.
  $editor = $this
    ->drupalCreateUser([
    'create article content',
    'edit any article content',
    'override premium option of any content type',
  ]);
  $this
    ->drupalLogin($editor);

  // Create a node and override premium setting.
  $edit = [
    'title[0][value]' => 'Lorem ipsum',
    'premium[value]' => 1,
  ];
  $this
    ->drupalPostForm('node/add/article', $edit, 'Save');

  // Assert that a node was created and premium is enabled.
  $node = Node::load(1);
  $this
    ->assertEquals(1, $node->premium->value);

  // Edit an existing node and enable premium there.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->assertEquals(0, $node->premium->value);
  $edit = [
    'premium[value]' => 1,
  ];
  $this
    ->drupalPostForm(sprintf('node/%s/edit', $node
    ->id()), $edit, 'Save');

  // Assert that the node is now premium.
  $node = $this
    ->reloadEntity($node);
  $this
    ->assertEquals(1, $node->premium->value);
}