public function DevelElementInfoTest::testElementList in Devel 8
Same name and namespace in other branches
- 8.3 tests/src/Functional/DevelElementInfoTest.php \Drupal\Tests\devel\Functional\DevelElementInfoTest::testElementList()
- 8.2 tests/src/Functional/DevelElementInfoTest.php \Drupal\Tests\devel\Functional\DevelElementInfoTest::testElementList()
- 4.x tests/src/Functional/DevelElementInfoTest.php \Drupal\Tests\devel\Functional\DevelElementInfoTest::testElementList()
Tests element list page.
File
- tests/
src/ Functional/ DevelElementInfoTest.php, line 58
Class
- DevelElementInfoTest
- Tests element info pages and links.
Namespace
Drupal\Tests\devel\FunctionalCode
public function testElementList() {
$this
->drupalGet('/devel/elements');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Element Info');
$page = $this
->getSession()
->getPage();
// Ensures that the element list table is found.
$table = $page
->find('css', 'table.devel-element-list');
$this
->assertNotNull($table);
// Ensures that the expected table headers are found.
$headers = $table
->findAll('css', 'thead th');
$this
->assertEquals(4, count($headers));
$expected_headers = [
'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) elements in the table.
$expected_elements = [
'button' => [
'class' => 'Drupal\\Core\\Render\\Element\\Button',
'provider' => 'core',
],
'form' => [
'class' => 'Drupal\\Core\\Render\\Element\\Form',
'provider' => 'core',
],
'html' => [
'class' => 'Drupal\\Core\\Render\\Element\\Html',
'provider' => 'core',
],
];
foreach ($expected_elements as $element_name => $element) {
$row = $table
->find('css', sprintf('tbody tr:contains("%s")', $element_name));
$this
->assertNotNull($row);
/** @var $cells \Behat\Mink\Element\NodeElement[] */
$cells = $row
->findAll('css', 'td');
$this
->assertEquals(4, count($cells));
$cell = $cells[0];
$this
->assertEquals($element_name, $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[1];
$this
->assertEquals($element['provider'], $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[2];
$this
->assertEquals($element['class'], $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[3];
$actual_href = $cell
->findLink('Devel')
->getAttribute('href');
$expected_href = Url::fromRoute('devel.elements_page.detail', [
'element_name' => $element_name,
])
->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/elements');
$this
->assertSession()
->statusCodeEquals(403);
}