annotate core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php @ 4:a9cd425dd02b

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