View source
<?php
namespace Drupal\Tests\devel\Functional;
use Behat\Mink\Element\NodeElement;
use Drupal\Core\Url;
class DevelElementInfoTest extends DevelBrowserTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalLogin($this->develUser);
}
public function testElementInfoMenuLink() {
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalGet('');
$this
->clickLink('Element Info');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('/devel/elements');
$this
->assertSession()
->pageTextContains('Element Info');
}
public function testElementList() {
$this
->drupalGet('/devel/elements');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Element Info');
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table.devel-element-list');
$this
->assertNotNull($table);
$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);
$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);
$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);
}
$this
->drupalLogout();
$this
->drupalGet('devel/elements');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testElementDetail() {
$element_name = 'button';
$this
->drupalGet("/devel/elements/{$element_name}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Element {$element_name}");
$this
->drupalGet('/devel/elements/not_exists');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalLogout();
$this
->drupalGet("/devel/elements/{$element_name}");
$this
->assertSession()
->statusCodeEquals(403);
}
}