You are here

public function VideoFieldTestCase::testDeleteVideoFieldItemTwice_EntityDelete in Video 7.2

Tests adding a video to two different nodes and deleting the nodes

File

tests/VideoField.test, line 297
Tests for the the Video field type

Class

VideoFieldTestCase
Tests for the the Video field type

Code

public function testDeleteVideoFieldItemTwice_EntityDelete() {

  // Build test data
  $file = $this
    ->createFile('file4.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');
  $this
    ->assertTrue(file_exists($file->uri), 'The file should exist');
  $queue = array_shift($queues);
  $this
    ->transcodeVideo($node1, $queue->vid, $file->fid);
  node_save($node2);

  // Delete node 1
  node_delete($node1->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 one node');
  $this
    ->assertEqual(1, count($this
    ->getFileUsage($file->fid)), 'There should be one usage entry remaining after deleting one node');
  $this
    ->assertTrue(file_exists($file->uri), 'The file should exist after deleting 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 video from one node');
  $this
    ->assertEqual(5, count($this
    ->getThumbnailFiles($file->fid)), 'There should be 5 thumbnail files immediately after video from one node');

  // Delete node 2
  node_delete($node2->nid);

  // Queue entry and usage entry should still be removed
  $this
    ->assertEqual(0, count($this
    ->getQueues($file->fid)), 'No video_queue entry should be present after deleting all nodes');
  $this
    ->assertEqual(0, count($this
    ->getFileUsage($file->fid)), 'There should be no usage entries remaining after deleting all nodes');
  $this
    ->assertFalse(file_exists($file->uri), 'The file should be removed after deleting the video from all nodes');
}