BatchUpdateTest.php in Entity Usage 8
File
tests/src/FunctionalJavascript/BatchUpdateTest.php
View source
<?php
namespace Drupal\Tests\entity_usage\FunctionalJavascript;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\Role;
class BatchUpdateTest extends EntityUsageJavascriptTestBase {
public function setUp() {
parent::setUp();
$role = Role::load('authenticated');
$this
->grantPermissions($role, [
'perform batch updates entity usage',
]);
}
public function testBatchUpdate() {
$page = $this
->getSession()
->getPage();
$usage_service = \Drupal::service('entity_usage.usage');
$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.');
$this
->saveHtmlOutput();
$this
->drupalGet('/node/add/eu_test_ct');
$page
->fillField('title[0][value]', 'Node 3');
$page
->fillField('field_eu_test_related_nodes[0][target_id]', 'Node 1 (1)');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('eu_test_ct Node 3 has been created.');
$this
->saveHtmlOutput();
$usage_service
->delete(1, 'node', 2, 'node');
$usage = $usage_service
->listUsage($node1);
$this
->assertEquals($usage['node'], [
'3' => '1',
]);
$this
->drupalGet('/admin/config/entity-usage/batch-update');
$this
->assertSession()
->pageTextContains('Batch Update');
$this
->assertSession()
->pageTextContains('This form allows you to reset and track again all entity usages in your system.');
$page
->pressButton('Recreate entity usage statistics');
$this
->getSession()
->wait(5000);
$this
->saveHtmlOutput();
$this
->assertSession()
->pageTextContains('Recreated entity usage for');
$usage = $usage_service
->listUsage($node1);
$this
->assertEquals($usage['node'], [
'2' => '1',
'3' => '1',
]);
}
}