annotate core/modules/node/tests/src/Functional/NodeRevisionsUiBypassAccessTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\node\Functional;
Chris@0 4
Chris@0 5 use Drupal\node\Entity\NodeType;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Tests the revision tab display.
Chris@0 9 *
Chris@0 10 * This test is similar to NodeRevisionsUITest except that it uses a user with
Chris@0 11 * the bypass node access permission to make sure that the revision access
Chris@0 12 * check adds correct cacheability metadata.
Chris@0 13 *
Chris@0 14 * @group node
Chris@0 15 */
Chris@0 16 class NodeRevisionsUiBypassAccessTest extends NodeTestBase {
Chris@0 17
Chris@0 18 /**
Chris@0 19 * User with bypass node access permission.
Chris@0 20 *
Chris@0 21 * @var \Drupal\user\Entity\User
Chris@0 22 */
Chris@0 23 protected $editor;
Chris@0 24
Chris@0 25 /**
Chris@0 26 * {@inheritdoc}
Chris@0 27 */
Chris@0 28 public static $modules = ['block'];
Chris@0 29
Chris@0 30 /**
Chris@0 31 * {@inheritdoc}
Chris@0 32 */
Chris@0 33 protected function setUp() {
Chris@0 34 parent::setUp();
Chris@0 35
Chris@0 36 // Create a user.
Chris@0 37 $this->editor = $this->drupalCreateUser([
Chris@0 38 'administer nodes',
Chris@0 39 'edit any page content',
Chris@0 40 'view page revisions',
Chris@0 41 'bypass node access',
Chris@0 42 'access user profiles',
Chris@0 43 ]);
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Checks that the Revision tab is displayed correctly.
Chris@0 48 */
Chris@0 49 public function testDisplayRevisionTab() {
Chris@0 50 $this->drupalPlaceBlock('local_tasks_block');
Chris@0 51
Chris@0 52 $this->drupalLogin($this->editor);
Chris@0 53 $node_storage = $this->container->get('entity.manager')->getStorage('node');
Chris@0 54
Chris@0 55 // Set page revision setting 'create new revision'. This will mean new
Chris@0 56 // revisions are created by default when the node is edited.
Chris@0 57 $type = NodeType::load('page');
Chris@0 58 $type->setNewRevision(TRUE);
Chris@0 59 $type->save();
Chris@0 60
Chris@0 61 // Create the node.
Chris@0 62 $node = $this->drupalCreateNode();
Chris@0 63
Chris@0 64 // Verify the checkbox is checked on the node edit form.
Chris@0 65 $this->drupalGet('node/' . $node->id() . '/edit');
Chris@0 66 $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
Chris@0 67
Chris@0 68 // Uncheck the create new revision checkbox and save the node.
Chris@0 69 $edit = ['revision' => FALSE];
Chris@0 70 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
Chris@0 71
Chris@0 72 $this->assertUrl($node->toUrl());
Chris@18 73 // Verify revisions exist since the content type has revisions enabled.
Chris@18 74 $this->assertLink(t('Revisions'));
Chris@0 75
Chris@0 76 // Verify the checkbox is checked on the node edit form.
Chris@0 77 $this->drupalGet('node/' . $node->id() . '/edit');
Chris@0 78 $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
Chris@0 79
Chris@0 80 // Submit the form without changing the checkbox.
Chris@0 81 $edit = [];
Chris@0 82 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
Chris@0 83
Chris@0 84 $this->assertUrl($node->toUrl());
Chris@0 85 $this->assertLink(t('Revisions'));
Chris@18 86
Chris@18 87 // Unset page revision setting 'create new revision'. This will mean new
Chris@18 88 // revisions are not created by default when the node is edited.
Chris@18 89 $type = NodeType::load('page');
Chris@18 90 $type->setNewRevision(FALSE);
Chris@18 91 $type->save();
Chris@18 92
Chris@18 93 // Create the node.
Chris@18 94 $node = $this->drupalCreateNode();
Chris@18 95
Chris@18 96 // Verify the checkbox is unchecked on the node edit form.
Chris@18 97 $this->drupalGet('node/' . $node->id() . '/edit');
Chris@18 98 $this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked");
Chris@18 99 // Submit the form without changing the checkbox.
Chris@18 100 $edit = [];
Chris@18 101 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
Chris@18 102
Chris@18 103 $this->assertUrl($node->toUrl());
Chris@18 104 // Verify that no link to revisions is displayed since the type
Chris@18 105 // has the 'create new revision' setting unset.
Chris@18 106 $this->assertNoLink(t('Revisions'));
Chris@18 107
Chris@18 108 // Verify the checkbox is unchecked on the node edit form.
Chris@18 109 $this->drupalGet('node/' . $node->id() . '/edit');
Chris@18 110 $this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked");
Chris@18 111
Chris@18 112 // Check the 'create new revision' checkbox and save the node.
Chris@18 113 $edit = ['revision' => TRUE];
Chris@18 114 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
Chris@18 115
Chris@18 116 $this->assertUrl($node->toUrl());
Chris@18 117 // Verify that the link is displayed since a new revision is created and
Chris@18 118 // the 'create new revision' checkbox on the node is checked.
Chris@18 119 $this->assertLink(t('Revisions'));
Chris@0 120 }
Chris@0 121
Chris@0 122 }