public function NodeViewTest::testViewModesSetting in Node Option Premium 8
Tests view modes setting.
Tests if enabling premium can be disabled for some view modes.
File
- tests/
src/ Kernel/ NodeViewTest.php, line 162
Class
- NodeViewTest
- Tests displaying nodes.
Namespace
Drupal\Tests\nopremium\KernelCode
public function testViewModesSetting() {
// Create two custom view modes and displays.
$this
->createViewModeAndDisplay('foo');
$this
->createViewModeAndDisplay('bar');
// Disable premium for 'bar' view mode.
$this
->config('nopremium.settings')
->set('view_modes', [
'foo' => 'foo',
])
->save();
// Create a premium node.
$node = $this
->createNodeWithBodyValue('Lorem ipsum', [
'premium' => TRUE,
]);
// Ensure that the premium message is still displayed on the 'foo' view
// mode.
$build = $this->viewBuilder
->view($node, 'foo');
$output = (string) $this->renderer
->renderPlain($build);
$this
->assertStringContainsString('The full content of this page is available to premium users only.', $output);
$this
->assertStringNotContainsString('Lorem ipsum', $output);
// But *not* on the 'bar' view mode.
$build = $this->viewBuilder
->view($node, 'bar');
$output = (string) $this->renderer
->renderPlain($build);
$this
->assertStringNotContainsString('The full content of this page is available to premium users only.', $output);
$this
->assertStringContainsString('Lorem ipsum', $output);
}