public function FeedsMapperFormatConfig::test in Feeds 7.2
Basic test for setting mapping configuration.
File
- tests/
feeds_mapper_format_config.test, line 34 - Contains FeedsMapperFormatConfig.
Class
- FeedsMapperFormatConfig
- Class for testing "Text format" mapping configuration on text fields.
Code
public function test() {
// Create content type with three fields. Two that support text formats
// and one that doesn't.
$typename = $this
->createContentType(array(), array(
'alpha' => array(
'type' => 'text',
'instance_settings' => array(
'instance[settings][text_processing]' => 1,
),
),
'beta' => array(
'type' => 'text_long',
'instance_settings' => array(
'instance[settings][text_processing]' => 1,
),
),
'gamma' => array(
'type' => 'text',
'instance_settings' => array(
'instance[settings][text_processing]' => 0,
),
),
));
// Create a new filter format.
$format = drupal_strtolower($this
->randomName());
$edit = array(
'format' => $format,
'name' => $this
->randomName(),
// Authenticated users.
'roles[2]' => TRUE,
);
$this
->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
// Create and configure importer.
$this
->createImporterConfiguration();
$this
->setSettings('syndication', NULL, array(
'content_type' => '',
));
$this
->setPlugin('syndication', 'FeedsFileFetcher');
$this
->setPlugin('syndication', 'FeedsCSVParser');
$this
->setSettings('syndication', 'FeedsNodeProcessor', array(
'bundle' => $typename,
));
$this
->addMappings('syndication', array(
0 => array(
'source' => 'title',
'target' => 'title',
),
1 => array(
'source' => 'created',
'target' => 'created',
),
2 => array(
'source' => 'body',
'target' => 'body',
'format' => $format,
),
3 => array(
'source' => 'alpha',
'target' => 'field_alpha',
'format' => $format,
),
4 => array(
'source' => 'beta',
'target' => 'field_beta',
'format' => $format,
),
5 => array(
'source' => 'gamma',
'target' => 'field_gamma',
),
));
// Assert that for the gamma field no format can be chosen.
$this
->assertNoText('Text format: Plain text');
// Import csv file.
$this
->importFile('syndication', $this
->absolutePath() . '/tests/feeds/content.csv');
$this
->assertText('Created 2 nodes');
// Assert that fields body, alpha and beta got the expected text format.
$node = node_load(1);
$this
->assertEqual($format, $node->body[LANGUAGE_NONE][0]['format'], 'The body field got the expected format.');
$this
->assertEqual($format, $node->field_alpha[LANGUAGE_NONE][0]['format'], 'The alpha field got the expected format.');
$this
->assertEqual($format, $node->field_beta[LANGUAGE_NONE][0]['format'], 'The beta field got the expected format.');
$this
->assertEqual(filter_fallback_format(), $node->field_gamma[LANGUAGE_NONE][0]['format'], 'The gama field got the expected format.');
}