3db9c4a67b39aa1b955310bbca04e5e6f38bce7d
[yaffs-website] / web / core / modules / comment / src / Tests / Update / CommentUpdateTest.php
1 <?php
2
3 namespace Drupal\comment\Tests\Update;
4
5 use Drupal\system\Tests\Update\UpdatePathTestBase;
6
7 /**
8  * Tests that comment settings are properly updated during database updates.
9  *
10  * @group comment
11  */
12 class CommentUpdateTest extends UpdatePathTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function setDatabaseDumpFiles() {
18     $this->databaseDumpFiles = [
19       __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.filled.standard.php.gz',
20     ];
21   }
22
23   /**
24    * Tests comment_update_8200().
25    *
26    * @see comment_update_8200()
27    */
28   public function testCommentUpdate8101() {
29     // Load the 'node.article.default' entity view display config, and check
30     // that component 'comment' does not contain the 'view_mode' setting.
31     $config = $this->config('core.entity_view_display.node.article.default');
32     $this->assertNull($config->get('content.comment.settings.view_mode'));
33
34     // Load the 'node.forum.default' entity view display config, and check that
35     // component 'comment_forum' does not contain the 'view_mode' setting.
36     $config = $this->config('core.entity_view_display.node.forum.default');
37     $this->assertNull($config->get('content.comment_forum.settings.view_mode'));
38
39     // Run updates.
40     $this->runUpdates();
41
42     // Check that 'node.article.default' entity view display setting 'view_mode'
43     // has the value 'default'.
44     $config = $this->config('core.entity_view_display.node.article.default');
45     $this->assertIdentical($config->get('content.comment.settings.view_mode'), 'default');
46
47     // Check that 'node.forum.default' entity view display setting 'view_mode'
48     // has the value 'default'.
49     $config = $this->config('core.entity_view_display.node.forum.default');
50     $this->assertIdentical($config->get('content.comment_forum.settings.view_mode'), 'default');
51   }
52
53   /**
54    * Tests that the comment entity type has a 'published' entity key.
55    *
56    * @see comment_update_8301()
57    */
58   public function testPublishedEntityKey() {
59     // Check that the 'published' entity key does not exist prior to the update.
60     $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
61     $this->assertFalse($entity_type->getKey('published'));
62
63     // Run updates.
64     $this->runUpdates();
65
66     // Check that the entity key exists and it has the correct value.
67     $entity_type = \Drupal::entityDefinitionUpdateManager()->getEntityType('comment');
68     $this->assertEqual('status', $entity_type->getKey('published'));
69
70     // Check that the {comment_field_data} table status index has been created.
71     $this->assertTrue(\Drupal::database()->schema()->indexExists('comment_field_data', 'comment__status_comment_type'));
72   }
73
74 }