View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Core\Url;
class DevelContainerInfoTest extends DevelBrowserTestBase {
use DevelWebAssertHelper;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalLogin($this->develUser);
}
public function testContainerInfoMenuLink() {
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalGet('');
$this
->clickLink('Container Info');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('/devel/container/service');
$this
->assertSession()
->pageTextContains('Container services');
}
public function testServiceList() {
$this
->drupalGet('/devel/container/service');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Container services');
$this
->assertContainerInfoLocalTasks();
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table.devel-service-list');
$this
->assertNotNull($table);
$headers = $table
->findAll('css', 'thead th');
$this
->assertEquals(4, count($headers));
$expected_headers = [
'ID',
'Class',
'Alias',
'Operations',
];
$actual_headers = array_map(function ($element) {
return $element
->getText();
}, $headers);
$this
->assertSame($expected_headers, $actual_headers);
$cached_definition = \Drupal::service('kernel')
->getCachedContainerDefinition();
$this
->assertNotNull($cached_definition);
$rows = $table
->findAll('css', 'tbody tr');
$this
->assertEquals(count($cached_definition['services']), count($rows));
$expected_services = [
'config.factory' => [
'class' => 'Drupal\\Core\\Config\\ConfigFactory',
'alias' => '',
],
'devel.route_subscriber' => [
'class' => 'Drupal\\devel\\Routing\\RouteSubscriber',
'alias' => '',
],
'plugin.manager.element_info' => [
'class' => 'Drupal\\Core\\Render\\ElementInfoManager',
'alias' => 'element_info',
],
];
foreach ($expected_services as $service_id => $expected) {
$row = $table
->find('css', sprintf('tbody tr:contains("%s")', $service_id));
$this
->assertNotNull($row);
$cells = $row
->findAll('css', 'td');
$this
->assertEquals(4, count($cells));
$cell_service_id = $cells[0];
$this
->assertEquals($service_id, $cell_service_id
->getText());
$this
->assertTrue($cell_service_id
->hasClass('table-filter-text-source'));
$cell_class = $cells[1];
$this
->assertEquals($expected['class'], $cell_class
->getText());
$this
->assertTrue($cell_class
->hasClass('table-filter-text-source'));
$cell_alias = $cells[2];
$this
->assertEquals($expected['alias'], $cell_alias
->getText());
$this
->assertTrue($cell_class
->hasClass('table-filter-text-source'));
$cell_operations = $cells[3];
$actual_href = $cell_operations
->findLink('Devel')
->getAttribute('href');
$expected_href = Url::fromRoute('devel.container_info.service.detail', [
'service_id' => $service_id,
])
->toString();
$this
->assertEquals($expected_href, $actual_href);
}
$this
->drupalLogout();
$this
->drupalGet('devel/container/service');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testServiceDetail() {
$service_id = 'devel.dumper';
$this
->drupalGet("/devel/container/service/{$service_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Service {$service_id} detail");
$this
->drupalGet('/devel/container/service/not.exists');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalLogout();
$this
->drupalGet("devel/container/service/{$service_id}");
$this
->assertSession()
->statusCodeEquals(403);
}
public function testParameterList() {
$this
->drupalGet('/devel/container/parameter');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Container parameters');
$this
->assertContainerInfoLocalTasks();
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table.devel-parameter-list');
$this
->assertNotNull($table);
$headers = $table
->findAll('css', 'thead th');
$this
->assertEquals(2, count($headers));
$expected_headers = [
'Name',
'Operations',
];
$actual_headers = array_map(function ($element) {
return $element
->getText();
}, $headers);
$this
->assertSame($expected_headers, $actual_headers);
$cached_definition = \Drupal::service('kernel')
->getCachedContainerDefinition();
$this
->assertNotNull($cached_definition);
$rows = $table
->findAll('css', 'tbody tr');
$this
->assertEquals(count($cached_definition['parameters']), count($rows));
$expected_parameters = [
'container.modules',
'cache_bins',
'factory.keyvalue',
'twig.config',
];
foreach ($expected_parameters as $parameter_name) {
$row = $table
->find('css', sprintf('tbody tr:contains("%s")', $parameter_name));
$this
->assertNotNull($row);
$cells = $row
->findAll('css', 'td');
$this
->assertEquals(2, count($cells));
$cell_parameter_name = $cells[0];
$this
->assertEquals($parameter_name, $cell_parameter_name
->getText());
$this
->assertTrue($cell_parameter_name
->hasClass('table-filter-text-source'));
$cell_operations = $cells[1];
$actual_href = $cell_operations
->findLink('Devel')
->getAttribute('href');
$expected_href = Url::fromRoute('devel.container_info.parameter.detail', [
'parameter_name' => $parameter_name,
])
->toString();
$this
->assertEquals($expected_href, $actual_href);
}
$this
->drupalLogout();
$this
->drupalGet('devel/container/service');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testParameterDetail() {
$parameter_name = 'cache_bins';
$this
->drupalGet("/devel/container/parameter/{$parameter_name}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Parameter {$parameter_name} value");
$this
->drupalGet('/devel/container/parameter/not_exists');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalLogout();
$this
->drupalGet("devel/container/service/{$parameter_name}");
$this
->assertSession()
->statusCodeEquals(403);
}
protected function assertContainerInfoLocalTasks() {
$expected_local_tasks = [
[
'devel.container_info.service',
[],
],
[
'devel.container_info.parameter',
[],
],
];
$this
->assertLocalTasks($expected_local_tasks);
}
}