NodeRevisionsUiBypassAccessTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Drupal\Tests\node\Functional;
  3. use Drupal\node\Entity\NodeType;
  4. /**
  5. * Tests the revision tab display.
  6. *
  7. * This test is similar to NodeRevisionsUITest except that it uses a user with
  8. * the bypass node access permission to make sure that the revision access
  9. * check adds correct cacheability metadata.
  10. *
  11. * @group node
  12. */
  13. class NodeRevisionsUiBypassAccessTest extends NodeTestBase {
  14. /**
  15. * User with bypass node access permission.
  16. *
  17. * @var \Drupal\user\Entity\User
  18. */
  19. protected $editor;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static $modules = ['block'];
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function setUp() {
  28. parent::setUp();
  29. // Create a user.
  30. $this->editor = $this->drupalCreateUser([
  31. 'administer nodes',
  32. 'edit any page content',
  33. 'view page revisions',
  34. 'bypass node access',
  35. 'access user profiles',
  36. ]);
  37. }
  38. /**
  39. * Checks that the Revision tab is displayed correctly.
  40. */
  41. public function testDisplayRevisionTab() {
  42. $this->drupalPlaceBlock('local_tasks_block');
  43. $this->drupalLogin($this->editor);
  44. $node_storage = $this->container->get('entity.manager')->getStorage('node');
  45. // Set page revision setting 'create new revision'. This will mean new
  46. // revisions are created by default when the node is edited.
  47. $type = NodeType::load('page');
  48. $type->setNewRevision(TRUE);
  49. $type->save();
  50. // Create the node.
  51. $node = $this->drupalCreateNode();
  52. // Verify the checkbox is checked on the node edit form.
  53. $this->drupalGet('node/' . $node->id() . '/edit');
  54. $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
  55. // Uncheck the create new revision checkbox and save the node.
  56. $edit = ['revision' => FALSE];
  57. $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
  58. $this->assertUrl($node->toUrl());
  59. $this->assertNoLink(t('Revisions'));
  60. // Verify the checkbox is checked on the node edit form.
  61. $this->drupalGet('node/' . $node->id() . '/edit');
  62. $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
  63. // Submit the form without changing the checkbox.
  64. $edit = [];
  65. $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
  66. $this->assertUrl($node->toUrl());
  67. $this->assertLink(t('Revisions'));
  68. }
  69. }