EntityReferenceFieldCreationTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Entity/EntityReferenceFieldCreationTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Entity;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
class EntityReferenceFieldCreationTest extends BrowserTestBase {
use EntityReferenceTestTrait;
protected static $modules = [
'entity_test',
'node',
'field_ui',
];
protected $defaultTheme = 'stark';
public function testAddReferenceFieldTargetingEntityTypeWithoutId() {
$this
->drupalLogin($this->rootUser);
$node_type = $this
->drupalCreateContentType()
->id();
$this
->drupalGet("/admin/structure/types/manage/{$node_type}/fields/add-field");
$edit = [
'new_storage_type' => 'entity_reference',
'label' => 'Test Field',
'field_name' => 'test_reference_field',
];
$this
->submitForm($edit, 'Save and continue');
$this
->assertSession()
->optionNotExists('settings[target_type]', 'entity_test_no_id');
$this
->expectException('\\Drupal\\Core\\Field\\FieldException');
$this
->expectExceptionMessage('Entity type "entity_test_no_id" has no ID key and cannot be targeted by entity reference field "test_reference_field"');
$this
->createEntityReferenceField('node', $node_type, 'test_reference_field', 'Test Field', 'entity_test_no_id');
}
}