3 namespace Drupal\Tests\devel\Functional;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests container info pages and links.
13 class DevelContainerInfoTest extends BrowserTestBase {
15 use DevelWebAssertHelper;
20 public static $modules = ['devel', 'devel_test', 'block'];
25 * @var \Drupal\user\UserInterface
32 protected function setUp() {
35 $this->drupalPlaceBlock('local_tasks_block');
36 $this->drupalPlaceBlock('page_title_block');
38 $this->develUser = $this->drupalCreateUser(['access devel information']);
39 $this->drupalLogin($this->develUser);
43 * Tests container info menu link.
45 public function testContainerInfoMenuLink() {
46 $this->drupalPlaceBlock('system_menu_block:devel');
47 // Ensures that the events info link is present on the devel menu and that
48 // it points to the correct page.
50 $this->clickLink('Container Info');
51 $this->assertSession()->statusCodeEquals(200);
52 $this->assertSession()->addressEquals('/devel/container/service');
53 $this->assertSession()->pageTextContains('Container services');
57 * Tests service list page.
59 public function testServiceList() {
60 $this->drupalGet('/devel/container/service');
61 $this->assertSession()->statusCodeEquals(200);
62 $this->assertSession()->pageTextContains('Container services');
63 $this->assertContainerInfoLocalTasks();
65 $page = $this->getSession()->getPage();
67 // Ensures that the services table is found.
68 $table = $page->find('css', 'table.devel-service-list');
69 $this->assertNotNull($table);
71 // Ensures that the expected table headers are found.
72 /** @var $headers \Behat\Mink\Element\NodeElement[] */
73 $headers = $table->findAll('css', 'thead th');
74 $this->assertEquals(4, count($headers));
76 $expected_headers = ['ID', 'Class', 'Alias', 'Operations'];
77 $actual_headers = array_map(function ($element) {
78 return $element->getText();
80 $this->assertSame($expected_headers, $actual_headers);
82 // Ensures that all the serivices are listed in the table.
83 $cached_definition = \Drupal::service('kernel')->getCachedContainerDefinition();
84 $this->assertNotNull($cached_definition);
85 $rows = $table->findAll('css', 'tbody tr');
86 $this->assertEquals(count($cached_definition['services']), count($rows));
88 // Tests the presence of some (arbitrarily chosen) services in the table.
89 $expected_services = [
91 'class' => 'Drupal\Core\Config\ConfigFactory',
94 'devel.route_subscriber' => [
95 'class' => 'Drupal\devel\Routing\RouteSubscriber',
98 'plugin.manager.element_info' => [
99 'class' => 'Drupal\Core\Render\ElementInfoManager',
100 'alias' => 'element_info',
104 foreach ($expected_services as $service_id => $expected) {
105 $row = $table->find('css', sprintf('tbody tr:contains("%s")', $service_id));
106 $this->assertNotNull($row);
108 /** @var $cells \Behat\Mink\Element\NodeElement[] */
109 $cells = $row->findAll('css', 'td');
110 $this->assertEquals(4, count($cells));
112 $cell_service_id = $cells[0];
113 $this->assertEquals($service_id, $cell_service_id->getText());
114 $this->assertTrue($cell_service_id->hasClass('table-filter-text-source'));
116 $cell_class = $cells[1];
117 $this->assertEquals($expected['class'], $cell_class->getText());
118 $this->assertTrue($cell_class->hasClass('table-filter-text-source'));
120 $cell_alias = $cells[2];
121 $this->assertEquals($expected['alias'], $cell_alias->getText());
122 $this->assertTrue($cell_class->hasClass('table-filter-text-source'));
124 $cell_operations = $cells[3];
125 $actual_href = $cell_operations->findLink('Devel')->getAttribute('href');
126 $expected_href = Url::fromRoute('devel.container_info.service.detail', ['service_id' => $service_id])->toString();
127 $this->assertEquals($expected_href, $actual_href);
130 // Ensures that the page is accessible ony to users with the adequate
132 $this->drupalLogout();
133 $this->drupalGet('devel/container/service');
134 $this->assertSession()->statusCodeEquals(403);
138 * Tests service detail page.
140 public function testServiceDetail() {
141 $service_id = 'devel.dumper';
143 // Ensures that the page works as expected.
144 $this->drupalGet("/devel/container/service/$service_id");
145 $this->assertSession()->statusCodeEquals(200);
146 $this->assertSession()->pageTextContains("Service $service_id detail");
148 // Ensures that the page returns a 404 error if the requested service is
150 $this->drupalGet('/devel/container/service/not.exists');
151 $this->assertSession()->statusCodeEquals(404);
153 // Ensures that the page is accessible ony to users with the adequate
155 $this->drupalLogout();
156 $this->drupalGet("devel/container/service/$service_id");
157 $this->assertSession()->statusCodeEquals(403);
161 * Tests parameter list page.
163 public function testParameterList() {
164 // Ensures that the page works as expected.
165 $this->drupalGet('/devel/container/parameter');
166 $this->assertSession()->statusCodeEquals(200);
167 $this->assertSession()->pageTextContains('Container parameters');
168 $this->assertContainerInfoLocalTasks();
170 $page = $this->getSession()->getPage();
172 // Ensures that the parameters table is found.
173 $table = $page->find('css', 'table.devel-parameter-list');
174 $this->assertNotNull($table);
176 // Ensures that the expected table headers are found.
177 /** @var $headers \Behat\Mink\Element\NodeElement[] */
178 $headers = $table->findAll('css', 'thead th');
179 $this->assertEquals(2, count($headers));
181 $expected_headers = ['Name', 'Operations'];
182 $actual_headers = array_map(function ($element) {
183 return $element->getText();
185 $this->assertSame($expected_headers, $actual_headers);
187 // Ensures that all the parameters are listed in the table.
188 $cached_definition = \Drupal::service('kernel')->getCachedContainerDefinition();
189 $this->assertNotNull($cached_definition);
190 $rows = $table->findAll('css', 'tbody tr');
191 $this->assertEquals(count($cached_definition['parameters']), count($rows));
193 // Tests the presence of some parameters in the table.
194 $expected_parameters = [
201 foreach ($expected_parameters as $parameter_name) {
202 $row = $table->find('css', sprintf('tbody tr:contains("%s")', $parameter_name));
203 $this->assertNotNull($row);
205 /** @var $cells \Behat\Mink\Element\NodeElement[] */
206 $cells = $row->findAll('css', 'td');
207 $this->assertEquals(2, count($cells));
209 $cell_parameter_name = $cells[0];
210 $this->assertEquals($parameter_name, $cell_parameter_name->getText());
211 $this->assertTrue($cell_parameter_name->hasClass('table-filter-text-source'));
213 $cell_operations = $cells[1];
214 $actual_href = $cell_operations->findLink('Devel')->getAttribute('href');
215 $expected_href = Url::fromRoute('devel.container_info.parameter.detail', ['parameter_name' => $parameter_name])->toString();
216 $this->assertEquals($expected_href, $actual_href);
219 // Ensures that the page is accessible ony to users with the adequate
221 $this->drupalLogout();
222 $this->drupalGet('devel/container/service');
223 $this->assertSession()->statusCodeEquals(403);
227 * Tests parameter detail page.
229 public function testParameterDetail() {
230 $parameter_name = 'cache_bins';
232 // Ensures that the page works as expected.
233 $this->drupalGet("/devel/container/parameter/$parameter_name");
234 $this->assertSession()->statusCodeEquals(200);
235 $this->assertSession()->pageTextContains("Parameter $parameter_name value");
237 // Ensures that the page returns a 404 error if the requested parameter is
239 $this->drupalGet('/devel/container/parameter/not_exists');
240 $this->assertSession()->statusCodeEquals(404);
242 // Ensures that the page is accessible ony to users with the adequate
244 $this->drupalLogout();
245 $this->drupalGet("devel/container/service/$parameter_name");
246 $this->assertSession()->statusCodeEquals(403);
250 * Asserts that container info local tasks are present.
252 protected function assertContainerInfoLocalTasks() {
253 $expected_local_tasks = [
254 ['devel.container_info.service', []],
255 ['devel.container_info.parameter', []],
258 $this->assertLocalTasks($expected_local_tasks);