You are here

public function VideoFieldTestCase::testSaveVideoFieldItem in Video 7.2

Tests basic behavior for saving a new video and adding it to a node.

File

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

Class

VideoFieldTestCase
Tests for the the Video field type

Code

public function testSaveVideoFieldItem() {

  // Build test data
  $file = $this
    ->createFile();
  $node = new stdClass();
  $node->uid = $this->user->uid;
  $node->type = 'page';
  $node->title = 'Test node';
  $node->videofield['und'][0] = array(
    'fid' => $file->fid,
    'dimensions' => '100x60',
  );
  node_save($node);
  $node = node_load($node->nid);

  // Check file status set to permanent
  $file = file_load($file->fid);
  $this
    ->assertEqual(FILE_STATUS_PERMANENT, $file->status, 'The file should be permanent');
  $this
    ->assertTrue(file_exists($file->uri), 'The file should exist');

  // Check queue result
  $queues = $this
    ->getQueues($file->fid);
  $this
    ->assertEqual(1, count($queues), 'One video_queue entry should be present');
  $queue = array_shift($queues);
  $this
    ->assertEqual($file->fid, $queue->fid, 'video_queue entry should have fid ' . $file->fid);
  $this
    ->assertEqual('node', $queue->entity_type, 'video_queue entry should entity_type node');
  $this
    ->assertEqual($node->nid, $queue->entity_id, 'video_queue entry should entity_id ' . $node->nid);
  $this
    ->assertEqual(VIDEO_RENDERING_PENDING, $queue->status, 'video_queue entry should have status ' . VIDEO_RENDERING_PENDING);
  $this
    ->assertEqual('100x60', $queue->dimensions, 'video_queue entry should have dimensions 100x60');
  $this
    ->assertNull($queue->duration, 'video_queue entry should have empty duration');
  $this
    ->assertEqual(0, $queue->started, 'video_queue entry should have started 0');
  $this
    ->assertEqual(0, $queue->completed, 'video_queue entry should have completed 0');
  $this
    ->assertEqual('videofield', $queue->data['field_name'], 'video_queue entry should have field_name videofield');
  $this
    ->assertEqual('und', $queue->data['langcode'], 'video_queue entry should have langcode und');
  $this
    ->assertEqual(0, $queue->data['delta'], 'video_queue entry should have delta 0');

  // No converted files and thumbnails at this point
  $this
    ->assertEqual(0, count($this
    ->getConvertedFiles($file->fid)), 'There should be no converted files immediately after saving');
  $this
    ->assertEqual(0, count($this
    ->getThumbnailFiles($file->fid)), 'There should be no thumbnail files immediately after saving');

  // Transcode the video
  $this
    ->transcodeVideo($node, $queue->vid, $file->fid);

  // Test the transcoded video
  $queues = $this
    ->getQueues($file->fid);
  $this
    ->assertEqual(1, count($queues), 'One video_queue entry should be present');
  $queue = array_shift($queues);
  $this
    ->assertEqual(VIDEO_RENDERING_COMPLETE, $queue->status, 'video_queue entry should have status ' . VIDEO_RENDERING_COMPLETE);

  // One converted video
  $conv = $this
    ->getConvertedFiles($file->fid);
  $this
    ->assertEqual(1, count($conv), 'There should be one converted files after transcoding');

  // Five thumbnails files
  $tn = $this
    ->getThumbnailFiles($file->fid);
  $this
    ->assertEqual(5, count($tn), 'There should be five thumbnail files after transcoding');

  // One usage entry for the video
  $u = $this
    ->getFileUsage($file->fid);
  $this
    ->assertEqual(1, count($u), 'There should be one usage entry immediately after saving');
  $this
    ->assertEqual($file->fid, $u[0]->fid, 'usage entry should have fid ' . $file->fid);
  $this
    ->assertEqual('file', $u[0]->module, 'usage entry should have module file');
  $this
    ->assertEqual('node', $u[0]->type, 'usage entry should have type node');
  $this
    ->assertEqual($node->nid, $u[0]->id, 'usage entry should have id ' . $node->nid);
  $this
    ->assertEqual(1, $u[0]->count, 'usage entry should have count 1');

  // Check usage for converted video and thumbnails
  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 . ' immediately after saving');
    if (count($u) == 0) {
      continue;
    }
    $this
      ->assertEqual('node', $u[0]->type, 'usage entry for derived file ' . $df->fid . ' should have type node');
    $this
      ->assertEqual($node->nid, $u[0]->id, 'usage entry for derived file ' . $df->fid . ' should have id ' . $node->nid);
  }
}