Namespace
Drupal\Tests\config_entity_example\Functional
File
-
modules/config_entity_example/tests/src/Functional/RobotReferenceTest.php
View source
<?php
namespace Drupal\Tests\config_entity_example\Functional;
use Drupal\config_entity_example\Entity\Robot;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class RobotReferenceTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'config_entity_example',
'node',
'field_ui',
];
protected $profile = 'minimal';
public function testEntityReference() {
$assert = $this->assertSession();
$type = $this->createContentType();
$this->drupalLogin($this->createUser([
'create ' . $type->id() . ' content',
'administer node fields',
]));
$this->drupalGet('admin/structure/types/manage/' . $type->id() . '/fields');
$assert->statusCodeEquals(200);
$this->clickLink('Add field');
$this->submitForm([
'new_storage_type' => 'entity_reference',
'field_name' => 'robot_reference',
'label' => 'robot_reference',
], 'Save and continue');
$assert->statusCodeEquals(200);
$this->submitForm([
'settings[target_type]' => 'robot',
], 'Save field settings');
$assert->statusCodeEquals(200);
$robot = Robot::loadMultiple();
$robot = reset($robot);
$this->drupalGet(Url::fromRoute('node.add', [
'node_type' => $type->id(),
]));
$this->submitForm([
'title[0][value]' => 'title',
'field_robot_reference[0][target_id]' => $robot->label(),
], 'Save');
$assert->statusCodeEquals(200);
$assert->pageTextContains($robot->label());
}
}
Classes
| Title |
Deprecated |
Summary |
| RobotReferenceTest |
|
Ensure Robot entities can be used in entity_reference fields. |