public function FeedsMapperTaxonomyTest::testSearchByGUID in Feeds 8.2
Tests mapping to a taxonomy term's guid.
File
- lib/
Drupal/ feeds/ Tests/ FeedsMapperTaxonomyTest.php, line 253 - Test case for taxonomy mapper mappers/taxonomy.inc.
Class
- FeedsMapperTaxonomyTest
- Class for testing Feeds <em>content</em> mapper.
Namespace
Drupal\feeds\TestsCode
public function testSearchByGUID() {
// Create 10 terms. The first one was created in setup.
$tids = array(
1,
);
foreach (range(2, 10) as $i) {
$term = entity_create('taxonomy_term', array(
'name' => 'term' . $i,
'vid' => 'tags',
));
$term
->save();
$tids[] = $term
->id();
}
// 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();
$entityNG = entity_create('node', array(
'type' => 'article',
))
->getNGEntity();
$entity = $entityNG
->getBCEntity();
$target = 'field_tags';
$mapping = array(
'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_GUID,
);
taxonomy_feeds_set_target(NULL, $entity, $target, $guids, $mapping);
$this
->assertEqual(count($entityNG->field_tags), 10);
foreach ($entityNG->field_tags as $delta => $values) {
$this
->assertEqual($tids[$delta], $values->tid, 'Correct term id foud.');
}
// Test a second mapping with a bogus term id.
taxonomy_feeds_set_target(NULL, $entity, $target, array(
1234,
), $mapping);
$this
->assertEqual(count($entityNG->field_tags), 10);
foreach ($entityNG->field_tags as $delta => $values) {
$this
->assertEqual($tids[$delta], $values->tid, 'Correct term id foud.');
}
}