3 namespace Drupal\Tests\node\Functional;
5 use Drupal\node\Entity\NodeType;
8 * Tests the revision tab display.
10 * This test is similar to NodeRevisionsUITest except that it uses a user with
11 * the bypass node access permission to make sure that the revision access
12 * check adds correct cacheability metadata.
16 class NodeRevisionsUiBypassAccessTest extends NodeTestBase {
19 * User with bypass node access permission.
21 * @var \Drupal\user\Entity\User
28 public static $modules = ['block'];
33 protected function setUp() {
37 $this->editor = $this->drupalCreateUser([
39 'edit any page content',
40 'view page revisions',
42 'access user profiles',
47 * Checks that the Revision tab is displayed correctly.
49 public function testDisplayRevisionTab() {
50 $this->drupalPlaceBlock('local_tasks_block');
52 $this->drupalLogin($this->editor);
53 $node_storage = $this->container->get('entity.manager')->getStorage('node');
55 // Set page revision setting 'create new revision'. This will mean new
56 // revisions are created by default when the node is edited.
57 $type = NodeType::load('page');
58 $type->setNewRevision(TRUE);
62 $node = $this->drupalCreateNode();
64 // Verify the checkbox is checked on the node edit form.
65 $this->drupalGet('node/' . $node->id() . '/edit');
66 $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
68 // Uncheck the create new revision checkbox and save the node.
69 $edit = ['revision' => FALSE];
70 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
72 $this->assertUrl($node->toUrl());
73 $this->assertNoLink(t('Revisions'));
75 // Verify the checkbox is checked on the node edit form.
76 $this->drupalGet('node/' . $node->id() . '/edit');
77 $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
79 // Submit the form without changing the checkbox.
81 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
83 $this->assertUrl($node->toUrl());
84 $this->assertLink(t('Revisions'));