3 namespace Drupal\Tests\comment\Kernel;
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\field\Entity\FieldStorageConfig;
10 * Tests that comment fields cannot be added to entities with non-integer IDs.
14 class CommentStringIdEntitiesTest extends KernelTestBase {
21 public static $modules = [
30 protected function setUp() {
32 $this->installEntitySchema('comment');
33 $this->installSchema('comment', ['comment_entity_statistics']);
34 // Create the comment body field storage.
35 $this->installConfig(['field']);
39 * Tests that comment fields cannot be added entities with non-integer IDs.
41 public function testCommentFieldNonStringId() {
43 $bundle = CommentType::create([
47 'target_entity_type_id' => 'entity_test_string_id',
50 $field_storage = FieldStorageConfig::create([
51 'field_name' => 'foo',
52 'entity_type' => 'entity_test_string_id',
54 'comment_type' => 'entity_test_string_id',
58 $field_storage->save();
59 $this->fail('Did not throw an exception as expected.');
61 catch (\UnexpectedValueException $e) {
62 $this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');