3 namespace Drupal\Tests\devel\Functional;
5 use Behat\Mink\Element\NodeElement;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests element info pages and links.
14 class DevelElementInfoTest extends BrowserTestBase {
19 public static $modules = ['devel', 'block'];
22 * The user for the test.
24 * @var \Drupal\user\UserInterface
31 protected function setUp() {
34 $this->drupalPlaceBlock('system_menu_block:devel');
35 $this->drupalPlaceBlock('page_title_block');
37 $this->develUser = $this->drupalCreateUser(['access devel information']);
38 $this->drupalLogin($this->develUser);
42 * Tests element info menu link.
44 public function testElementInfoMenuLink() {
45 $this->drupalPlaceBlock('system_menu_block:devel');
46 // Ensures that the element info link is present on the devel menu and that
47 // it points to the correct page.
49 $this->clickLink('Element Info');
50 $this->assertSession()->statusCodeEquals(200);
51 $this->assertSession()->addressEquals('/devel/elements');
52 $this->assertSession()->pageTextContains('Element Info');
56 * Tests element list page.
58 public function testElementList() {
59 $this->drupalGet('/devel/elements');
60 $this->assertSession()->statusCodeEquals(200);
61 $this->assertSession()->pageTextContains('Element Info');
63 $page = $this->getSession()->getPage();
65 // Ensures that the element list table is found.
66 $table = $page->find('css', 'table.devel-element-list');
67 $this->assertNotNull($table);
69 // Ensures that the expected table headers are found.
70 $headers = $table->findAll('css', 'thead th');
71 $this->assertEquals(4, count($headers));
73 $expected_headers = ['Name', 'Provider', 'Class', 'Operations'];
74 $actual_headers = array_map(function (NodeElement $element) {
75 return $element->getText();
77 $this->assertSame($expected_headers, $actual_headers);
79 // Tests the presence of some (arbitrarily chosen) elements in the table.
80 $expected_elements = [
82 'class' => 'Drupal\Core\Render\Element\Button',
86 'class' => 'Drupal\Core\Render\Element\Form',
90 'class' => 'Drupal\Core\Render\Element\Html',
95 foreach ($expected_elements as $element_name => $element) {
96 $row = $table->find('css', sprintf('tbody tr:contains("%s")', $element_name));
97 $this->assertNotNull($row);
99 /** @var $cells \Behat\Mink\Element\NodeElement[] */
100 $cells = $row->findAll('css', 'td');
101 $this->assertEquals(4, count($cells));
104 $this->assertEquals($element_name, $cell->getText());
105 $this->assertTrue($cell->hasClass('table-filter-text-source'));
108 $this->assertEquals($element['provider'], $cell->getText());
109 $this->assertTrue($cell->hasClass('table-filter-text-source'));
112 $this->assertEquals($element['class'], $cell->getText());
113 $this->assertTrue($cell->hasClass('table-filter-text-source'));
116 $actual_href = $cell->findLink('Devel')->getAttribute('href');
117 $expected_href = Url::fromRoute('devel.elements_page.detail', ['element_name' => $element_name])->toString();
118 $this->assertEquals($expected_href, $actual_href);
121 // Ensures that the page is accessible only to the users with the adequate
123 $this->drupalLogout();
124 $this->drupalGet('devel/elements');
125 $this->assertSession()->statusCodeEquals(403);
129 * Tests element detail page.
131 public function testElementDetail() {
132 $element_name = 'button';
134 // Ensures that the page works as expected.
135 $this->drupalGet("/devel/elements/$element_name");
136 $this->assertSession()->statusCodeEquals(200);
137 $this->assertSession()->pageTextContains("Element $element_name");
139 // Ensures that the page returns a 404 error if the requested element is
141 $this->drupalGet('/devel/elements/not_exists');
142 $this->assertSession()->statusCodeEquals(404);
144 // Ensures that the page is accessible ony to users with the adequate
146 $this->drupalLogout();
147 $this->drupalGet("/devel/elements/$element_name");
148 $this->assertSession()->statusCodeEquals(403);