function EntityFormTest::doTestFormCRUD

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestFormCRUD()
  2. 8.9.x core/modules/system/tests/src/Functional/Entity/EntityFormTest.php \Drupal\Tests\system\Functional\Entity\EntityFormTest::doTestFormCRUD()
  3. 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 137

Class

EntityFormTest
Tests the entity form.

Namespace

Drupal\Tests\system\Functional\Entity

Code

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, "{$entity_type}: Entity found in the database.");
    $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, "{$entity_type}: The entity has been modified.");
    $entity = $this->loadEntityByName($entity_type, $name2);
    $this->assertNotNull($entity, "{$entity_type}: Modified entity found in the database.");
    $this->assertNotEquals($name1, $entity->name->value, "{$entity_type}: The entity name has been modified.");
    $this->drupalGet($entity_type . '/manage/' . $entity->id() . '/edit');
    $this->clickLink('Delete');
    $this->submitForm([], 'Delete');
    $entity = $this->loadEntityByName($entity_type, $name2);
    $this->assertNull($entity, "{$entity_type}: Entity not found in the database.");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.