function CommentStringIdEntitiesTest::testCommentFieldNonStringId

Same name in other branches
  1. 9 core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php \Drupal\Tests\comment\Kernel\CommentStringIdEntitiesTest::testCommentFieldNonStringId()
  2. 8.9.x core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php \Drupal\Tests\comment\Kernel\CommentStringIdEntitiesTest::testCommentFieldNonStringId()
  3. 11.x core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php \Drupal\Tests\comment\Kernel\CommentStringIdEntitiesTest::testCommentFieldNonStringId()

Tests that comment fields cannot be added entities with non-integer IDs.

File

core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php, line 45

Class

CommentStringIdEntitiesTest
Tests that comment fields cannot be added to entities with non-integer IDs.

Namespace

Drupal\Tests\comment\Kernel

Code

public function testCommentFieldNonStringId() : void {
    $this->expectException(\UnexpectedValueException::class);
    $bundle = CommentType::create([
        'id' => 'foo',
        'label' => 'foo',
        'description' => '',
        'target_entity_type_id' => 'entity_test_string_id',
    ]);
    $bundle->save();
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'foo',
        'entity_type' => 'entity_test_string_id',
        'settings' => [
            'comment_type' => 'entity_test_string_id',
        ],
        'type' => 'comment',
    ]);
    $field_storage->save();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.