View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class DevelEventInfoTest extends BrowserTestBase {
public static $modules = [
'devel',
'block',
];
protected $develUser;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
$this->develUser = $this
->drupalCreateUser([
'access devel information',
]);
$this
->drupalLogin($this->develUser);
}
public function testEventsInfoMenuLink() {
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalGet('');
$this
->clickLink('Events Info');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('/devel/events');
$this
->assertSession()
->pageTextContains('Events');
}
public function testEventList() {
$event_dispatcher = \Drupal::service('event_dispatcher');
$this
->drupalGet('/devel/events');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Events');
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table.devel-event-list');
$this
->assertNotNull($table);
$headers = $table
->findAll('css', 'thead th');
$this
->assertEquals(3, count($headers));
$expected_headers = [
'Event Name',
'Callable',
'Priority',
];
$actual_headers = array_map(function ($element) {
return $element
->getText();
}, $headers);
$this
->assertSame($expected_headers, $actual_headers);
$events = $event_dispatcher
->getListeners();
$event_header_row = $table
->findAll('css', 'tbody tr th.devel-event-name-header');
$this
->assertEquals(count($events), count($event_header_row));
$expected_events = [
'config.delete',
'kernel.request',
'routing.route_alter',
];
foreach ($expected_events as $event_name) {
$listeners = $event_dispatcher
->getListeners($event_name);
$event_header_row = $table
->findAll('css', sprintf('tbody tr th:contains("%s")', $event_name));
$this
->assertNotNull($event_header_row);
$this
->assertEquals(1, count($event_header_row));
$event_rows = $table
->findAll('css', sprintf('tbody tr:contains("%s")', $event_name));
array_shift($event_rows);
$this
->assertEquals(count($listeners), count($event_rows));
foreach ($listeners as $index => $listener) {
$cells = $event_rows[$index]
->findAll('css', 'td');
$this
->assertEquals(3, count($cells));
$cell_event_name = $cells[0];
$this
->assertEquals($event_name, $cell_event_name
->getText());
$this
->assertTrue($cell_event_name
->hasClass('table-filter-text-source'));
$this
->assertTrue($cell_event_name
->hasClass('visually-hidden'));
$cell_callable = $cells[1];
is_callable($listener, TRUE, $callable_name);
$this
->assertEquals($callable_name, $cell_callable
->getText());
$cell_methods = $cells[2];
$this
->assertEquals($index, $cell_methods
->getText());
}
}
$this
->drupalLogout();
$this
->drupalGet('devel/events');
$this
->assertSession()
->statusCodeEquals(403);
}
}