Commit 8e4d4ec6 authored by webchick's avatar webchick

#933270 by Damien Tournoud, catch: Fixed Taxonomy terms are incorrectly put in...

#933270 by Damien Tournoud, catch: Fixed Taxonomy terms are incorrectly put in the 'Taxonomy upgrade vocabulary' in some cases. (beta blocker)
parent 1af46189
...@@ -90,6 +90,8 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase { ...@@ -90,6 +90,8 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase {
$nodes += node_load_multiple(array(), array('type' => 'story')); $nodes += node_load_multiple(array(), array('type' => 'story'));
$terms = db_select('taxonomy_term_data', 'td') $terms = db_select('taxonomy_term_data', 'td')
->fields('td') ->fields('td')
->orderBy('vid')
->orderBy('tid')
->execute() ->execute()
->fetchAllAssoc('tid'); ->fetchAllAssoc('tid');
field_attach_prepare_view('node', $nodes, 'full'); field_attach_prepare_view('node', $nodes, 'full');
...@@ -98,22 +100,56 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase { ...@@ -98,22 +100,56 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase {
$render = drupal_render($node->content); $render = drupal_render($node->content);
$this->drupalSetContent($render); $this->drupalSetContent($render);
$this->verbose($render); $this->verbose($render);
$vocabulary_seen = array();
foreach ($terms as $tid => $term) { foreach ($terms as $tid => $term) {
// In our test database, each node is arbitrary associated with all
// terms except two: one whose tid is ($nid) and one whose tid is
// (49 - $nid).
$should_be_displayed = ($tid != $nid) && ($tid + $nid != 49);
// Only vocabularies 13 to 24 are properly associated with the node
// type 'page'. All other node types are not associated with any
// vocabulary, but still are associated with terms. Those terms
// will be moved to the taxonomy extra field.
if ($node->type == 'page' && $term->vid >= 13 && $term->vid <= 24) {
$vocabulary = taxonomy_vocabulary_load($term->vid);
$field_class = 'field-name-' . strtr('taxonomy_' . $vocabulary->machine_name, '_', '-');;
}
else {
$field_class = 'field-name-taxonomyextra';
}
// Odd vocabularies are single, so any additional term will be moved
// to the taxonomy extra field.
if ($should_be_displayed) {
if ($term->vid % 2 == 1 && !empty($vocabulary_seen[$term->vid])) {
$field_class = 'field-name-taxonomyextra';
}
$vocabulary_seen[$term->vid] = TRUE;
}
$args = array( $args = array(
'%name' => $term->name, '%name' => $term->name,
'@tid' => $tid, '@field' => $field_class,
'%nid' => $nid, '%nid' => $nid,
); );
// Use link rather than term name because migrated term names can be // Use link rather than term name because migrated term names can be
// substrings of other term names. e.g. "term 1 of vocabulary 2" is // substrings of other term names. e.g. "term 1 of vocabulary 2" is
// found when "term 1 of vocabulary 20" is output. // found when "term 1 of vocabulary 20" is output.
$link = l($term->name, 'taxonomy/term/' . $term->tid); $term_path = url('taxonomy/term/' . $term->tid);
if (($tid == $nid) || ($tid + $nid == 49)) { if (!$should_be_displayed) {
$this->assertNoRaw($link, t('Term %name (@tid) is not displayed on node %nid', $args)); // Look for any link with the term path.
$links = $this->xpath('//a[@href=:term_path]', array(':term_path' => $term_path));
$this->assertFalse($links, t('Term %name (@field) is not displayed on node %nid', $args));
} }
else { else {
$this->assertRaw($link, t('Term %name (@tid) is displayed on node %nid', $args)); // Look for a link with the term path inside the correct field.
// We search for "SPACE + class + SPACE" to avoid matching a substring
// of the class.
$links = $this->xpath('//div[contains(concat(" ", normalize-space(@class), " "), :field_class)]//a[@href=:term_path]', array(':field_class' => ' ' . $field_class . ' ', ':term_path' => $term_path));
$this->assertTrue($links, t('Term %name (@field) is displayed on node %nid', $args));
} }
} }
...@@ -142,10 +178,10 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase { ...@@ -142,10 +178,10 @@ class UpgradePathTaxonomyTestCase extends UpgradePathTestCase {
$term = $terms[$node->nid]; $term = $terms[$node->nid];
$link = l($term->name, 'taxonomy/term/' . $term->tid); $link = l($term->name, 'taxonomy/term/' . $term->tid);
$this->assertRaw($link, t('Term %name (@tid) is displayed on node %nid vid %old_vid.', $args)); $this->assertRaw($link, t('Term %name (@field) is displayed on node %nid vid %old_vid.', $args));
$term = $terms[49-$node->nid]; $term = $terms[49-$node->nid];
$link = l($term->name, 'taxonomy/term/' . $term->tid); $link = l($term->name, 'taxonomy/term/' . $term->tid);
$this->assertRaw($link, t('Term %name (@tid) is displayed on node %nid %old_vid.', $args)); $this->assertRaw($link, t('Term %name (@field) is displayed on node %nid %old_vid.', $args));
} }
else { else {
$this->assertEqual(count($revisions), 1, t('Node %nid has one revision.', $args)); $this->assertEqual(count($revisions), 1, t('Node %nid has one revision.', $args));
......
...@@ -647,8 +647,11 @@ function taxonomy_update_7005(&$sandbox) { ...@@ -647,8 +647,11 @@ function taxonomy_update_7005(&$sandbox) {
// use the previous deltas to calculate the next delta. // use the previous deltas to calculate the next delta.
if ($record->vid == $values[2]) { if ($record->vid == $values[2]) {
// see field_default_validate(). // For limited cardinality fields, the delta must not be allowed to
if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ($deltas[$field_name] + 1) >= $field['cardinality']) { // exceed the cardinality during the update. So ensure that the
// delta about to be inserted is within this limit.
// @see field_default_validate().
if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ($deltas[$field_name] + 1) > $field['cardinality']) {
// For excess values of a single-term vocabulary, switch over to // For excess values of a single-term vocabulary, switch over to
// the overflow field. // the overflow field.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment