Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/tests/src/Functional/NodeRevisionsTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
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\Core\Url; | 6 use Drupal\Core\Url; |
6 use Drupal\field\Entity\FieldConfig; | 7 use Drupal\field\Entity\FieldConfig; |
7 use Drupal\field\Entity\FieldStorageConfig; | 8 use Drupal\field\Entity\FieldStorageConfig; |
8 use Drupal\language\Entity\ConfigurableLanguage; | 9 use Drupal\language\Entity\ConfigurableLanguage; |
9 use Drupal\node\Entity\Node; | 10 use Drupal\node\Entity\Node; |
161 // Confirm that revisions revert properly. | 162 // Confirm that revisions revert properly. |
162 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", [], t('Revert')); | 163 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert", [], t('Revert')); |
163 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [ | 164 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [ |
164 '@type' => 'Basic page', | 165 '@type' => 'Basic page', |
165 '%title' => $nodes[1]->label(), | 166 '%title' => $nodes[1]->label(), |
166 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()), | 167 '%revision-date' => $this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime()), |
167 ]), 'Revision reverted.'); | 168 ]), 'Revision reverted.'); |
168 $node_storage->resetCache([$node->id()]); | 169 $node_storage->resetCache([$node->id()]); |
169 $reverted_node = $node_storage->load($node->id()); | 170 $reverted_node = $node_storage->load($node->id()); |
170 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); | 171 $this->assertTrue(($nodes[1]->body->value == $reverted_node->body->value), 'Node reverted correctly.'); |
171 // Confirm the revision author is the user performing the revert. | 172 // Confirm the revision author is the user performing the revert. |
178 $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.'); | 179 $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.'); |
179 | 180 |
180 // Confirm revisions delete properly. | 181 // Confirm revisions delete properly. |
181 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete')); | 182 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete", [], t('Delete')); |
182 $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', [ | 183 $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', [ |
183 '%revision-date' => format_date($nodes[1]->getRevisionCreationTime()), | 184 '%revision-date' => $this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime()), |
184 '@type' => 'Basic page', | 185 '@type' => 'Basic page', |
185 '%title' => $nodes[1]->label(), | 186 '%title' => $nodes[1]->label(), |
186 ]), 'Revision deleted.'); | 187 ]), 'Revision deleted.'); |
188 $connection = Database::getConnection(); | |
187 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.'); | 189 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.'); |
188 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Field revision not found.'); | 190 $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Field revision not found.'); |
189 | 191 |
190 // Set the revision timestamp to an older date to make sure that the | 192 // Set the revision timestamp to an older date to make sure that the |
191 // confirmation message correctly displays the stored revision date. | 193 // confirmation message correctly displays the stored revision date. |
192 $old_revision_date = REQUEST_TIME - 86400; | 194 $old_revision_date = REQUEST_TIME - 86400; |
193 db_update('node_revision') | 195 $connection->update('node_revision') |
194 ->condition('vid', $nodes[2]->getRevisionId()) | 196 ->condition('vid', $nodes[2]->getRevisionId()) |
195 ->fields([ | 197 ->fields([ |
196 'revision_timestamp' => $old_revision_date, | 198 'revision_timestamp' => $old_revision_date, |
197 ]) | 199 ]) |
198 ->execute(); | 200 ->execute(); |
199 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert')); | 201 $this->drupalPostForm("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert", [], t('Revert')); |
200 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [ | 202 $this->assertRaw(t('@type %title has been reverted to the revision from %revision-date.', [ |
201 '@type' => 'Basic page', | 203 '@type' => 'Basic page', |
202 '%title' => $nodes[2]->label(), | 204 '%title' => $nodes[2]->label(), |
203 '%revision-date' => format_date($old_revision_date), | 205 '%revision-date' => $this->container->get('date.formatter')->format($old_revision_date), |
204 ])); | 206 ])); |
205 | 207 |
206 // Make a new revision and set it to not be default. | 208 // Make a new revision and set it to not be default. |
207 // This will create a new revision that is not "front facing". | 209 // This will create a new revision that is not "front facing". |
208 $new_node_revision = clone $node; | 210 $new_node_revision = clone $node; |
220 $this->drupalGet("node/" . $node->id() . "/revisions/" . $new_node_revision->getRevisionId() . "/view"); | 222 $this->drupalGet("node/" . $node->id() . "/revisions/" . $new_node_revision->getRevisionId() . "/view"); |
221 $this->assertText($new_body, 'Revision body text is present when loading specific revision.'); | 223 $this->assertText($new_body, 'Revision body text is present when loading specific revision.'); |
222 | 224 |
223 // Verify that the non-default revision vid is greater than the default | 225 // Verify that the non-default revision vid is greater than the default |
224 // revision vid. | 226 // revision vid. |
225 $default_revision = db_select('node', 'n') | 227 $default_revision = $connection->select('node', 'n') |
226 ->fields('n', ['vid']) | 228 ->fields('n', ['vid']) |
227 ->condition('nid', $node->id()) | 229 ->condition('nid', $node->id()) |
228 ->execute() | 230 ->execute() |
229 ->fetchCol(); | 231 ->fetchCol(); |
230 $default_revision_vid = $default_revision[0]; | 232 $default_revision_vid = $default_revision[0]; |
235 $node->title = 'Node title in EN'; | 237 $node->title = 'Node title in EN'; |
236 $node->revision_log = 'Simple revision message (EN)'; | 238 $node->revision_log = 'Simple revision message (EN)'; |
237 $node->save(); | 239 $node->save(); |
238 | 240 |
239 $this->drupalGet("node/" . $node->id() . "/revisions"); | 241 $this->drupalGet("node/" . $node->id() . "/revisions"); |
242 // Verify revisions is accessible since the type has revisions enabled. | |
243 $this->assertResponse(200); | |
244 // Check initial revision is shown on the node revisions overview page. | |
245 $this->assertText('Simple revision message (EN)'); | |
246 | |
247 // Verify that delete operation is inaccessible for the default revision. | |
248 $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/delete"); | |
249 $this->assertResponse(403); | |
250 | |
251 // Verify that revert operation is inaccessible for the default revision. | |
252 $this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/revert"); | |
240 $this->assertResponse(403); | 253 $this->assertResponse(403); |
241 | 254 |
242 // Create a new revision and new log message. | 255 // Create a new revision and new log message. |
243 $node = Node::load($node->id()); | 256 $node = Node::load($node->id()); |
244 $node->body->value = 'New text (EN)'; | 257 $node->body->value = 'New text (EN)'; |
257 $node->title = 'Node title in EN'; | 270 $node->title = 'Node title in EN'; |
258 $node->revision_log = 'Simple revision message (EN)'; | 271 $node->revision_log = 'Simple revision message (EN)'; |
259 $node->save(); | 272 $node->save(); |
260 | 273 |
261 $this->drupalGet("node/" . $node->id() . "/revisions"); | 274 $this->drupalGet("node/" . $node->id() . "/revisions"); |
262 $this->assertResponse(403); | 275 // Verify revisions is accessible since the type has revisions enabled. |
276 $this->assertResponse(200); | |
277 // Check initial revision is shown on the node revisions overview page. | |
278 $this->assertText('Simple revision message (EN)'); | |
263 | 279 |
264 // Add a translation in 'DE' and create a new revision and new log message. | 280 // Add a translation in 'DE' and create a new revision and new log message. |
265 $translation = $node->addTranslation('de'); | 281 $translation = $node->addTranslation('de'); |
266 $translation->title->value = 'Node title in DE'; | 282 $translation->title->value = 'Node title in DE'; |
267 $translation->body->value = 'New text (DE)'; | 283 $translation->body->value = 'New text (DE)'; |