3 namespace Drupal\Tests\devel\Functional;
5 use Behat\Mink\Element\NodeElement;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests entity type info pages and links.
14 class DevelEntityTypeInfoTest 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 entity info menu link.
44 public function testEntityInfoMenuLink() {
45 $this->drupalPlaceBlock('system_menu_block:devel');
46 // Ensures that the entity type info link is present on the devel menu and that
47 // it points to the correct page.
49 $this->clickLink('Entity Info');
50 $this->assertSession()->statusCodeEquals(200);
51 $this->assertSession()->addressEquals('/devel/entity/info');
52 $this->assertSession()->pageTextContains('Entity Info');
56 * Tests entity type list page.
58 public function testEntityTypeList() {
59 $this->drupalGet('/devel/entity/info');
60 $this->assertSession()->statusCodeEquals(200);
61 $this->assertSession()->pageTextContains('Entity Info');
63 $page = $this->getSession()->getPage();
65 // Ensures that the entity type list table is found.
66 $table = $page->find('css', 'table.devel-entity-type-list');
67 $this->assertNotNull($table);
69 // Ensures that the expected table headers are found.
70 $headers = $table->findAll('css', 'thead th');
71 $this->assertEquals(5, count($headers));
73 $expected_headers = ['ID', '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) entity types in the table.
82 'name' => 'Date format',
83 'class' => 'Drupal\Core\Datetime\Entity\DateFormat',
88 'class' => 'Drupal\block\Entity\Block',
89 'provider' => 'block',
91 'entity_view_mode' => [
92 'name' => 'View mode',
93 'class' => 'Drupal\Core\Entity\Entity\EntityViewMode',
98 foreach ($expected_types as $entity_type_id => $entity_type) {
99 $row = $table->find('css', sprintf('tbody tr:contains("%s")', $entity_type_id));
100 $this->assertNotNull($row);
102 /** @var $cells \Behat\Mink\Element\NodeElement[] */
103 $cells = $row->findAll('css', 'td');
104 $this->assertEquals(5, count($cells));
107 $this->assertEquals($entity_type_id, $cell->getText());
108 $this->assertTrue($cell->hasClass('table-filter-text-source'));
111 $this->assertEquals($entity_type['name'], $cell->getText());
112 $this->assertTrue($cell->hasClass('table-filter-text-source'));
115 $this->assertEquals($entity_type['provider'], $cell->getText());
116 $this->assertTrue($cell->hasClass('table-filter-text-source'));
119 $this->assertEquals($entity_type['class'], $cell->getText());
120 $this->assertTrue($cell->hasClass('table-filter-text-source'));
123 $actual_href = $cell->findLink('Devel')->getAttribute('href');
124 $expected_href = Url::fromRoute('devel.entity_info_page.detail', ['entity_type_id' => $entity_type_id])->toString();
125 $this->assertEquals($expected_href, $actual_href);
128 // Ensures that the page is accessible only to the users with the adequate
130 $this->drupalLogout();
131 $this->drupalGet('devel/entity/info');
132 $this->assertSession()->statusCodeEquals(403);
136 * Tests entity type detail page.
138 public function testEntityTypeDetail() {
139 $entity_type_id = 'date_format';
141 // Ensures that the page works as expected.
142 $this->drupalGet("/devel/entity/info/$entity_type_id");
143 $this->assertSession()->statusCodeEquals(200);
144 $this->assertSession()->pageTextContains("Entity type $entity_type_id");
146 // Ensures that the page returns a 404 error if the requested entity type is
148 $this->drupalGet('/devel/entity/info/not_exists');
149 $this->assertSession()->statusCodeEquals(404);
151 // Ensures that the page is accessible ony to users with the adequate
153 $this->drupalLogout();
154 $this->drupalGet("/devel/entity/info/$entity_type_id");
155 $this->assertSession()->statusCodeEquals(403);