View source
<?php
namespace Drupal\Tests\devel\Functional;
use Behat\Mink\Element\NodeElement;
use Drupal\Core\Url;
class DevelEntityTypeInfoTest extends DevelBrowserTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalLogin($this->develUser);
}
public function testEntityInfoMenuLink() {
$this
->drupalPlaceBlock('system_menu_block:devel');
$this
->drupalGet('');
$this
->clickLink('Entity Info');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->addressEquals('/devel/entity/info');
$this
->assertSession()
->pageTextContains('Entity Info');
}
public function testEntityTypeList() {
$this
->drupalGet('/devel/entity/info');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Entity Info');
$page = $this
->getSession()
->getPage();
$table = $page
->find('css', 'table.devel-entity-type-list');
$this
->assertNotNull($table);
$headers = $table
->findAll('css', 'thead th');
$this
->assertEquals(5, count($headers));
$expected_headers = [
'ID',
'Name',
'Provider',
'Class',
'Operations',
];
$actual_headers = array_map(function (NodeElement $element) {
return $element
->getText();
}, $headers);
$this
->assertSame($expected_headers, $actual_headers);
$expected_types = [
'date_format' => [
'name' => 'Date format',
'class' => 'Drupal\\Core\\Datetime\\Entity\\DateFormat',
'provider' => 'core',
],
'block' => [
'name' => 'Block',
'class' => 'Drupal\\block\\Entity\\Block',
'provider' => 'block',
],
'entity_view_mode' => [
'name' => 'View mode',
'class' => 'Drupal\\Core\\Entity\\Entity\\EntityViewMode',
'provider' => 'core',
],
];
foreach ($expected_types as $entity_type_id => $entity_type) {
$row = $table
->find('css', sprintf('tbody tr:contains("%s")', $entity_type_id));
$this
->assertNotNull($row);
$cells = $row
->findAll('css', 'td');
$this
->assertEquals(5, count($cells));
$cell = $cells[0];
$this
->assertEquals($entity_type_id, $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[1];
$this
->assertEquals($entity_type['name'], $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[2];
$this
->assertEquals($entity_type['provider'], $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[3];
$this
->assertEquals($entity_type['class'], $cell
->getText());
$this
->assertTrue($cell
->hasClass('table-filter-text-source'));
$cell = $cells[4];
$actual_href = $cell
->findLink('Devel')
->getAttribute('href');
$expected_href = Url::fromRoute('devel.entity_info_page.detail', [
'entity_type_id' => $entity_type_id,
])
->toString();
$this
->assertEquals($expected_href, $actual_href);
$actual_href = $cell
->findLink('Fields')
->getAttribute('href');
$expected_href = Url::fromRoute('devel.entity_info_page.fields', [
'entity_type_id' => $entity_type_id,
])
->toString();
$this
->assertEquals($expected_href, $actual_href);
}
$this
->drupalLogout();
$this
->drupalGet('devel/entity/info');
$this
->assertSession()
->statusCodeEquals(403);
}
public function testEntityTypeDetail() {
$entity_type_id = 'date_format';
$this
->drupalGet("/devel/entity/info/{$entity_type_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Entity type {$entity_type_id}");
$this
->drupalGet('/devel/entity/info/not_exists');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalLogout();
$this
->drupalGet("/devel/entity/info/{$entity_type_id}");
$this
->assertSession()
->statusCodeEquals(403);
}
public function testEntityTypeFields() {
$entity_type_id = 'date_format';
$this
->drupalGet("/devel/entity/fields/{$entity_type_id}");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains("Entity fields {$entity_type_id}");
$this
->drupalGet('/devel/entity/fields/not_exists');
$this
->assertSession()
->statusCodeEquals(404);
$this
->drupalLogout();
$this
->drupalGet("/devel/entity/fields/{$entity_type_id}");
$this
->assertSession()
->statusCodeEquals(403);
}
}