You are here

public function DevelEntityTypeInfoTest::testEntityTypeList in Devel 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/DevelEntityTypeInfoTest.php \Drupal\Tests\devel\Functional\DevelEntityTypeInfoTest::testEntityTypeList()
  2. 8.2 tests/src/Functional/DevelEntityTypeInfoTest.php \Drupal\Tests\devel\Functional\DevelEntityTypeInfoTest::testEntityTypeList()
  3. 4.x tests/src/Functional/DevelEntityTypeInfoTest.php \Drupal\Tests\devel\Functional\DevelEntityTypeInfoTest::testEntityTypeList()

Tests entity type list page.

File

tests/src/Functional/DevelEntityTypeInfoTest.php, line 42

Class

DevelEntityTypeInfoTest
Tests entity type info pages and links.

Namespace

Drupal\Tests\devel\Functional

Code

public function testEntityTypeList() {
  $this
    ->drupalGet('/devel/entity/info');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Entity Info');
  $page = $this
    ->getSession()
    ->getPage();

  // Ensures that the entity type list table is found.
  $table = $page
    ->find('css', 'table.devel-entity-type-list');
  $this
    ->assertNotNull($table);

  // Ensures that the expected table headers are found.
  $headers = $table
    ->findAll('css', 'thead th');
  $this
    ->assertEquals(5, count($headers));
  $expected_headers = [
    'ID',
    'Name',
    'Provider',
    'Class',
    'Operations',
  ];
  $actual_headers = array_map(function (NodeElement $element) {
    return $element
      ->getText();
  }, $headers);
  $this
    ->assertSame($expected_headers, $actual_headers);

  // Tests the presence of some (arbitrarily chosen) entity types in the
  // table.
  $expected_types = [
    'date_format' => [
      'name' => 'Date format',
      'class' => 'Drupal\\Core\\Datetime\\Entity\\DateFormat',
      'provider' => 'core',
    ],
    'block' => [
      'name' => 'Block',
      'class' => 'Drupal\\block\\Entity\\Block',
      'provider' => 'block',
    ],
    'entity_view_mode' => [
      'name' => 'View mode',
      'class' => 'Drupal\\Core\\Entity\\Entity\\EntityViewMode',
      'provider' => 'core',
    ],
  ];
  foreach ($expected_types as $entity_type_id => $entity_type) {
    $row = $table
      ->find('css', sprintf('tbody tr:contains("%s")', $entity_type_id));
    $this
      ->assertNotNull($row);

    /* @var $cells \Behat\Mink\Element\NodeElement[] */
    $cells = $row
      ->findAll('css', 'td');
    $this
      ->assertEquals(5, count($cells));
    $cell = $cells[0];
    $this
      ->assertEquals($entity_type_id, $cell
      ->getText());
    $this
      ->assertTrue($cell
      ->hasClass('table-filter-text-source'));
    $cell = $cells[1];
    $this
      ->assertEquals($entity_type['name'], $cell
      ->getText());
    $this
      ->assertTrue($cell
      ->hasClass('table-filter-text-source'));
    $cell = $cells[2];
    $this
      ->assertEquals($entity_type['provider'], $cell
      ->getText());
    $this
      ->assertTrue($cell
      ->hasClass('table-filter-text-source'));
    $cell = $cells[3];
    $this
      ->assertEquals($entity_type['class'], $cell
      ->getText());
    $this
      ->assertTrue($cell
      ->hasClass('table-filter-text-source'));
    $cell = $cells[4];
    $actual_href = $cell
      ->findLink('Devel')
      ->getAttribute('href');
    $expected_href = Url::fromRoute('devel.entity_info_page.detail', [
      'entity_type_id' => $entity_type_id,
    ])
      ->toString();
    $this
      ->assertEquals($expected_href, $actual_href);
    $actual_href = $cell
      ->findLink('Fields')
      ->getAttribute('href');
    $expected_href = Url::fromRoute('devel.entity_info_page.fields', [
      'entity_type_id' => $entity_type_id,
    ])
      ->toString();
    $this
      ->assertEquals($expected_href, $actual_href);
  }

  // Ensures that the page is accessible only to the users with the adequate
  // permissions.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('devel/entity/info');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}