Chris@0: editor = $this->drupalCreateUser([ Chris@0: 'administer nodes', Chris@0: 'edit any page content', Chris@0: 'view page revisions', Chris@0: 'bypass node access', Chris@0: 'access user profiles', Chris@0: ]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks that the Revision tab is displayed correctly. Chris@0: */ Chris@0: public function testDisplayRevisionTab() { Chris@0: $this->drupalPlaceBlock('local_tasks_block'); Chris@0: Chris@0: $this->drupalLogin($this->editor); Chris@0: $node_storage = $this->container->get('entity.manager')->getStorage('node'); Chris@0: Chris@0: // Set page revision setting 'create new revision'. This will mean new Chris@0: // revisions are created by default when the node is edited. Chris@0: $type = NodeType::load('page'); Chris@0: $type->setNewRevision(TRUE); Chris@0: $type->save(); Chris@0: Chris@0: // Create the node. Chris@0: $node = $this->drupalCreateNode(); Chris@0: Chris@0: // Verify the checkbox is checked on the node edit form. Chris@0: $this->drupalGet('node/' . $node->id() . '/edit'); Chris@0: $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked"); Chris@0: Chris@0: // Uncheck the create new revision checkbox and save the node. Chris@0: $edit = ['revision' => FALSE]; Chris@0: $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save'); Chris@0: Chris@0: $this->assertUrl($node->toUrl()); Chris@18: // Verify revisions exist since the content type has revisions enabled. Chris@18: $this->assertLink(t('Revisions')); Chris@0: Chris@0: // Verify the checkbox is checked on the node edit form. Chris@0: $this->drupalGet('node/' . $node->id() . '/edit'); Chris@0: $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked"); Chris@0: Chris@0: // Submit the form without changing the checkbox. Chris@0: $edit = []; Chris@0: $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save'); Chris@0: Chris@0: $this->assertUrl($node->toUrl()); Chris@0: $this->assertLink(t('Revisions')); Chris@18: Chris@18: // Unset page revision setting 'create new revision'. This will mean new Chris@18: // revisions are not created by default when the node is edited. Chris@18: $type = NodeType::load('page'); Chris@18: $type->setNewRevision(FALSE); Chris@18: $type->save(); Chris@18: Chris@18: // Create the node. Chris@18: $node = $this->drupalCreateNode(); Chris@18: Chris@18: // Verify the checkbox is unchecked on the node edit form. Chris@18: $this->drupalGet('node/' . $node->id() . '/edit'); Chris@18: $this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked"); Chris@18: // Submit the form without changing the checkbox. Chris@18: $edit = []; Chris@18: $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save'); Chris@18: Chris@18: $this->assertUrl($node->toUrl()); Chris@18: // Verify that no link to revisions is displayed since the type Chris@18: // has the 'create new revision' setting unset. Chris@18: $this->assertNoLink(t('Revisions')); Chris@18: Chris@18: // Verify the checkbox is unchecked on the node edit form. Chris@18: $this->drupalGet('node/' . $node->id() . '/edit'); Chris@18: $this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked"); Chris@18: Chris@18: // Check the 'create new revision' checkbox and save the node. Chris@18: $edit = ['revision' => TRUE]; Chris@18: $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save'); Chris@18: Chris@18: $this->assertUrl($node->toUrl()); Chris@18: // Verify that the link is displayed since a new revision is created and Chris@18: // the 'create new revision' checkbox on the node is checked. Chris@18: $this->assertLink(t('Revisions')); Chris@0: } Chris@0: Chris@0: }