function ConfigEntityListTest::testList

Tests entity list controller methods.

File

drupal/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php, line 37
Definition of Drupal\config\Tests\ConfigEntityListTest.

Class

ConfigEntityListTest
Tests the listing of configuration entities.

Namespace

Drupal\config\Tests

Code

function testList() {
  $controller = entity_list_controller('config_test');

  // Test getStorageController() method.
  $this
    ->assertTrue($controller
    ->getStorageController() instanceof EntityStorageControllerInterface, 'EntityStorageController instance in storage.');

  // Get a list of ConfigTest entities and confirm that it contains the
  // ConfigTest entity provided by the config_test module.
  // @see config_test.dynamic.default.yml
  $list = $controller
    ->load();
  $this
    ->assertEqual(count($list), 1, '1 ConfigTest entity found.');
  $entity = $list['default'];
  $this
    ->assertTrue(!empty($entity), '"Default" ConfigTest entity ID found.');
  $this
    ->assertTrue($entity instanceof ConfigTest, '"Default" ConfigTest entity is an instance of ConfigTest.');

  // Test getOperations() method.
  $uri = $entity
    ->uri();
  $expected_operations = array(
    'edit' => array(
      'title' => 'Edit',
      'href' => 'admin/structure/config_test/manage/default/edit',
      'options' => $uri['options'],
      'weight' => 10,
    ),
    'delete' => array(
      'title' => 'Delete',
      'href' => 'admin/structure/config_test/manage/default/delete',
      'options' => $uri['options'],
      'weight' => 100,
    ),
  );
  $actual_operations = $controller
    ->getOperations($entity);
  $this
    ->assertIdentical($expected_operations, $actual_operations, 'Return value from getOperations matches expected.');

  // Test buildHeader() method.
  $expected_items = array(
    'label' => 'Label',
    'id' => 'Machine name',
    'operations' => 'Operations',
  );
  $actual_items = $controller
    ->buildHeader();
  $this
    ->assertIdentical($expected_items, $actual_items, 'Return value from buildHeader matches expected.');

  // Test buildRow() method.
  $build_operations = $controller
    ->buildOperations($entity);
  $expected_items = array(
    'label' => 'Default',
    'id' => 'default',
    'operations' => array(
      'data' => $build_operations,
    ),
  );
  $actual_items = $controller
    ->buildRow($entity);
  $this
    ->assertIdentical($expected_items, $actual_items, 'Return value from buildRow matches expected.');
}