public function VideoFieldTestCase::testDeleteVideoFieldItemTwice in Video 7.2
Tests adding a video to two different nodes and deleting them one by one
File
- tests/
VideoField.test, line 209 - Tests for the the Video field type
Class
- VideoFieldTestCase
- Tests for the the Video field type
Code
public function testDeleteVideoFieldItemTwice() {
// Build test data
$file = $this
->createFile('file3.mp4');
$node1 = new stdClass();
$node1->uid = $this->user->uid;
$node1->type = 'page';
$node1->title = 'Test node';
$node1->videofield['und'][0] = array(
'fid' => $file->fid,
'dimensions' => '100x60',
);
node_save($node1);
$node2 = new stdClass();
$node2->uid = $this->user->uid;
$node2->type = 'page';
$node2->title = 'Test node';
$node2->videofield['und'][0] = array(
'fid' => $file->fid,
'dimensions' => '100x60',
);
node_save($node2);
$node1 = node_load($node1->nid);
$node2 = node_load($node2->nid);
// Sanity checks
$queues = $this
->getQueues($file->fid);
$this
->assertEqual(1, count($queues), 'One video_queue entry should be present');
$this
->assertEqual(2, count($this
->getFileUsage($file->fid)), 'There should be two usage entries immediately after saving');
$queue = array_shift($queues);
$this
->transcodeVideo($node1, $queue->vid, $file->fid);
node_save($node2);
// Check converted files and thumbnails
$conv = $this
->getConvertedFiles($file->fid);
$tn = $this
->getThumbnailFiles($file->fid);
$this
->assertEqual(1, count($conv), 'There should be 1 converted file immediately after saving');
$this
->assertEqual(5, count($tn), 'There should be 5 thumbnail files immediately after saving');
// Check usage of derived files: 2 usages should be registered
foreach ($conv + $tn as $df) {
$u = $this
->getFileUsage($df->fid);
$this
->assertEqual(2, count($u), 'There should be one usage entry for derived file ' . $df->fid . ' after saving both nodes');
if (count($u) == 0) {
continue;
}
$this
->assertEqual('node', $u[0]->type, 'usage entry for derived file ' . $df->fid . ' should have type node');
$this
->assertEqual($node1->nid, $u[0]->id, 'usage entry for derived file ' . $df->fid . ' should have id ' . $node1->nid);
$this
->assertEqual('node', $u[1]->type, 'usage entry for derived file ' . $df->fid . ' should have type node');
$this
->assertEqual($node2->nid, $u[1]->id, 'usage entry for derived file ' . $df->fid . ' should have id ' . $node2->nid);
}
// Delete the video from node 1
unset($node1->videofield['und'][0]);
node_save($node1);
// Check usage of derived files: 1 usages should be registered
foreach ($conv + $tn as $df) {
$u = $this
->getFileUsage($df->fid);
$this
->assertEqual(1, count($u), 'There should be one usage entry for derived file ' . $df->fid . ' after deleting the video from one node');
if (count($u) == 0) {
continue;
}
$this
->assertEqual('node', $u[0]->type, 'usage entry for derived file ' . $df->fid . ' should have type node');
$this
->assertEqual($node2->nid, $u[0]->id, 'usage entry for derived file ' . $df->fid . ' should have id ' . $node2->nid);
}
// Queue entry should still be there, one usage should remain
$this
->assertEqual(1, count($this
->getQueues($file->fid)), 'One video_queue entry should be present after deleting the video from one node');
$this
->assertEqual(1, count($this
->getFileUsage($file->fid)), 'There should be one usage entry remaining after deleting the video from one node');
// Check whether the converted files and thumbnails still exist
$this
->assertEqual(1, count($this
->getConvertedFiles($file->fid)), 'There should be 1 converted file immediately after deleting the video from one node');
$this
->assertEqual(5, count($this
->getThumbnailFiles($file->fid)), 'There should be 5 thumbnail files immediately after deleting the video from one node');
// Delete the video from node 2
unset($node2->videofield['und'][0]);
node_save($node2);
// Check if everything is deleted properly
$this
->assertEqual(0, count($this
->getQueues($file->fid)), 'video_queue entry should be removed');
$this
->assertEqual(0, count($this
->getFileUsage($file->fid)), 'There should be no usage entries after deleting');
$this
->assertEqual(0, count($this
->getThumbnailFiles($file->fid)), 'There should be no thumbnail entries after deleting');
$this
->assertEqual(0, count($this
->getConvertedFiles($file->fid)), 'There should be no converted entries after deleting');
// Check usage of derived files: 0 usages should be registered
foreach ($conv + $tn as $df) {
$u = $this
->getFileUsage($df->fid);
$this
->assertEqual(0, count($u), 'There should be no usage entry for derived file ' . $df->fid . ' after saving both nodes');
}
}