123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- class UpgradePathTaxonomyTestCase extends UpgradePathTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Taxonomy upgrade path',
- 'description' => 'Taxonomy upgrade path tests.',
- 'group' => 'Upgrade path',
- );
- }
- public function setUp() {
-
- $this->databaseDumpFiles = array(
- drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
- );
- parent::setUp();
- }
-
- function instanceVocabularies($entity_type, $bundle) {
- $instances = array();
- foreach (field_info_instances($entity_type, $bundle) as $instance) {
- $field = field_info_field($instance['field_name']);
- if ($field['type'] == 'taxonomy_term_reference') {
- foreach ($field['settings']['allowed_values'] as $tree) {
-
-
- if (empty($instances[$tree['vocabulary']]) || $instances[$tree['vocabulary']] == 'taxonomyextra') {
- $instances[$tree['vocabulary']] = $field['field_name'];
- }
- }
- }
- }
- return $instances;
- }
-
- public function testTaxonomyUpgrade() {
- $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
-
- $this->drupalGet('');
-
-
- $this->assertFalse(db_table_exists('taxonomy_vocabulary_node_type'), 'taxonomy_vocabulary_node_type has been removed.');
- $this->assertFalse(db_table_exists('taxonomy_term_node'), 'taxonomy_term_node has been removed.');
-
- $nids = db_query('SELECT nid from {node} WHERE status = :status', array(':status' => NODE_NOT_PUBLISHED))->fetchCol();
- $indexed_nids = db_query('SELECT DISTINCT nid from {taxonomy_index}')->fetchCol();
- $this->assertFalse(array_intersect($nids, $indexed_nids), 'No unpublished nid present in taxonomy_index');
-
-
- $voc_keys = array();
- foreach (taxonomy_get_vocabularies() as $vocab) {
- $voc_keys[] = $vocab->machine_name;
- }
- $instances = $this->instanceVocabularies('node', 'page');
- $inst_keys = array_keys($instances);
- sort($voc_keys);
- sort($inst_keys);
- $this->assertEqual($voc_keys, $inst_keys, 'Node type page has instances for every vocabulary.');
-
- foreach (array_unique($instances) as $instance) {
- $field_instance = field_info_instance('node', $instance, 'page');
- $this->assertTrue(isset($field_instance['required']), 'The required setting was preserved during the upgrade path.');
- $this->assertTrue($field_instance['description'], 'The description was preserved during the upgrade path');
- }
-
-
-
-
- $instances = $this->instanceVocabularies('node', 'story');
- $field_names = array_flip($instances);
- $this->assertEqual(count($field_names), 1, 'Only one taxonomy term field instance exists for story nodes');
- $this->assertEqual(key($field_names), 'taxonomyextra', 'Only the excess taxonomy term field is used on story nodes');
-
-
- $instances = $this->instanceVocabularies('node', 'poll');
- $this->assertTrue(empty($instances), 'Node type poll has no taxonomy term reference field instances.');
-
-
-
- $nodes = node_load_multiple(array(), array('type' => 'page'));
- $nodes += node_load_multiple(array(), array('type' => 'story'));
- $terms = db_select('taxonomy_term_data', 'td')
- ->fields('td')
- ->orderBy('vid')
- ->orderBy('tid')
- ->execute()
- ->fetchAllAssoc('tid');
- field_attach_prepare_view('node', $nodes, 'full');
- foreach ($nodes as $nid => $node) {
- $node->content = field_attach_view('node', $node, 'full');
- $render = drupal_render($node->content);
- $this->drupalSetContent($render);
- $this->verbose($render);
- $vocabulary_seen = array();
- foreach ($terms as $tid => $term) {
-
-
-
- $should_be_displayed = ($tid != $nid) && ($tid + $nid != 49);
-
-
-
-
- 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';
- }
-
-
- 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(
- '%name' => $term->name,
- '@field' => $field_class,
- '%nid' => $nid,
- );
-
-
-
- $term_path = url('taxonomy/term/' . $term->tid);
- if (!$should_be_displayed) {
-
- $links = $this->xpath('//a[@href=:term_path]', array(':term_path' => $term_path));
- $this->assertFalse($links, format_string('Term %name (@field) is not displayed on node %nid', $args));
- }
- else {
-
-
-
- $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, format_string('Term %name (@field) is displayed on node %nid', $args));
- }
- }
-
-
- if ($node->nid == 1) {
- $link = l($term->name, 'taxonomy/term/0');
- $this->assertNoRaw($link, format_string('Bogus term (tid 0) is not displayed on node 1 vid %old_vid.', $args));
- }
-
-
-
- $revisions = node_revision_list($node);
- if ($node->nid < 13) {
- $this->assertEqual(count($revisions), 2, format_string('Node %nid has two revisions.', $args));
- $last_rev = end($revisions);
- $args['%old_vid'] = $last_rev->vid;
- $node_old = node_load($node->nid, $last_rev->vid);
- field_attach_prepare_view('node', array($node_old->nid => $node_old), 'full');
- $node_old->content = field_attach_view('node', $node_old, 'full');
- $render = drupal_render($node_old->content);
- $this->drupalSetContent($render);
- $this->verbose($render);
- $term = $terms[$node->nid];
- $link = l($term->name, 'taxonomy/term/' . $term->tid);
- $this->assertRaw($link, format_string('Term %name (@field) is displayed on node %nid vid %old_vid.', $args));
- $term = $terms[49-$node->nid];
- $link = l($term->name, 'taxonomy/term/' . $term->tid);
- $this->assertRaw($link, format_string('Term %name (@field) is displayed on node %nid %old_vid.', $args));
- }
- else {
- $this->assertEqual(count($revisions), 1, format_string('Node %nid has one revision.', $args));
- }
- }
- }
- }
|