View source
<?php
namespace Drupal\Tests\nopremium\Functional;
use Drupal\node\Entity\Node;
class NodeEditTest extends NopremiumBrowserTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
}
public function testNodeFormWithoutOverridePremiumPermission() {
$editor = $this
->drupalCreateUser([
'create article content',
'edit any article content',
]);
$this
->drupalLogin($editor);
$this
->drupalGet('node/add/article');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldNotExists('premium[value]');
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalGet(sprintf('node/%s/edit', $node
->id()));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Edit Article');
$this
->assertSession()
->fieldNotExists('premium[value]');
}
public function testNodeFormWithOverridePremiumAnyContentTypePermission() {
$editor = $this
->drupalCreateUser([
'create article content',
'edit any article content',
'override premium option of any content type',
]);
$this
->drupalLogin($editor);
$edit = [
'title[0][value]' => 'Lorem ipsum',
'premium[value]' => 1,
];
$this
->drupalPostForm('node/add/article', $edit, 'Save');
$node = Node::load(1);
$this
->assertEquals(1, $node->premium->value);
$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');
$node = $this
->reloadEntity($node);
$this
->assertEquals(1, $node->premium->value);
}
public function testNodeFormWithOverridePremiumArticlePermission() {
$this
->drupalCreateContentType([
'type' => 'foo',
'name' => 'Foo',
]);
$editor = $this
->drupalCreateUser([
'create article content',
'edit any article content',
'create foo content',
'edit any foo content',
'override article premium content',
]);
$this
->drupalLogin($editor);
$edit = [
'title[0][value]' => 'Lorem ipsum',
'premium[value]' => 1,
];
$this
->drupalPostForm('node/add/article', $edit, 'Save');
$node = Node::load(1);
$this
->assertEquals(1, $node->premium->value);
$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');
$node = $this
->reloadEntity($node);
$this
->assertEquals(1, $node->premium->value);
$this
->drupalGet('node/add/foo');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldNotExists('premium[value]');
$node = $this
->drupalCreateNode([
'type' => 'foo',
]);
$this
->drupalGet(sprintf('node/%s/edit', $node
->id()));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Edit Foo');
$this
->assertSession()
->fieldNotExists('premium[value]');
}
}