function UsageTest::doTestRemoveUsage
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::doTestRemoveUsage()
- 10 core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::doTestRemoveUsage()
- 11.x core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::doTestRemoveUsage()
Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete().
2 calls to UsageTest::doTestRemoveUsage()
- UsageTest::testRemoveUsageNonTemporary in core/
modules/ file/ tests/ src/ Kernel/ UsageTest.php - Tests file usage deletion when files are made temporary.
- UsageTest::testRemoveUsageTemporary in core/
modules/ file/ tests/ src/ Kernel/ UsageTest.php - Tests file usage deletion when files are made temporary.
File
-
core/
modules/ file/ tests/ src/ Kernel/ UsageTest.php, line 105
Class
- UsageTest
- Tests file usage functions.
Namespace
Drupal\Tests\file\KernelCode
public function doTestRemoveUsage() {
$file = $this->createFile();
$file->setPermanent();
$file_usage = $this->container
->get('file.usage');
$connection = Database::getConnection();
$connection->insert('file_usage')
->fields([
'fid' => $file->id(),
'module' => 'testing',
'type' => 'bar',
'id' => 2,
'count' => 3,
])
->execute();
// Normal decrement.
$file_usage->delete($file, 'testing', 'bar', 2);
$count = $connection->select('file_usage', 'f')
->fields('f', [
'count',
])
->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertEqual(2, $count, 'The count was decremented correctly.');
// Multiple decrement and removal.
$file_usage->delete($file, 'testing', 'bar', 2, 2);
$count = $connection->select('file_usage', 'f')
->fields('f', [
'count',
])
->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertIdentical(FALSE, $count, 'The count was removed entirely when empty.');
// Non-existent decrement.
$file_usage->delete($file, 'testing', 'bar', 2);
$count = $connection->select('file_usage', 'f')
->fields('f', [
'count',
])
->condition('f.fid', $file->id())
->execute()
->fetchField();
$this->assertIdentical(FALSE, $count, 'Decrementing non-exist record complete.');
return $file;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.