ConfigurationFormTest.php in Entity Usage 8
File
tests/src/FunctionalJavascript/ConfigurationFormTest.php
View source
<?php
namespace Drupal\Tests\entity_usage\FunctionalJavascript;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\node\Entity\Node;
class ConfigurationFormTest extends EntityUsageJavascriptTestBase {
protected static $modules = [
'block',
];
public function testConfigForm() {
$this
->drupalPlaceBlock('local_tasks_block');
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('/admin/config/entity-usage/settings');
$assert_session
->statusCodeEquals(403);
$this
->drupalLogin($this
->drupalCreateUser([
'bypass node access',
'administer entity usage',
'access entity usage statistics',
]));
$this
->drupalGet('/admin/config/entity-usage/settings');
$assert_session
->statusCodeEquals(200);
$assert_session
->titleEquals('Entity Usage Settings' . ' | Drupal');
$summary = $assert_session
->elementExists('css', '#edit-local-task-enabled-entity-types summary');
$this
->assertEquals('Local tasks', $summary
->getText());
$assert_session
->pageTextContains('Check in which entity types there should be a tab (local task) linking to the usage page.');
foreach (\Drupal::entityTypeManager()
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type instanceof ContentEntityTypeInterface && $entity_type
->hasLinkTemplate('canonical')) {
$field_name = "local_task_enabled_entity_types[{$entity_type_id}]";
$assert_session
->fieldExists($field_name);
$assert_session
->checkboxNotChecked($field_name);
}
}
$page
->checkField('local_task_enabled_entity_types[node]');
$page
->pressButton('Save configuration');
$this
->saveHtmlOutput();
$assert_session
->pageTextContains('The configuration options have been saved.');
$assert_session
->checkboxChecked('local_task_enabled_entity_types[node]');
$node = Node::create([
'type' => 'eu_test_ct',
'title' => 'Test node',
]);
$node
->save();
$this
->drupalGet("/node/{$node->id()}");
$assert_session
->pageTextContains('Usage');
$page
->clickLink('Usage');
$this
->saveHtmlOutput();
$this
->assertTrue(strpos($session
->getCurrentUrl(), "/node/{$node->id()}/usage") !== FALSE);
$assert_session
->pageTextContains('Entity usage information for Test node');
$assert_session
->pageTextContains('There are no recorded usages for ');
$page
->clickLink('View');
$this
->saveHtmlOutput();
$assert_session
->titleEquals('Test node' . ' | Drupal');
}
}