public function EntityUsageTest::testBulkDeleteTargets in Entity Usage 8.2
Same name and namespace in other branches
- 8.4 tests/src/Kernel/EntityUsageTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageTest::testBulkDeleteTargets()
- 8 tests/src/Kernel/EntityUsageTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageTest::testBulkDeleteTargets()
- 8.3 tests/src/Kernel/EntityUsageTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageTest::testBulkDeleteTargets()
Tests the bulkDeleteTargets() method.
@covers \Drupal\entity_usage\EntityUsage::bulkDeleteTargets
File
- tests/
src/ Kernel/ EntityUsageTest.php, line 366
Class
- EntityUsageTest
- Tests the basic API operations of our tracking service.
Namespace
Drupal\Tests\entity_usage\KernelCode
public function testBulkDeleteTargets() {
$entity_type = $this->testEntities[0]
->getEntityTypeId();
// Create 2 fake registers on the database table, one for each entity.
foreach ($this->testEntities as $entity) {
$this->injectedDatabase
->insert($this->tableName)
->fields([
'target_id' => $entity
->id(),
'target_type' => $entity_type,
'source_id' => 1,
'source_type' => 'foo',
'source_langcode' => 'en',
'source_vid' => 1,
'method' => 'entity_reference',
'field_name' => 'body',
'count' => 1,
])
->execute();
}
/** @var \Drupal\entity_usage\EntityUsage $entity_usage */
$entity_usage = $this->container
->get('entity_usage.usage');
$entity_usage
->bulkDeleteTargets($entity_type);
$event = \Drupal::state()
->get('entity_usage_events_test.usage_bulk_delete_targets', []);
$this
->assertSame($event['event_name'], Events::BULK_DELETE_DESTINATIONS);
$this
->assertSame($event['target_id'], NULL);
$this
->assertSame($event['target_type'], $entity_type);
$this
->assertSame($event['source_id'], NULL);
$this
->assertSame($event['source_type'], NULL);
$this
->assertSame($event['source_langcode'], NULL);
$this
->assertSame($event['source_vid'], NULL);
$this
->assertSame($event['method'], NULL);
$this
->assertSame($event['field_name'], NULL);
$this
->assertSame($event['count'], NULL);
// Check if there are no records left.
$count = $this->injectedDatabase
->select($this->tableName, 'e')
->fields('e', [
'count',
])
->condition('e.target_type', $entity_type)
->execute()
->fetchField();
$this
->assertSame(FALSE, $count);
// Clean back the environment.
$this->injectedDatabase
->truncate($this->tableName);
}