public function FeedsMapperFileTest::testImages in Feeds 8.2
Tests mapping to an image field.
File
- lib/
Drupal/ feeds/ Tests/ FeedsMapperFileTest.php, line 172 - Test case for Filefield mapper mappers/filefield.inc.
Class
- FeedsMapperFileTest
- Class for testing Feeds file mapper.
Namespace
Drupal\feeds\TestsCode
public function testImages() {
$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/node.{$typename}.field_images", $edit, t('Save settings'));
// Create a CSV importer configuration.
$this
->createImporterConfiguration('Node import from CSV', 'image_test');
$this
->setPlugin('image_test', 'csv');
$this
->setSettings('image_test', 'node', 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[Drupal\\feeds\\Plugin\\feeds\\fetcher\\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');
$f = new FeedsEnclosure(array_shift($files), NULL);
$this
->assertRaw($f
->getUrlEncodedValue());
$this
->assertRaw("Alt text {$i}");
$this
->assertRaw("Title text {$i}");
}
}