Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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 } |