You are here

public function MediaFeedsMappingTestCase::testFileFieldMapping in Media Feeds 7.2

Tests mapping to a file field.

File

./media_feeds.test, line 63
Tests for the Media Feeds module.

Class

MediaFeedsMappingTestCase
Tests mapping to different field types.

Code

public function testFileFieldMapping() {
  global $base_url;
  $this
    ->drupalLogin($this->admin_user);

  // Create a content type with a file field.
  $content_type = $this
    ->createContentType(array(), array(
    'alpha' => array(
      'type' => 'file',
      'widget' => 'media_generic',
    ),
  ));

  // Create a CSV importer configuration.
  $this
    ->createImporterConfiguration('Node import from CSV', 'node');
  $this
    ->setPlugin('node', 'FeedsCSVParser');
  $this
    ->setSettings('node', 'FeedsNodeProcessor', array(
    'content_type' => $content_type,
  ));
  $this
    ->addMappings('node', array(
    array(
      'source' => 'title',
      'target' => 'title',
    ),
    array(
      'source' => 'file',
      'target' => 'field_alpha',
    ),
  ));

  // Import.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => $base_url . '/sites/default/files/sample.csv',
  );
  debug($edit);
  $this
    ->drupalPost('import/node', $edit, 'Import');
  $this
    ->assertText('Created 1 node');

  // Test that the file has been correctly attached.
  $entities = db_select('feeds_item')
    ->fields('feeds_item', array(
    'entity_id',
  ))
    ->condition('id', 'node')
    ->execute();
  foreach ($entities as $entity) {
    $this
      ->drupalGet('node/' . $entity->entity_id . '/edit');
    $this
      ->assertRaw('druplicon.png');
  }
}