You are here

public function VideoFieldTestCase::testSaveVideoFieldItemTwice in Video 7.2

Tests saving a new video and adding it to two different nodes

File

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

Class

VideoFieldTestCase
Tests for the the Video field type

Code

public function testSaveVideoFieldItemTwice() {

  // Build test data
  $file = $this
    ->createFile('file2.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);

  // Check queue result
  $queues = $this
    ->getQueues($file->fid);
  $this
    ->assertEqual(1, count($queues), 'One video_queue entry should be present');
  $queue = array_shift($queues);
  $node1 = node_load($node1->nid);
  $this
    ->transcodeVideo($node1, $queue->vid, $file->fid);
  $node2 = node_load($node2->nid);

  // @todo the video module should not reference the entity itself because one fid can be associated with multiple entities
  $this
    ->assertEqual($node1->nid, $queue->entity_id, 'video_queue entry should entity_id ' . $node1->nid);

  // Two usage entries for the video
  $u = $this
    ->getFileUsage($file->fid);
  $this
    ->assertEqual(2, count($u), 'There should be two usage entries immediately after saving');

  // First usage row
  $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($node1->nid, $u[0]->id, 'usage entry should have id ' . $node1->nid);
  $this
    ->assertEqual(1, $u[0]->count, 'usage entry should have count 1');

  // Second usage row
  $this
    ->assertEqual($file->fid, $u[1]->fid, 'usage entry should have fid ' . $file->fid);
  $this
    ->assertEqual('file', $u[1]->module, 'usage entry should have module file');
  $this
    ->assertEqual('node', $u[1]->type, 'usage entry should have type node');
  $this
    ->assertEqual($node2->nid, $u[1]->id, 'usage entry should have id ' . $node2->nid);
  $this
    ->assertEqual(1, $u[1]->count, 'usage entry should have count 1');
}