function FeedsMapperFieldTest::test in Feeds 8.2
Basic test loading a double entry CSV file.
File
- lib/
Drupal/ feeds/ Tests/ FeedsMapperFieldTest.php, line 39 - Test case for simple CCK field mapper mappers/content.inc.
Class
- FeedsMapperFieldTest
- Class for testing Feeds field mapper.
Namespace
Drupal\feeds\TestsCode
function test() {
// Create content type.
$typename = $this
->createContentType(array(), array(
'alpha' => 'text',
'beta' => 'number_integer',
'gamma' => 'number_decimal',
'delta' => 'number_float',
));
// Create and configure importer.
$this
->createImporterConfiguration('Content CSV', 'csv');
$this
->setSettings('csv', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this
->setPlugin('csv', 'file');
$this
->setPlugin('csv', 'csv');
$this
->setSettings('csv', 'node', array(
'bundle' => $typename,
));
$this
->addMappings('csv', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
1 => array(
'source' => 'created',
'target' => 'created',
),
2 => array(
'source' => 'body',
'target' => 'body',
),
3 => array(
'source' => 'alpha',
'target' => 'field_alpha',
),
4 => array(
'source' => 'beta',
'target' => 'field_beta',
),
5 => array(
'source' => 'gamma',
'target' => 'field_gamma',
),
6 => array(
'source' => 'delta',
'target' => 'field_delta',
),
));
// Import CSV file.
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content.csv');
$this
->assertText('Created 2 nodes');
// Check the two imported files.
$this
->drupalGet('node/1/edit');
$this
->assertNodeFieldValue('alpha', 'Lorem');
$this
->assertNodeFieldValue('beta', '42');
$this
->assertNodeFieldValue('gamma', '4.20');
$this
->assertNodeFieldValue('delta', '3.14159');
$this
->drupalGet('node/2/edit');
$this
->assertNodeFieldValue('alpha', 'Ut wisi');
$this
->assertNodeFieldValue('beta', '32');
$this
->assertNodeFieldValue('gamma', '1.20');
$this
->assertNodeFieldValue('delta', '5.62951');
}