Skip to content
Snippets Groups Projects
Commit 4846c3cd authored by Chris Leppanen's avatar Chris Leppanen
Browse files

Tests for #1019688.

parent 9b828bb6
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter ...@@ -98,7 +98,7 @@ abstract class FeedsPlugin extends FeedsConfigurable implements FeedsSourceInter
* *
* @todo: Use CTools Plugin API. * @todo: Use CTools Plugin API.
*/ */
protected static function loadMappers() { public static function loadMappers() {
static $loaded = FALSE; static $loaded = FALSE;
if (!$loaded) { if (!$loaded) {
$path = drupal_get_path('module', 'feeds') . '/mappers'; $path = drupal_get_path('module', 'feeds') . '/mappers';
......
...@@ -112,7 +112,7 @@ class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase { ...@@ -112,7 +112,7 @@ class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase {
} }
/** /**
* Test inheriting taxonomy from the feed node. * Tests inheriting taxonomy from the feed node.
*/ */
function testInheritTaxonomy() { function testInheritTaxonomy() {
...@@ -152,120 +152,165 @@ class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase { ...@@ -152,120 +152,165 @@ class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase {
} }
/** /**
* Test aggregating RSS categories to taxonomy. * Tests searching taxonomy terms by name.
*/ */
/* public function testSearchByName() {
function testRSSCategoriesToTaxonomy() {
// Add mapping to tags vocabulary.
$this->addMappings('syndication',
array(
array(
'source' => 'tags',
'target' => 'taxonomy:1',
),
)
);
// Aggregate feed node with "Tag" vocabulary.
$nid = $this->createFeedNode();
// Assert 10 items aggregated after creation of the node.
$this->assertText('Created 10 nodes');
// There should be 30 terms and 44 term-node relations.
$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.");
// Take a look at the actual terms on frontpage.
$this->drupalGet('node');
$terms = array( $terms = array(
'authentication',
'custom mapping',
'data visualization',
'Drupal', 'Drupal',
'Drupal planet',
'faceted search',
'GeoDC',
'graphs',
'interface',
'intranet',
'localization', 'localization',
'localization client', 'localization client',
'localization server', 'localization server',
'map-basec browser',
'mapbox',
'microfinance',
'MIX Market',
'open atrium', 'open atrium',
'open data',
'open source',
'Peru',
'salesforce',
'siteminder',
'siteminder module',
'software freedom day',
'translation', 'translation',
'translation server', 'translation server',
'usability', 'Drupal planet',
'Washington DC',
'World Bank',
); );
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
'skip_hash_check' => TRUE,
'update_existing' => 2,
));
$mappings = array(
5 => array(
'source' => 'tags',
'target' => 'field_tags',
'term_search' => 0,
),
);
$this->addMappings('syndication', $mappings);
$nid = $this->createFeedNode('syndication', NULL, 'Syndication');
$this->assertText('Created 10 nodes.');
// Check that terms we not auto-created.
$this->drupalGet('node/2');
foreach ($terms as $term) {
$this->assertNoTaxonomyTerm($term);
}
$this->drupalGet('node/3');
$this->assertNoTaxonomyTerm('Washington DC');
// Change the mapping configuration.
$this->removeMappings('syndication', $mappings);
// Turn on autocreate.
$mappings[5]['autocreate'] = TRUE;
$this->addMappings('syndication', $mappings);
$this->drupalPost('node/' . $nid . '/import', array(), t('Import'));
$this->assertText('Updated 10 nodes.');
$this->drupalGet('node/2');
foreach ($terms as $term) { foreach ($terms as $term) {
$this->assertTaxonomyTerm($term); $this->assertTaxonomyTerm($term);
} }
$this->drupalGet('node/3');
$this->assertTaxonomyTerm('Washington DC');
// Delete all items, all associations are gone. $names = db_query('SELECT name FROM {taxonomy_term_data}')->fetchCol();
$this->drupalPost("node/$nid/delete-items", array(), 'Delete'); $this->assertEqual(count($names), 31, 'Found correct number of terms in the database.');
$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.");
// Remove "Tag" setting, import again. // Run import again. This verifys that the terms we found by name.
$edit = array( $this->drupalPost('node/' . $nid . '/import', array(), t('Import'));
'tags' => FALSE, $this->assertText('Updated 10 nodes.');
); $names = db_query('SELECT name FROM {taxonomy_term_data}')->fetchCol();
$this->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save'); $this->assertEqual(count($names), 31, 'Found correct number of terms in the database.');
$this->drupalPost("node/$nid/import", array(), 'Import'); }
$this->assertText('Created 10 nodes');
// We should only get one term-node association per node. /**
$this->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")->fetchField(), "Found correct number of terms."); * Tests mapping to taxonomy terms by tid.
$this->assertEqual(10, db_query("SELECT count(*) FROM {term_node}")->fetchField(), "Found correct number of term-node relations."); */
public function testSearchByID() {
// Create 10 terms. The first one was created in setup.
$terms = array(1);
foreach (range(2, 10) as $i) {
$term = (object) array(
'name' => 'term' . $i,
'vid' => 1,
);
taxonomy_term_save($term);
$terms[] = $term->tid;
}
// Delete all items. FeedsPlugin::loadMappers();
$this->drupalPost("node/$nid/delete-items", array(), 'Delete');
// Set vocabulary to multiple terms, import again. $entity = new stdClass();
$edit = array( $target = 'field_tags';
'multiple' => TRUE, $mapping = array(
'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_ID,
); );
$this->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save');
$this->drupalPost("node/$nid/import", array(), 'Import');
$this->assertText('Created 10 nodes');
// We should get all term-node associations again. taxonomy_feeds_set_target(NULL, $entity, $target, $terms, $mapping);
$this->assertEqual(30, db_query("SELECT count(*) FROM {term_data}")->fetchField(), "Found correct number of terms."); $this->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
$this->assertEqual(44, db_query("SELECT count(*) FROM {term_node}")->fetchField(), "Found correct number of term-node relations.");
// Delete all items. // Test a second mapping with a bogus term id.
$this->drupalPost("node/$nid/delete-items", array(), 'Delete'); taxonomy_feeds_set_target(NULL, $entity, $target, array(1234), $mapping);
$this->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
}
// Remove a term, import again. /**
$this->drupalPost('admin/content/taxonomy/edit/term/1', array(), 'Delete'); * Tests mapping to a taxonomy term's guid.
$this->drupalPost(NULL, array(), 'Delete'); */
$this->assertText('Deleted term'); public function testSearchByGUID() {
$this->drupalPost("node/$nid/import", array(), 'Import'); // Create 10 terms. The first one was created in setup.
$this->assertText('Created 10 nodes'); $tids = array(1);
foreach (range(2, 10) as $i) {
$term = (object) array(
'name' => 'term' . $i,
'vid' => 1,
);
taxonomy_term_save($term);
$tids[] = $term->tid;
}
// Create a bunch of bogus imported terms.
$guids = array();
foreach ($tids as $tid) {
$guid = 100 * $tid;
$guids[] = $guid;
$record = array(
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'id' => 'does_not_exist',
'feed_nid' => 0,
'imported' => REQUEST_TIME,
'url' => '',
'guid' => $guid,
);
drupal_write_record('feeds_item', $record);
}
FeedsPlugin::loadMappers();
$entity = new stdClass();
$target = 'field_tags';
$mapping = array(
'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_GUID,
);
taxonomy_feeds_set_target(NULL, $entity, $target, $guids, $mapping);
$this->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
foreach ($entity->field_tags[LANGUAGE_NONE] as $delta => $values) {
$this->assertEqual($tids[$delta], $values['tid'], 'Correct term id foud.');
}
// This term should now be missing from term-node associations. // Test a second mapping with a bogus term id.
$this->assertEqual(29, db_query("SELECT count(*) FROM {term_data}")->fetchField(), "Found correct number of terms."); taxonomy_feeds_set_target(NULL, $entity, $target, array(1234), $mapping);
$this->assertEqual(39, db_query("SELECT count(*) FROM {term_node}")->fetchField(), "Found correct number of term-node relations."); $this->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
foreach ($entity->field_tags[LANGUAGE_NONE] as $delta => $values) {
$this->assertEqual($tids[$delta], $values['tid'], 'Correct term id foud.');
}
} }
*/
/** /**
* Helper, finds node style taxonomy term markup in DOM. * Finds node style taxonomy term markup in DOM.
*/ */
public function assertTaxonomyTerm($term) { public function assertTaxonomyTerm($term) {
$term = check_plain($term); $term = check_plain($term);
$this->assertPattern('/<a href="\/.*taxonomy\/term\/[0-9]+">' . $term . '<\/a>/', 'Found ' . $term); $this->assertPattern('/<a href="\/.*taxonomy\/term\/[0-9]+">' . $term . '<\/a>/', 'Found ' . $term);
} }
/**
* Asserts that the term does not exist on a node page.
*/
public function assertNoTaxonomyTerm($term) {
$term = check_plain($term);
$this->assertNoPattern('/<a href="\/.*taxonomy\/term\/[0-9]+">' . $term . '<\/a>/', 'Did not find ' . $term);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment