function ConfigEntityTest::testCRUDUI

Tests CRUD operations through the UI.

File

drupal/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php, line 183
Definition of Drupal\config\Tests\ConfigEntityTest.

Class

ConfigEntityTest
Tests configuration entities.

Namespace

Drupal\config\Tests

Code

function testCRUDUI() {
  $id = strtolower($this
    ->randomName());
  $label1 = $this
    ->randomName();
  $label2 = $this
    ->randomName();
  $label3 = $this
    ->randomName();
  $message_insert = format_string('%label configuration has been created.', array(
    '%label' => $label1,
  ));
  $message_update = format_string('%label configuration has been updated.', array(
    '%label' => $label2,
  ));
  $message_delete = format_string('%label configuration has been deleted.', array(
    '%label' => $label2,
  ));

  // Create a configuration entity.
  $edit = array(
    'id' => $id,
    'label' => $label1,
  );
  $this
    ->drupalPost('admin/structure/config_test/add', $edit, 'Save');
  $this
    ->assertUrl('admin/structure/config_test');
  $this
    ->assertResponse(200);
  $this
    ->assertRaw($message_insert);
  $this
    ->assertNoRaw($message_update);
  $this
    ->assertLinkByHref("admin/structure/config_test/manage/{$id}/edit");

  // Update the configuration entity.
  $edit = array(
    'label' => $label2,
  );
  $this
    ->drupalPost("admin/structure/config_test/manage/{$id}", $edit, 'Save');
  $this
    ->assertUrl('admin/structure/config_test');
  $this
    ->assertResponse(200);
  $this
    ->assertNoRaw($message_insert);
  $this
    ->assertRaw($message_update);
  $this
    ->assertLinkByHref("admin/structure/config_test/manage/{$id}/edit");
  $this
    ->assertLinkByHref("admin/structure/config_test/manage/{$id}/delete");

  // Delete the configuration entity.
  $this
    ->drupalGet("admin/structure/config_test/manage/{$id}/edit");
  $this
    ->drupalPost(NULL, array(), 'Delete');
  $this
    ->assertUrl("admin/structure/config_test/manage/{$id}/delete");
  $this
    ->drupalPost(NULL, array(), 'Delete');
  $this
    ->assertUrl('admin/structure/config_test');
  $this
    ->assertResponse(200);
  $this
    ->assertNoRaw($message_update);
  $this
    ->assertRaw($message_delete);
  $this
    ->assertNoText($label1);
  $this
    ->assertNoLinkByHref("admin/structure/config_test/manage/{$id}");
  $this
    ->assertNoLinkByHref("admin/structure/config_test/manage/{$id}/edit");

  // Re-create a configuration entity.
  $edit = array(
    'id' => $id,
    'label' => $label1,
  );
  $this
    ->drupalPost('admin/structure/config_test/add', $edit, 'Save');
  $this
    ->assertUrl('admin/structure/config_test');
  $this
    ->assertResponse(200);
  $this
    ->assertText($label1);
  $this
    ->assertLinkByHref("admin/structure/config_test/manage/{$id}/edit");

  // Rename the configuration entity's ID/machine name.
  $edit = array(
    'id' => strtolower($this
      ->randomName()),
    'label' => $label3,
  );
  $this
    ->drupalPost("admin/structure/config_test/manage/{$id}", $edit, 'Save');
  $this
    ->assertUrl('admin/structure/config_test');
  $this
    ->assertResponse(200);
  $this
    ->assertNoText($label1);
  $this
    ->assertNoText($label2);
  $this
    ->assertText($label3);
  $this
    ->assertNoLinkByHref("admin/structure/config_test/manage/{$id}");
  $this
    ->assertNoLinkByHref("admin/structure/config_test/manage/{$id}/edit");
  $id = $edit['id'];
  $this
    ->assertLinkByHref("admin/structure/config_test/manage/{$id}/edit");

  // Create a configuration entity with '0' machine name.
  $edit = array(
    'id' => '0',
    'label' => '0',
  );
  $this
    ->drupalPost('admin/structure/config_test/add', $edit, 'Save');
  $this
    ->assertResponse(200);
  $message_insert = format_string('%label configuration has been created.', array(
    '%label' => $edit['label'],
  ));
  $this
    ->assertRaw($message_insert);
  $this
    ->assertLinkByHref('admin/structure/config_test/manage/0/edit');
  $this
    ->assertLinkByHref('admin/structure/config_test/manage/0/delete');
  $this
    ->drupalPost('admin/structure/config_test/manage/0/delete', array(), 'Delete');
  $this
    ->assertFalse(entity_load('config_test', '0'), 'Test entity deleted');
}