You are here

public function FeedsMapperFileTestCase::testImages in Feeds 7.2

Tests mapping to an image field.

File

tests/feeds_mapper_file.test, line 644
Contains FeedsMapperFileTestCase.

Class

FeedsMapperFileTestCase
Test case for Filefield mapper mappers/filefield.inc.

Code

public function testImages() {
  variable_set('feeds_never_use_curl', TRUE);
  $typename = $this
    ->createContentType(array(), array(
    'images' => 'image',
  ));

  // Enable title and alt mapping.
  $edit = array(
    'instance[settings][alt_field]' => 1,
    'instance[settings][title_field]' => 1,
  );
  $this
    ->drupalPost("admin/structure/types/manage/{$typename}/fields/field_images", $edit, t('Save settings'));

  // Create a CSV importer configuration.
  $this
    ->createImporterConfiguration('Node import from CSV', 'image_test');
  $this
    ->setPlugin('image_test', 'FeedsCSVParser');
  $this
    ->setSettings('image_test', 'FeedsNodeProcessor', array(
    'bundle' => $typename,
  ));
  $this
    ->setSettings('image_test', NULL, array(
    'content_type' => '',
  ));
  $this
    ->addMappings('image_test', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
    ),
    1 => array(
      'source' => 'file',
      'target' => 'field_images:uri',
    ),
    2 => array(
      'source' => 'title2',
      'target' => 'field_images:title',
    ),
    3 => array(
      'source' => 'alt',
      'target' => 'field_images:alt',
    ),
  ));

  // Import.
  $edit = array(
    'feeds[FeedsHTTPFetcher][source]' => url('testing/feeds/files-remote.csv', array(
      'absolute' => TRUE,
    )),
  );
  $this
    ->drupalPost('import/image_test', $edit, 'Import');
  $this
    ->assertText('Created 5 nodes');

  // Assert files exist.
  $files = $this
    ->listTestFiles();
  $entities = db_select('feeds_item')
    ->fields('feeds_item', array(
    'entity_id',
  ))
    ->condition('id', 'image_test')
    ->execute();
  foreach ($entities as $i => $entity) {
    $this
      ->drupalGet('node/' . $entity->entity_id . '/edit');
    $this
      ->assertRaw(str_replace(' ', '_', array_shift($files)));
    $this
      ->assertRaw("Alt text {$i}");
    $this
      ->assertRaw("Title text {$i}");
  }
}