protected function EntityFormTest::assertFormCRUD

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::assertFormCRUD()
EntityFormTest::testFormCRUD in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php
Tests basic form CRUD functionality.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php, line 66
Definition of Drupal\system\Tests\Entity\EntityFormTest.

Class

EntityFormTest
Tests the Entity Form Controller.

Namespace

Drupal\system\Tests\Entity

Code

protected function assertFormCRUD($entity_type) {
  $langcode = Language::LANGCODE_NOT_SPECIFIED;
  $name1 = $this
    ->randomName(8);
  $name2 = $this
    ->randomName(10);
  $edit = array(
    'name' => $name1,
    'user_id' => mt_rand(0, 128),
    "field_test_text[{$langcode}][0][value]" => $this
      ->randomName(16),
  );
  $this
    ->drupalPost($entity_type . '/add', $edit, t('Save'));
  $entity = $this
    ->loadEntityByName($entity_type, $name1);
  $this
    ->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array(
    '%entity_type' => $entity_type,
  )));
  $edit['name'] = $name2;
  $this
    ->drupalPost($entity_type . '/manage/' . $entity
    ->id() . '/edit', $edit, t('Save'));
  $entity = $this
    ->loadEntityByName($entity_type, $name1);
  $this
    ->assertFalse($entity, format_string('%entity_type: The entity has been modified.', array(
    '%entity_type' => $entity_type,
  )));
  $entity = $this
    ->loadEntityByName($entity_type, $name2);
  $this
    ->assertTrue($entity, format_string('%entity_type: Modified entity found in the database.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->assertNotEqual($entity->name->value, $name1, format_string('%entity_type: The entity name has been modified.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->drupalPost($entity_type . '/manage/' . $entity
    ->id() . '/edit', array(), t('Delete'));
  $entity = $this
    ->loadEntityByName($entity_type, $name2);
  $this
    ->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', array(
    '%entity_type' => $entity_type,
  )));
}