diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index f7bfd80..52f7bc6 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -9,6 +9,7 @@ namespace Drupal\config\Tests; use Drupal\simpletest\WebTestBase; use Drupal\config_test\ConfigTest; +use Drupal\Core\Entity\EntityStorageControllerInterface; /** * Tests the listing of configuration entities. @@ -31,30 +32,105 @@ class ConfigEntityListTest extends WebTestBase { } /** - * Tests that the entity list controller loads a valid list of entities. + * Tests entity list controller methods. */ 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.'); - $this->assertTrue(!empty($list['default']), '"Default" ConfigTest entity ID found.'); - $this->assertTrue($list['default'] instanceof ConfigTest, '"Default" ConfigTest entity is an instance of ConfigTest.'); + $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 getPath() method. + $this->assertIdentical($controller->getPath(), 'admin/structure/config_test', 'Return value from getPath is correct.'); + + // 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' => render($build_operations), + ); + $actual_items = $controller->buildRow($entity); + $this->assertIdentical($expected_items, $actual_items, 'Return value from buildRow matches expected.'); } /** * Tests the listing UI. */ function testListUI() { + // Get the list callback page. $page = $this->drupalGet('admin/structure/config_test'); - $this->assertText('Test configuration'); - // Verify that the default ConfigTest configuration appears. - $this->assertText('default'); - $this->assertText('Default'); + // Test for the page title. + $element = $this->xpath('//h1[@id="page-title"]'); + $this->assertEqual((string) $element[0], 'Test configuration', 'Page title found.'); + + // Test for the table. + $element = $this->xpath('//div[@id="content"]/table'); + $this->assertTrue($element, 'Configuration entity list table found.'); + + // Test the table header. + $elements = $this->xpath('//div[@id="content"]/table/thead/tr/th'); + $this->assertEqual(count($elements), 3, 'Correct number of table header cells found.'); + + // Test the contents of each th cell. + $expected_items = array('Label', 'Machine name', 'Operations'); + foreach ($elements as $key => $element) { + $this->assertIdentical((string) $element[0], $expected_items[$key]); + } + + // Check the number of table row cells. + $elements = $this->xpath('//div[@id="content"]/table/tbody/tr[@class="odd"]/td'); + $this->assertEqual(count($elements), 3, 'Correct number of table row cells found.'); + + // Check the contents of each row cell. + $this->assertIdentical((string) $elements[0], 'Default'); + $this->assertIdentical((string) $elements[1], 'default'); + $this->assertTrue($elements[2]->children()->xpath('//ul'), 'Operations list found.'); + + // Verify the 'Add' action link is present. + $this->assertLink('Add test configuration'); + $this->clickLink('Add test configuration'); + $this->assertResponse(200); + + $this->drupalSetContent($page); // Verify that the expected operation links work. foreach (array('Edit', 'Delete') as $link) {