public function EntityUsageTest::testEntityUsageBlockTrackingHook 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::testEntityUsageBlockTrackingHook()
- 8.3 tests/src/Kernel/EntityUsageTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageTest::testEntityUsageBlockTrackingHook()
Tests that our hook correctly blocks a usage from being tracked.
File
- tests/
src/ Kernel/ EntityUsageTest.php, line 332
Class
- EntityUsageTest
- Tests the basic API operations of our tracking service.
Namespace
Drupal\Tests\entity_usage\KernelCode
public function testEntityUsageBlockTrackingHook() {
$this->container
->get('module_installer')
->install([
'image',
'media',
'path',
'views',
'entity_usage_test',
]);
$entity = $this->testEntities[0];
$field_name = 'body';
/** @var \Drupal\entity_usage\EntityUsage $entity_usage */
$entity_usage = $this->container
->get('entity_usage.usage');
$entity_usage
->registerUsage($entity
->id(), $entity
->getEntityTypeId(), 1, 'foo', 'en', 0, 'entity_reference', $field_name, 31);
$real_usage = $this->injectedDatabase
->select($this->tableName, 'e')
->fields('e', [
'count',
])
->condition('e.target_id', $entity
->id())
->execute()
->fetchField();
// In entity_usage_test_entity_usage_block_tracking() we block all
// transactions that try to add "31" as count. We expect then the usage to
// be 0.
$this
->assertEquals(0, $real_usage);
// Clean back the environment.
$this->injectedDatabase
->truncate($this->tableName);
}