Chris@0: editor = $this->drupalCreateUser([ Chris@0: 'administer nodes', Chris@0: 'edit any page content', Chris@0: 'view page revisions', Chris@0: 'access user profiles', Chris@0: ]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks that unchecking 'Create new revision' works when editing a node. Chris@0: */ Chris@0: public function testNodeFormSaveWithoutRevision() { 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, t('Save')); Chris@0: Chris@0: // Load the node again and check the revision is the same as before. Chris@0: $node_storage->resetCache([$node->id()]); Chris@0: $node_revision = $node_storage->load($node->id(), TRUE); Chris@0: $this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created."); 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, t('Save')); Chris@0: Chris@0: // Load the node again and check the revision is different from before. Chris@0: $node_storage->resetCache([$node->id()]); Chris@0: $node_revision = $node_storage->load($node->id()); Chris@0: $this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created."); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks HTML double escaping of revision logs. Chris@0: */ Chris@0: public function testNodeRevisionDoubleEscapeFix() { Chris@0: $this->drupalLogin($this->editor); Chris@0: $nodes = []; Chris@0: Chris@0: // Create the node. Chris@0: $node = $this->drupalCreateNode(); Chris@0: Chris@0: $username = [ Chris@0: '#theme' => 'username', Chris@0: '#account' => $this->editor, Chris@0: ]; Chris@0: $editor = \Drupal::service('renderer')->renderPlain($username); Chris@0: Chris@0: // Get original node. Chris@0: $nodes[] = clone $node; Chris@0: Chris@0: // Create revision with a random title and body and update variables. Chris@0: $node->title = $this->randomMachineName(); Chris@0: $node->body = [ Chris@0: 'value' => $this->randomMachineName(32), Chris@0: 'format' => filter_default_format(), Chris@0: ]; Chris@0: $node->setNewRevision(); Chris@0: $revision_log = 'Revision message with markup.'; Chris@0: $node->revision_log->value = $revision_log; Chris@0: $node->save(); Chris@0: // Make sure we get revision information. Chris@0: $node = Node::load($node->id()); Chris@0: $nodes[] = clone $node; Chris@0: Chris@0: $this->drupalGet('node/' . $node->id() . '/revisions'); Chris@0: Chris@0: // Assert the old revision message. Chris@18: $date = $this->container->get('date.formatter')->format($nodes[0]->revision_timestamp->value, 'short'); Chris@0: $url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]); Chris@0: $this->assertRaw(\Drupal::l($date, $url) . ' by ' . $editor); Chris@0: Chris@0: // Assert the current revision message. Chris@18: $date = $this->container->get('date.formatter')->format($nodes[1]->revision_timestamp->value, 'short'); Chris@18: $this->assertRaw($nodes[1]->toLink($date)->toString() . ' by ' . $editor . '
' . $revision_log . '
'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks the Revisions tab. Chris@0: */ Chris@0: public function testNodeRevisionsTabWithDefaultRevision() { Chris@0: $this->drupalLogin($this->editor); Chris@0: Chris@0: // Create the node. Chris@0: $node = $this->drupalCreateNode(); Chris@0: $storage = \Drupal::entityTypeManager()->getStorage($node->getEntityTypeId()); Chris@0: Chris@0: // Create a new revision based on the default revision. Chris@0: // Revision 2. Chris@0: $node = $storage->load($node->id()); Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->save(); Chris@0: Chris@0: // Revision 3. Chris@0: $node = $storage->load($node->id()); Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->save(); Chris@0: Chris@0: // Revision 4. Chris@0: // Trigger translation changes in order to show the revision. Chris@0: $node = $storage->load($node->id()); Chris@0: $node->setTitle($this->randomString()); Chris@0: $node->isDefaultRevision(FALSE); Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->save(); Chris@0: Chris@0: // Revision 5. Chris@0: $node = $storage->load($node->id()); Chris@0: $node->isDefaultRevision(FALSE); Chris@0: $node->setNewRevision(TRUE); Chris@0: $node->save(); Chris@0: Chris@0: $node_id = $node->id(); Chris@0: Chris@0: $this->drupalGet('node/' . $node_id . '/revisions'); Chris@0: Chris@14: // Verify that the latest affected revision having been a default revision Chris@14: // is displayed as the current one. Chris@14: $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/1/revert'); Chris@14: $elements = $this->xpath('//tr[contains(@class, "revision-current")]/td/a[1]'); Chris@14: // The site may be installed in a subdirectory, so check if the URL is Chris@14: // contained in the retrieved one. Chris@14: $this->assertContains('/node/1', current($elements)->getAttribute('href')); Chris@14: Chris@0: // Verify that the default revision can be an older revision than the latest Chris@0: // one. Chris@14: // Assert that the revisions with translations changes are shown. Chris@0: $this->assertLinkByHref('/node/' . $node_id . '/revisions/4/revert'); Chris@0: Chris@0: // Assert that the revisions without translations changes are filtered out: Chris@0: // 2, 3 and 5. Chris@0: $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/2/revert'); Chris@0: $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/3/revert'); Chris@0: $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/5/revert'); Chris@0: } Chris@0: Chris@0: }