function FileUsageTest::testRemoveUsage in MongoDB 8
Tests file_usage()->delete().
File
- src/
Tests/ FileUsageTest.php, line 82 - Definition of Drupal\mongodb\Tests\FileUsageTest.
Class
- FileUsageTest
- Tests file usage functions.
Namespace
Drupal\mongodb\TestsCode
function testRemoveUsage() {
$file = $this
->createFile();
$database = \Drupal::service('mongo');
$database
->get('file_usage')
->insert(array(
'fid' => (int) $file
->id(),
'module' => 'testing',
'type' => 'bar',
'id' => 2,
'count' => 3,
));
// Normal decrement.
file_usage()
->delete($file, 'testing', 'bar', 2);
$result = $database
->get('file_usage')
->findOne(array(
'fid' => (int) $file
->id(),
), array(
'count' => TRUE,
));
$this
->assertEqual(2, $result['count'], t('The count was decremented correctly.'));
// Multiple decrement and removal.
file_usage()
->delete($file, 'testing', 'bar', 2, 2);
$count = $database
->get('file_usage')
->findOne(array(
'fid' => (int) $file
->id(),
), array(
'count' => TRUE,
));
$this
->assertIdentical(FALSE, isset($count['count']), t('The count was removed entirely when empty.'));
// Non-existent decrement.
file_usage()
->delete($file, 'testing', 'bar', 2);
$count = $database
->get('file_usage')
->findOne(array(
'fid' => (int) $file
->id(),
), array(
'count' => TRUE,
));
$this
->assertIdentical(FALSE, isset($count['count']), t('Decrementing non-exist record complete.'));
}