Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / comment / tests / src / Kernel / CommentStringIdEntitiesTest.php
1 <?php
2
3 namespace Drupal\Tests\comment\Kernel;
4
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\field\Entity\FieldStorageConfig;
8
9 /**
10  * Tests that comment fields cannot be added to entities with non-integer IDs.
11  *
12  * @group comment
13  */
14 class CommentStringIdEntitiesTest extends KernelTestBase {
15
16   /**
17    * Modules to install.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'comment',
23     'user',
24     'field',
25     'field_ui',
26     'entity_test',
27     'text',
28   ];
29
30   protected function setUp() {
31     parent::setUp();
32     $this->installEntitySchema('comment');
33     $this->installSchema('comment', ['comment_entity_statistics']);
34     // Create the comment body field storage.
35     $this->installConfig(['field']);
36   }
37
38   /**
39    * Tests that comment fields cannot be added entities with non-integer IDs.
40    */
41   public function testCommentFieldNonStringId() {
42     try {
43       $bundle = CommentType::create([
44         'id' => 'foo',
45         'label' => 'foo',
46         'description' => '',
47         'target_entity_type_id' => 'entity_test_string_id',
48       ]);
49       $bundle->save();
50       $field_storage = FieldStorageConfig::create([
51         'field_name' => 'foo',
52         'entity_type' => 'entity_test_string_id',
53         'settings' => [
54           'comment_type' => 'entity_test_string_id',
55         ],
56         'type' => 'comment',
57       ]);
58       $field_storage->save();
59       $this->fail('Did not throw an exception as expected.');
60     }
61     catch (\UnexpectedValueException $e) {
62       $this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
63     }
64   }
65
66 }