You are here

protected function EntityFormTest::doTestFormCRUD in Drupal 8

Same name and namespace in other branches
  1. 9 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 77

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
    ->drupalPostForm($entity_type . '/add', $edit, t('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
    ->drupalPostForm($entity_type . '/manage/' . $entity
    ->id() . '/edit', $edit, t('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
    ->assertNotEqual($entity->name->value, $name1, new FormattableMarkup('%entity_type: The entity name has been modified.', [
    '%entity_type' => $entity_type,
  ]));
  $this
    ->drupalGet($entity_type . '/manage/' . $entity
    ->id() . '/edit');
  $this
    ->clickLink(t('Delete'));
  $this
    ->drupalPostForm(NULL, [], t('Delete'));
  $entity = $this
    ->loadEntityByName($entity_type, $name2);
  $this
    ->assertNull($entity, new FormattableMarkup('%entity_type: Entity not found in the database.', [
    '%entity_type' => $entity_type,
  ]));
}