public function ContentEntityExampleTest::testAddFields in Examples for Developers 3.x
Same name and namespace in other branches
- 8 content_entity_example/tests/src/Functional/ContentEntityExampleTest.php \Drupal\Tests\content_entity_example\Functional\ContentEntityExampleTest::testAddFields()
Test add new fields to the contact entity.
File
- modules/
content_entity_example/ tests/ src/ Functional/ ContentEntityExampleTest.php, line 229
Class
- ContentEntityExampleTest
- Tests the basic functions of the Content Entity Example module.
Namespace
Drupal\Tests\content_entity_example\FunctionalCode
public function testAddFields() {
$web_user = $this
->drupalCreateUser([
'administer contact entity',
'administer content_entity_example_contact display',
'administer content_entity_example_contact fields',
'administer content_entity_example_contact form display',
]);
$this
->drupalLogin($web_user);
$entity_name = 'content_entity_example_contact';
$add_field_url = 'admin/structure/' . $entity_name . '_settings/fields/add-field';
$this
->drupalGet($add_field_url);
$field_name = 'test_name';
$edit = [
'new_storage_type' => 'list_string',
'label' => 'test name',
'field_name' => $field_name,
];
$this
->drupalPostForm(NULL, $edit, 'Save and continue');
$expected_path = $this
->buildUrl('admin/structure/' . $entity_name . '_settings/fields/' . $entity_name . '.' . $entity_name . '.field_' . $field_name . '/storage');
// Fetch url without query parameters.
$current_path = strtok($this
->getUrl(), '?');
$this
->assertEquals($expected_path, $current_path);
}