Chris@0: drupalCreateUser(['create page content', 'edit own page content']); Chris@0: $this->drupalLogin($web_user); Chris@0: Chris@0: // Create a node. Chris@0: $edit = []; Chris@0: $edit['title[0][value]'] = $this->randomMachineName(8); Chris@0: $edit['body[0][value]'] = t('Data that should appear only in the body for the node.'); Chris@0: $edit['body[0][summary]'] = t('Extra data that should appear only in the teaser for the node.'); Chris@0: $this->drupalPostForm('node/add/page', $edit, t('Save')); Chris@0: Chris@0: $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); Chris@0: Chris@0: // Set the flag to alter the view mode and view the node. Chris@0: \Drupal::state()->set('node_test_change_view_mode', 'teaser'); Chris@0: Cache::invalidateTags(['rendered']); Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: Chris@0: // Check that teaser mode is viewed. Chris@0: $this->assertText('Extra data that should appear only in the teaser for the node.', 'Teaser text present'); Chris@0: // Make sure body text is not present. Chris@0: $this->assertNoText('Data that should appear only in the body for the node.', 'Body text not present'); Chris@0: Chris@0: // Test that the correct build mode has been set. Chris@0: $build = $this->buildEntityView($node); Chris@0: $this->assertEqual($build['#view_mode'], 'teaser', 'The view mode has correctly been set to teaser.'); Chris@0: } Chris@0: Chris@0: }