comparison core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\node\Functional; 3 namespace Drupal\Tests\node\Functional;
4 4
5 use Drupal\Core\Database\Database;
5 use Drupal\node\NodeInterface; 6 use Drupal\node\NodeInterface;
6 7
7 /** 8 /**
8 * Create a node with revisions and test viewing, saving, reverting, and 9 * Create a node with revisions and test viewing, saving, reverting, and
9 * deleting revisions for user with access to all. 10 * deleting revisions for user with access to all.
145 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/revert", [], t('Revert')); 146 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/revert", [], t('Revert'));
146 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', 147 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.',
147 [ 148 [
148 '@type' => 'Basic page', 149 '@type' => 'Basic page',
149 '%title' => $nodes[1]->getTitle(), 150 '%title' => $nodes[1]->getTitle(),
150 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()), 151 '%revision-date' => $this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime()),
151 ]), 152 ]),
152 'Revision reverted.'); 153 'Revision reverted.');
153 $node_storage->resetCache([$node->id()]); 154 $node_storage->resetCache([$node->id()]);
154 $reverted_node = $node_storage->load($node->id()); 155 $reverted_node = $node_storage->load($node->id());
155 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); 156 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.');
170 171
171 // Confirm revisions delete properly. 172 // Confirm revisions delete properly.
172 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete')); 173 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete'));
173 $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', 174 $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
174 [ 175 [
175 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()), 176 '%revision-date' => $this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime()),
176 '@type' => 'Basic page', 177 '@type' => 'Basic page',
177 '%title' => $nodes[1]->getTitle(), 178 '%title' => $nodes[1]->getTitle(),
178 ]), 179 ]),
179 'Revision deleted.'); 180 'Revision deleted.');
181 $connection = Database::getConnection();
180 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', 182 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid',
181 [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 183 [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0,
182 'Revision not found.'); 184 'Revision not found.');
183 185
184 // Set the revision timestamp to an older date to make sure that the 186 // Set the revision timestamp to an older date to make sure that the
185 // confirmation message correctly displays the stored revision date. 187 // confirmation message correctly displays the stored revision date.
186 $old_revision_date = REQUEST_TIME - 86400; 188 $old_revision_date = REQUEST_TIME - 86400;
187 db_update('node_revision') 189 $connection->update('node_revision')
188 ->condition('vid', $nodes[2]->getRevisionId()) 190 ->condition('vid', $nodes[2]->getRevisionId())
189 ->fields([ 191 ->fields([
190 'revision_timestamp' => $old_revision_date, 192 'revision_timestamp' => $old_revision_date,
191 ]) 193 ])
192 ->execute(); 194 ->execute();
193 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert')); 195 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert'));
194 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [ 196 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [
195 '@type' => 'Basic page', 197 '@type' => 'Basic page',
196 '%title' => $nodes[2]->getTitle(), 198 '%title' => $nodes[2]->getTitle(),
197 '%revision-date' => format_date($old_revision_date), 199 '%revision-date' => $this->container->get('date.formatter')->format($old_revision_date),
198 ])); 200 ]));
199 201
200 // Create 50 more revisions in order to trigger paging on the revisions 202 // Create 50 more revisions in order to trigger paging on the revisions
201 // overview screen. 203 // overview screen.
202 $node = $nodes[0]; 204 $node = $nodes[0];