View source
<?php
require_once drupal_get_path('module', 'feeds') . '/tests/feeds_mapper_test.inc';
class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase {
public static function getInfo() {
return array(
'name' => t('Mapper: Taxonomy'),
'description' => t('Test Feeds Mapper support for Taxonomy.'),
'group' => t('Feeds'),
);
}
function setUp() {
parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler', 'taxonomy');
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer content types',
'administer feeds',
'administer nodes',
'administer site configuration',
'administer taxonomy',
)));
$edit = array(
'name' => 'Tags',
'tags' => TRUE,
'nodes[article]' => TRUE,
'nodes[page]' => TRUE,
);
$this
->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, 'Save');
$this
->createImporterConfiguration('Syndication', 'syndication');
$this
->addMappings('syndication', array(
array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'description',
'target' => 'body',
'unique' => FALSE,
),
array(
'source' => 'timestamp',
'target' => 'created',
'unique' => FALSE,
),
array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
));
}
function testInheritTaxonomy() {
$this
->addMappings('syndication', array(
array(
'source' => 'parent:taxonomy:1',
'target' => 'taxonomy:1',
),
));
$edit = array(
'import_on_create' => FALSE,
);
$this
->drupalPost('admin/structure/feeds/edit/syndication/settings', $edit, 'Save');
$this
->assertText('Do not import on create');
$nid = $this
->createFeedNode();
$terms = array(
'testterm1',
'testterm2',
'testterm3',
);
$edit = array(
'taxonomy[tags][1]' => implode(',', $terms),
);
$this
->drupalPost("node/{$nid}/edit", $edit, t('Save'));
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$count = db_query("SELECT COUNT(*) FROM {term_node}")
->fetchField();
$this
->assertEqual(33, $count, 'Found correct number of tags for all feed nodes and feed items.');
foreach ($terms as $term) {
$this
->assertTaxonomyTerm($term);
}
}
function testRSSCategoriesToTaxonomy() {
$this
->addMappings('syndication', array(
array(
'source' => 'tags',
'target' => 'taxonomy:1',
),
));
$nid = $this
->createFeedNode();
$this
->assertText('Created 10 Article nodes.');
$this
->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")
->fetchField(), "Found correct number of terms.");
$this
->assertEqual(44, db_query("SELECT count(*) FROM {term_node}")
->fetchField(), "Found correct number of term-node relations.");
$this
->drupalGet('node');
$terms = array(
'authentication',
'custom mapping',
'data visualization',
'Drupal',
'Drupal planet',
'faceted search',
'GeoDC',
'graphs',
'interface',
'intranet',
'localization',
'localization client',
'localization server',
'map-basec browser',
'mapbox',
'microfinance',
'MIX Market',
'open atrium',
'open data',
'open source',
'Peru',
'salesforce',
'siteminder',
'siteminder module',
'software freedom day',
'translation',
'translation server',
'usability',
'Washington DC',
'World Bank',
);
foreach ($terms as $term) {
$this
->assertTaxonomyTerm($term);
}
$this
->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
$this
->assertText('Deleted 10 nodes.');
$this
->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")
->fetchField(), "Found correct number of terms.");
$this
->assertEqual(0, db_query("SELECT count(*) FROM {term_node}")
->fetchField(), "Found correct number of term-node relations.");
$edit = array(
'tags' => FALSE,
);
$this
->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('Created 10 Article nodes.');
$this
->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")
->fetchField(), "Found correct number of terms.");
$this
->assertEqual(10, db_query("SELECT count(*) FROM {term_node}")
->fetchField(), "Found correct number of term-node relations.");
$this
->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
$edit = array(
'multiple' => TRUE,
);
$this
->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('Created 10 Article nodes.');
$this
->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")
->fetchField(), "Found correct number of terms.");
$this
->assertEqual(44, db_query("SELECT count(*) FROM {term_node}")
->fetchField(), "Found correct number of term-node relations.");
$this
->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
$this
->drupalPost('admin/content/taxonomy/edit/term/1', array(), 'Delete');
$this
->drupalPost(NULL, array(), 'Delete');
$this
->assertText('Deleted term');
$this
->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this
->assertText('Created 10 Article nodes.');
$this
->assertEqual(29, db_query("SELECT count(*) FROM {term_data}")
->fetchField(), "Found correct number of terms.");
$this
->assertEqual(39, db_query("SELECT count(*) FROM {term_node}")
->fetchField(), "Found correct number of term-node relations.");
}
public function assertTaxonomyTerm($term) {
$term = check_plain($term);
$this
->assertPattern('/<a href="(.*?)\\/taxonomy\\/term\\/([0-9]*?)"(.*)>' . $term . '<\\/a>/', 'Found ' . $term);
}
}