function EntityFormTest::doTestFormCRUD
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestFormCRUD()
- 10 core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestFormCRUD()
- 11.x core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestFormCRUD()
Executes the form CRUD tests for the given entity type.
Parameters
string $entity_type: The entity type to run the tests with.
1 call to EntityFormTest::doTestFormCRUD()
- EntityFormTest::testFormCRUD in core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityFormTest.php - Tests basic form CRUD functionality.
File
-
core/
modules/ system/ tests/ src/ Functional/ Entity/ EntityFormTest.php, line 118
Class
- EntityFormTest
- Tests the entity form.
Namespace
Drupal\Tests\system\Functional\EntityCode
protected function doTestFormCRUD($entity_type) {
$name1 = $this->randomMachineName(8);
$name2 = $this->randomMachineName(10);
$edit = [
'name[0][value]' => $name1,
'field_test_text[0][value]' => $this->randomMachineName(16),
];
$this->drupalGet($entity_type . '/add');
$this->submitForm($edit, 'Save');
$entity = $this->loadEntityByName($entity_type, $name1);
$this->assertNotNull($entity, new FormattableMarkup('%entity_type: Entity found in the database.', [
'%entity_type' => $entity_type,
]));
$edit['name[0][value]'] = $name2;
$this->drupalGet($entity_type . '/manage/' . $entity->id() . '/edit');
$this->submitForm($edit, 'Save');
$entity = $this->loadEntityByName($entity_type, $name1);
$this->assertNull($entity, new FormattableMarkup('%entity_type: The entity has been modified.', [
'%entity_type' => $entity_type,
]));
$entity = $this->loadEntityByName($entity_type, $name2);
$this->assertNotNull($entity, new FormattableMarkup('%entity_type: Modified entity found in the database.', [
'%entity_type' => $entity_type,
]));
$this->assertNotEquals($name1, $entity->name->value, new FormattableMarkup('%entity_type: The entity name has been modified.', [
'%entity_type' => $entity_type,
]));
$this->drupalGet($entity_type . '/manage/' . $entity->id() . '/edit');
$this->clickLink('Delete');
$this->submitForm([], 'Delete');
$entity = $this->loadEntityByName($entity_type, $name2);
$this->assertNull($entity, new FormattableMarkup('%entity_type: Entity not found in the database.', [
'%entity_type' => $entity_type,
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.