ListControllerTest.php in Entity Usage 8
File
tests/src/FunctionalJavascript/ListControllerTest.php
View source
<?php
namespace Drupal\Tests\entity_usage\FunctionalJavascript;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\Role;
class ListControllerTest extends EntityUsageJavascriptTestBase {
public function setUp() {
parent::setUp();
$role = Role::load('authenticated');
$this
->grantPermissions($role, [
'access entity usage statistics',
]);
}
public function testListController() {
$page = $this
->getSession()
->getPage();
$this
->drupalGet('/node/add/eu_test_ct');
$page
->fillField('title[0][value]', 'Node 1');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('eu_test_ct Node 1 has been created.');
$node1 = Node::load(1);
$this
->saveHtmlOutput();
$this
->drupalGet('/node/add/eu_test_ct');
$page
->fillField('title[0][value]', 'Node 2');
$page
->fillField('field_eu_test_related_nodes[0][target_id]', 'Node 1 (1)');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('eu_test_ct Node 2 has been created.');
$node2 = Node::load(2);
$this
->saveHtmlOutput();
$uuid_node1 = $node1
->uuid();
$embedded_text = '<drupal-entity data-embed-button="node" data-entity-embed-display="entity_reference:entity_reference_label" data-entity-embed-display-settings="{"link":1}" data-entity-type="node" data-entity-uuid="' . $uuid_node1 . '"></drupal-entity>';
$node3 = Node::create([
'type' => 'eu_test_ct',
'title' => 'Node 3',
'field_eu_test_rich_text' => [
'value' => $embedded_text,
'format' => 'eu_test_text_format',
],
]);
$node3
->save();
$this
->drupalGet('/admin/content/entity-usage/node/1');
$this
->assertSession()
->pageTextContains('Entity usage information for Node 1');
$this
->assertSession()
->pageTextContains('Referencing entity');
$this
->assertSession()
->pageTextContains('Referencing entity type');
$this
->assertSession()
->pageTextContains('Referencing method');
$this
->assertSession()
->pageTextContains('Count');
$this
->assertSession()
->linkExists('Node 2');
$this
->assertSession()
->linkByHrefExists('/node/2');
$this
->assertSession()
->linkExists('Node 3');
$this
->assertSession()
->linkByHrefExists('/node/3');
$first_row_title = $this
->xpath('//table/tbody/tr[1]/td[1]')[0];
$this
->assertEquals('Node 2', $first_row_title
->getText());
$first_row_type = $this
->xpath('//table/tbody/tr[1]/td[2]')[0];
$this
->assertEquals('node', $first_row_type
->getText());
$first_row_method = $this
->xpath('//table/tbody/tr[1]/td[3]')[0];
$this
->assertEquals('entity_reference', $first_row_method
->getText());
$first_row_count = $this
->xpath('//table/tbody/tr[1]/td[4]')[0];
$this
->assertEquals('1', $first_row_count
->getText());
$second_row_title = $this
->xpath('//table/tbody/tr[2]/td[1]')[0];
$this
->assertEquals('Node 3', $second_row_title
->getText());
$second_row_type = $this
->xpath('//table/tbody/tr[2]/td[2]')[0];
$this
->assertEquals('node', $second_row_type
->getText());
$second_row_method = $this
->xpath('//table/tbody/tr[2]/td[3]')[0];
$this
->assertEquals('entity_embed', $second_row_method
->getText());
$second_row_count = $this
->xpath('//table/tbody/tr[2]/td[4]')[0];
$this
->assertEquals('1', $second_row_count
->getText());
}
}