function UsageTest::testAddUsage
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::testAddUsage()
- 8.9.x core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::testAddUsage()
- 11.x core/modules/file/tests/src/Kernel/UsageTest.php \Drupal\Tests\file\Kernel\UsageTest::testAddUsage()
Tests \Drupal\file\FileUsage\DatabaseFileUsageBackend::add().
File
-
core/
modules/ file/ tests/ src/ Kernel/ UsageTest.php, line 59
Class
- UsageTest
- Tests file usage functions.
Namespace
Drupal\Tests\file\KernelCode
public function testAddUsage() : void {
$file = $this->createFile();
$file_usage = $this->container
->get('file.usage');
$file_usage->add($file, 'testing', 'foo', 1);
// Add the file twice to ensure that the count is incremented rather than
// creating additional records.
$file_usage->add($file, 'testing', 'bar', 2);
$file_usage->add($file, 'testing', 'bar', 2);
$usage = Database::getConnection()->select('file_usage', 'f')
->fields('f')
->condition('f.fid', $file->id())
->execute()
->fetchAllAssoc('id');
$this->assertCount(2, $usage, 'Created two records');
$this->assertEquals('testing', $usage[1]->module, 'Correct module');
$this->assertEquals('testing', $usage[2]->module, 'Correct module');
$this->assertEquals('foo', $usage[1]->type, 'Correct type');
$this->assertEquals('bar', $usage[2]->type, 'Correct type');
$this->assertEquals(1, $usage[1]->count, 'Correct count');
$this->assertEquals(2, $usage[2]->count, 'Correct count');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.