annotate core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
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@18 33 $this->installEntitySchema('entity_test_string_id');
Chris@0 34 $this->installSchema('comment', ['comment_entity_statistics']);
Chris@0 35 // Create the comment body field storage.
Chris@0 36 $this->installConfig(['field']);
Chris@0 37 }
Chris@0 38
Chris@0 39 /**
Chris@0 40 * Tests that comment fields cannot be added entities with non-integer IDs.
Chris@0 41 */
Chris@0 42 public function testCommentFieldNonStringId() {
Chris@0 43 try {
Chris@0 44 $bundle = CommentType::create([
Chris@0 45 'id' => 'foo',
Chris@0 46 'label' => 'foo',
Chris@0 47 'description' => '',
Chris@0 48 'target_entity_type_id' => 'entity_test_string_id',
Chris@0 49 ]);
Chris@0 50 $bundle->save();
Chris@0 51 $field_storage = FieldStorageConfig::create([
Chris@0 52 'field_name' => 'foo',
Chris@0 53 'entity_type' => 'entity_test_string_id',
Chris@0 54 'settings' => [
Chris@0 55 'comment_type' => 'entity_test_string_id',
Chris@0 56 ],
Chris@0 57 'type' => 'comment',
Chris@0 58 ]);
Chris@0 59 $field_storage->save();
Chris@0 60 $this->fail('Did not throw an exception as expected.');
Chris@0 61 }
Chris@0 62 catch (\UnexpectedValueException $e) {
Chris@0 63 $this->pass('Exception thrown when trying to create comment field on Entity Type with string ID.');
Chris@0 64 }
Chris@0 65 }
Chris@0 66
Chris@0 67 }