NodeEntityViewModeAlterTest.php in Zircon Profile 8
File
core/modules/node/src/Tests/NodeEntityViewModeAlterTest.php
View source
<?php
namespace Drupal\node\Tests;
use Drupal\Core\Cache\Cache;
class NodeEntityViewModeAlterTest extends NodeTestBase {
public static $modules = array(
'node_test',
);
function testNodeViewModeChange() {
$web_user = $this
->drupalCreateUser(array(
'create page content',
'edit own page content',
));
$this
->drupalLogin($web_user);
$edit = array();
$edit['title[0][value]'] = $this
->randomMachineName(8);
$edit['body[0][value]'] = t('Data that should appear only in the body for the node.');
$edit['body[0][summary]'] = t('Extra data that should appear only in the teaser for the node.');
$this
->drupalPostForm('node/add/page', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
\Drupal::state()
->set('node_test_change_view_mode', 'teaser');
Cache::invalidateTags([
'rendered',
]);
$this
->drupalGet('node/' . $node
->id());
$this
->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present');
$this
->assertNoText('Data that should appear only in the body for the node.', 'Body text not present');
$build = $this
->drupalBuildEntityView($node);
$this
->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.');
}
}