NodeViewTest.php in Node Option Premium 8
File
tests/src/Functional/NodeViewTest.php
View source
<?php
namespace Drupal\Tests\nopremium\Functional;
class NodeViewTest extends NopremiumBrowserTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'foo',
]);
$this->container
->get('entity_type.manager')
->getStorage('entity_view_display')
->load('node.foo.teaser')
->removeComponent('body')
->save();
}
protected function createNodeWithBodyValue($body, array $values = []) {
$values += [
'type' => 'foo',
'body' => [
[
'value' => $body,
'format' => filter_default_format(),
],
],
];
return $this
->drupalCreateNode($values);
}
public function testViewPremiumNode() {
$node = $this
->createNodeWithBodyValue('Lorem ipsum', [
'premium' => TRUE,
]);
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextNotContains('Lorem ipsum');
$this
->assertSession()
->pageTextContains('The full content of this page is available to premium users only.');
$this
->assertSession()
->pageTextNotContains('Read more');
$this
->assertSession()
->linkNotExists($node
->label());
}
public function testViewNonPremiumNode() {
$node = $this
->createNodeWithBodyValue('Lorem ipsum');
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextContains('Lorem ipsum');
$this
->assertSession()
->pageTextNotContains('The full content of this page is available to premium users only.');
}
public function testSpecificContentTypeMessage() {
$this
->config('nopremium.settings')
->set('messages', [
'foo' => 'The foo message',
])
->save();
$node = $this
->createNodeWithBodyValue('Lorem ipsum', [
'premium' => TRUE,
]);
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextNotContains('Lorem ipsum');
$this
->assertSession()
->pageTextContains('The foo message');
}
}