function FileUsageTest::testAddUsage in MongoDB 8
Tests file_usage()->add().
File
- src/
Tests/ FileUsageTest.php, line 54 - Definition of Drupal\mongodb\Tests\FileUsageTest.
Class
- FileUsageTest
- Tests file usage functions.
Namespace
Drupal\mongodb\TestsCode
function testAddUsage() {
$file = $this
->createFile();
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);
$database = \Drupal::service('mongo');
$results = $database
->get('file_usage')
->find(array(
'fid' => (int) $file
->id(),
));
$usage = array();
foreach ($results as $result) {
$usage[$result['id']] = $result;
}
$this
->assertEqual(count($usage), 2, t('Created two records'));
$this
->assertEqual($usage[1]['module'], 'testing', t('Correct module'));
$this
->assertEqual($usage[2]['module'], 'testing', t('Correct module'));
$this
->assertEqual($usage[1]['type'], 'foo', t('Correct type'));
$this
->assertEqual($usage[2]['type'], 'bar', t('Correct type'));
$this
->assertEqual($usage[1]['count'], 1, t('Correct count'));
$this
->assertEqual($usage[2]['count'], 2, t('Correct count'));
}