View source
<?php
require_once drupal_get_path('module', 'feeds') . '/tests/feeds_mapper_test.inc';
class FeedsMapperContentTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => t('Mapper: Content'),
'description' => t('Test Feeds Mapper support for CCK fields. <strong>Requires CCK module</strong>.'),
'group' => t('Feeds'),
);
}
function setUp() {
parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler', 'content', 'number', 'text');
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer content types',
'administer feeds',
'administer nodes',
'administer site configuration',
)));
}
function test() {
$typename = $this
->createContentType(NULL, array(
'alpha' => 'text',
'beta' => 'number_integer',
'gamma' => 'number_decimal',
'delta' => 'number_float',
));
$this
->createImporterConfiguration('Content CSV', 'csv');
$this
->setSettings('csv', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this
->setPlugin('csv', 'FeedsFileFetcher');
$this
->setPlugin('csv', 'FeedsCSVParser');
$this
->setSettings('csv', 'FeedsNodeProcessor', array(
'content_type' => $typename,
));
$this
->addMappings('csv', array(
array(
'source' => 'title',
'target' => 'title',
),
array(
'source' => 'created',
'target' => 'created',
),
array(
'source' => 'body',
'target' => 'body',
),
array(
'source' => 'alpha',
'target' => 'field_alpha',
),
array(
'source' => 'beta',
'target' => 'field_beta',
),
array(
'source' => 'gamma',
'target' => 'field_gamma',
),
array(
'source' => 'delta',
'target' => 'field_delta',
),
));
$this
->importFile('csv', $this
->absolutePath() . '/tests/feeds/content.csv');
$this
->assertText('Created 2 ' . $typename . ' nodes.');
$this
->drupalGet('node/1/edit');
$this
->assertCCKFieldValue('alpha', 'Lorem');
$this
->assertCCKFieldValue('beta', '42');
$this
->assertCCKFieldValue('gamma', '4.20');
$this
->assertCCKFieldValue('delta', '3.14159');
$this
->drupalGet('node/2/edit');
$this
->assertCCKFieldValue('alpha', 'Ut wisi');
$this
->assertCCKFieldValue('beta', '32');
$this
->assertCCKFieldValue('gamma', '1.20');
$this
->assertCCKFieldValue('delta', '5.62951');
}
}