-
Chris Leppanen authoredChris Leppanen authored
feeds_processor_term.test 2.83 KiB
<?php
/**
* @file
* Tests for plugins/FeedsTermProcessor.inc
*/
/**
* Test aggregating a feed as data records.
*/
class FeedsCSVtoTermsTest extends FeedsWebTestCase {
public static function getInfo() {
return array(
'name' => 'CSV import to taxonomy',
'description' => 'Tests a standalone import configuration that uses file fetcher and CSV parser to import taxonomy terms from a CSV file.',
'group' => 'Feeds',
);
}
/**
* Test node creation, refreshing/deleting feeds and feed items.
*/
public function test() {
// Create an importer.
$this->createImporterConfiguration('Term import', 'term_import');
// Set and configure plugins and mappings.
$this->setPlugin('term_import', 'FeedsFileFetcher');
$this->setPlugin('term_import', 'FeedsCSVParser');
$this->setPlugin('term_import', 'FeedsTermProcessor');
$mappings = array(
0 => array(
'source' => 'name',
'target' => 'name',
'unique' => 1,
),
);
$this->addMappings('term_import', $mappings);
// Use standalone form.
$edit = array(
'content_type' => '',
);
$this->drupalPost('admin/structure/feeds/term_import/settings', $edit, 'Save');
$edit = array(
'name' => 'Addams vocabulary',
'machine_name' => 'addams',
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$edit = array(
'vocabulary' => 'addams',
);
$this->drupalPost('admin/structure/feeds/term_import/settings/FeedsTermProcessor', $edit, t('Save'));
// Import and assert.
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Created 5 terms');
$this->drupalGet('admin/structure/taxonomy/addams');
$this->assertText('Morticia');
$this->assertText('Fester');
$this->assertText('Gomez');
$this->assertText('Pugsley');
// Import again.
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('There are no new terms.');
// Force update.
$this->setSettings('term_import', 'FeedsTermProcessor', array(
'skip_hash_check' => TRUE,
'update_existing' => 2,
));
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
$this->assertText('Updated 5 terms.');
// Add a term manually, delete all terms, this term should still stand.
$edit = array(
'name' => 'Cousin Itt',
);
$this->drupalPost('admin/structure/taxonomy/addams/add', $edit, t('Save'));
$this->drupalPost('import/term_import/delete-items', array(), t('Delete'));
$this->drupalGet('admin/structure/taxonomy/addams');
$this->assertText('Cousin Itt');
$this->assertNoText('Morticia');
$this->assertNoText('Fester');
$this->assertNoText('Gomez');
$this->assertNoText('Pugsley');
}
}