Verified Commit 13472d3c authored by Juraj Nemec's avatar Juraj Nemec
Browse files

Issue #2574003 by poker10, stBorchert: Table alias missing in query condition...

Issue #2574003 by poker10, stBorchert: Table alias missing in query condition in taxonomy_select_nodes()
parent 5b004cca
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
name = "Taxonomy module node list tests"
description = "Support module for taxonomy node list related testing."
package = Testing
version = VERSION
core = 7.x
hidden = TRUE
+26 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Dummy module implementing hook_query_TAG_alter.
 */

/**
 * Implements hook_query_TAG_alter().
 */
function taxonomy_nodes_test_query_node_access_alter(QueryAlterableInterface $query) {
  if (variable_get('taxonomy_nodes_test_query_node_access_alter', FALSE)) {
    $taxonomy_index = FALSE;
    foreach ($query->getTables() as $alias => $table) {
      if ($table['table'] == 'taxonomy_index') {
        $taxonomy_index = TRUE;
      }
    }

    if ($taxonomy_index) {
      // Verify that additional data can be added to the default
      // taxonomy_select_nodes() query by altering it.
      $query->leftJoin('taxonomy_term_data', 'ttd', 'ttd.tid = t.tid');
    }
  }
}
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = arr
  }
  $query = db_select('taxonomy_index', 't');
  $query->addTag('node_access');
  $query->condition('tid', $tid);
  $query->condition('t.tid', $tid);
  if ($pager) {
    $count_query = clone $query;
    $count_query->addExpression('COUNT(t.nid)');
+23 −0
Original line number Diff line number Diff line
@@ -1008,6 +1008,29 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
    $this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
  }

  /**
   * Tests that taxonomy term detail page is working even after the default
   * taxonomy_select_nodes() query is altered.
   */
  public function testTaxonomySelectNodesAlter() {
    // Create a new term.
    $term = $this->createTerm($this->vocabulary);

    // Create an article.
    $settings = array(
      'type' => 'article',
      $this->instance['field_name'] => array(LANGUAGE_NONE => array(array('tid' => $term->tid))),
    );
    $this->drupalCreateNode($settings);

    // Check if the taxonomy term detail page is working.
    module_enable(array('taxonomy_nodes_test'));
    variable_set('taxonomy_nodes_test_query_node_access_alter', TRUE);
    $this->drupalGet('taxonomy/term/' . $term->tid);
    $this->assertResponse(200, 'The taxonomy term page is working.');
    variable_set('taxonomy_nodes_test_query_node_access_alter', FALSE);
  }

}

/**