updated core to 7.73
This commit is contained in:
@@ -20,12 +20,15 @@
|
||||
* An array of taxonomy vocabulary objects.
|
||||
*/
|
||||
function hook_taxonomy_vocabulary_load($vocabularies) {
|
||||
foreach ($vocabularies as $vocabulary) {
|
||||
$vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE);
|
||||
$result = db_select('mytable', 'm')
|
||||
->fields('m', array('vid', 'foo'))
|
||||
->condition('m.vid', array_keys($vocabularies), 'IN')
|
||||
->execute();
|
||||
foreach ($result as $record) {
|
||||
$vocabularies[$record->vid]->foo = $record->foo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Act on taxonomy vocabularies before they are saved.
|
||||
*
|
||||
@@ -49,8 +52,8 @@ function hook_taxonomy_vocabulary_presave($vocabulary) {
|
||||
* A taxonomy vocabulary object.
|
||||
*/
|
||||
function hook_taxonomy_vocabulary_insert($vocabulary) {
|
||||
if ($vocabulary->synonyms) {
|
||||
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE);
|
||||
if ($vocabulary->machine_name == 'my_vocabulary') {
|
||||
$vocabulary->weight = 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +66,10 @@ function hook_taxonomy_vocabulary_insert($vocabulary) {
|
||||
* A taxonomy vocabulary object.
|
||||
*/
|
||||
function hook_taxonomy_vocabulary_update($vocabulary) {
|
||||
$status = $vocabulary->synonyms ? TRUE : FALSE;
|
||||
if ($vocabulary->synonyms) {
|
||||
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status);
|
||||
}
|
||||
db_update('mytable')
|
||||
->fields(array('foo' => $vocabulary->foo))
|
||||
->condition('vid', $vocabulary->vid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,9 +82,9 @@ function hook_taxonomy_vocabulary_update($vocabulary) {
|
||||
* A taxonomy vocabulary object.
|
||||
*/
|
||||
function hook_taxonomy_vocabulary_delete($vocabulary) {
|
||||
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
|
||||
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
|
||||
}
|
||||
db_delete('mytable')
|
||||
->condition('vid', $vocabulary->vid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +104,10 @@ function hook_taxonomy_vocabulary_delete($vocabulary) {
|
||||
* An array of term objects, indexed by tid.
|
||||
*/
|
||||
function hook_taxonomy_term_load($terms) {
|
||||
$result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms)));
|
||||
$result = db_select('mytable', 'm')
|
||||
->fields('m', array('tid', 'foo'))
|
||||
->condition('m.tid', array_keys($terms), 'IN')
|
||||
->execute();
|
||||
foreach ($result as $record) {
|
||||
$terms[$record->tid]->foo = $record->foo;
|
||||
}
|
||||
@@ -130,18 +136,12 @@ function hook_taxonomy_term_presave($term) {
|
||||
* A taxonomy term object.
|
||||
*/
|
||||
function hook_taxonomy_term_insert($term) {
|
||||
if (!empty($term->synonyms)) {
|
||||
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
|
||||
if ($synonym) {
|
||||
db_insert('taxonomy_term_synonym')
|
||||
->fields(array(
|
||||
'tid' => $term->tid,
|
||||
'name' => rtrim($synonym),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
db_insert('mytable')
|
||||
->fields(array(
|
||||
'tid' => $term->tid,
|
||||
'foo' => $term->foo,
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,19 +153,10 @@ function hook_taxonomy_term_insert($term) {
|
||||
* A taxonomy term object.
|
||||
*/
|
||||
function hook_taxonomy_term_update($term) {
|
||||
hook_taxonomy_term_delete($term);
|
||||
if (!empty($term->synonyms)) {
|
||||
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
|
||||
if ($synonym) {
|
||||
db_insert('taxonomy_term_synonym')
|
||||
->fields(array(
|
||||
'tid' => $term->tid,
|
||||
'name' => rtrim($synonym),
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
db_update('mytable')
|
||||
->fields(array('foo' => $term->foo))
|
||||
->condition('tid', $term->tid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +169,9 @@ function hook_taxonomy_term_update($term) {
|
||||
* A taxonomy term object.
|
||||
*/
|
||||
function hook_taxonomy_term_delete($term) {
|
||||
db_delete('term_synoynm')->condition('tid', $term->tid)->execute();
|
||||
db_delete('mytable')
|
||||
->condition('tid', $term->tid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +212,7 @@ function hook_taxonomy_term_view($term, $view_mode, $langcode) {
|
||||
* documentation respectively for details.
|
||||
*
|
||||
* @param $build
|
||||
* A renderable array representing the node content.
|
||||
* A renderable array representing the term.
|
||||
*
|
||||
* @see hook_entity_view_alter()
|
||||
*/
|
||||
|
||||
@@ -8,8 +8,7 @@ files[] = taxonomy.module
|
||||
files[] = taxonomy.test
|
||||
configure = admin/structure/taxonomy
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
@@ -448,7 +448,7 @@ function taxonomy_update_7004() {
|
||||
}
|
||||
else {
|
||||
$instance['widget'] = array(
|
||||
'type' => 'select',
|
||||
'type' => 'options_select',
|
||||
'module' => 'options',
|
||||
'settings' => array(),
|
||||
);
|
||||
@@ -492,6 +492,7 @@ function taxonomy_update_7004() {
|
||||
'bundle' => $bundle->type,
|
||||
'settings' => array(),
|
||||
'description' => 'Debris left over after upgrade from Drupal 6',
|
||||
'required' => FALSE,
|
||||
'widget' => array(
|
||||
'type' => 'taxonomy_autocomplete',
|
||||
'module' => 'taxonomy',
|
||||
@@ -557,7 +558,7 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
// of term references stored so far for the current revision, which
|
||||
// provides the delta value for each term reference data insert. The
|
||||
// deltas are reset for each new revision.
|
||||
|
||||
|
||||
$conditions = array(
|
||||
'type' => 'taxonomy_term_reference',
|
||||
'deleted' => 0,
|
||||
@@ -638,6 +639,10 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'status' => array(
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'is_current' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
@@ -670,6 +675,7 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
$query->addField('n', 'type');
|
||||
$query->addField('n2', 'created');
|
||||
$query->addField('n2', 'sticky');
|
||||
$query->addField('n2', 'status');
|
||||
$query->addField('n2', 'nid', 'is_current');
|
||||
// This query must return a consistent ordering across multiple calls.
|
||||
// We need them ordered by node vid (since we use that to decide when
|
||||
@@ -682,6 +688,14 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
$query->orderBy('tn.vid');
|
||||
$query->orderBy('td.weight');
|
||||
$query->orderBy('tn.tid');
|
||||
|
||||
// Work around a bug in the PostgreSQL driver that would result in fatal
|
||||
// errors when this subquery is used in the insert query below. See
|
||||
// https://drupal.org/node/2057693.
|
||||
$fields = &$query->getFields();
|
||||
unset($fields['td.weight']);
|
||||
unset($fields['tn.tid']);
|
||||
|
||||
db_insert('taxonomy_update_7005')
|
||||
->from($query)
|
||||
->execute();
|
||||
@@ -690,7 +704,7 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
// We do each pass in batches of 1000.
|
||||
$batch = 1000;
|
||||
|
||||
$result = db_query_range('SELECT vocab_id, tid, nid, vid, type, created, sticky, is_current FROM {taxonomy_update_7005} ORDER BY n', $sandbox['last'], $batch);
|
||||
$result = db_query_range('SELECT vocab_id, tid, nid, vid, type, created, sticky, status, is_current FROM {taxonomy_update_7005} ORDER BY n', $sandbox['last'], $batch);
|
||||
if (isset($sandbox['cursor'])) {
|
||||
$values = $sandbox['cursor']['values'];
|
||||
$deltas = $sandbox['cursor']['deltas'];
|
||||
@@ -757,12 +771,14 @@ function taxonomy_update_7005(&$sandbox) {
|
||||
// is_current column is a node ID if this revision is also current.
|
||||
if ($record->is_current) {
|
||||
db_insert($table_name)->fields($columns)->values($values)->execute();
|
||||
|
||||
// Update the {taxonomy_index} table.
|
||||
db_insert('taxonomy_index')
|
||||
->fields(array('nid', 'tid', 'sticky', 'created',))
|
||||
->values(array($record->nid, $record->tid, $record->sticky, $record->created))
|
||||
->execute();
|
||||
// Only insert a record in the taxonomy index if the node is published.
|
||||
if ($record->status) {
|
||||
// Update the {taxonomy_index} table.
|
||||
db_insert('taxonomy_index')
|
||||
->fields(array('nid', 'tid', 'sticky', 'created',))
|
||||
->values(array($record->nid, $record->tid, $record->sticky, $record->created))
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -880,3 +896,44 @@ function taxonomy_update_7010() {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @addtogroup updates-7.x-extra
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Drop unpublished nodes from the index.
|
||||
*/
|
||||
function taxonomy_update_7011(&$sandbox) {
|
||||
// Initialize information needed by the batch update system.
|
||||
if (!isset($sandbox['progress'])) {
|
||||
$sandbox['progress'] = 0;
|
||||
$sandbox['max'] = db_query('SELECT COUNT(DISTINCT n.nid) FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', array(':status' => NODE_NOT_PUBLISHED))->fetchField();
|
||||
// If there's no data, don't bother with the extra work.
|
||||
if (empty($sandbox['max'])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Process records in groups of 5000.
|
||||
$limit = 5000;
|
||||
$nids = db_query_range('SELECT DISTINCT n.nid FROM {node} n INNER JOIN {taxonomy_index} t ON n.nid = t.nid WHERE n.status = :status', 0, $limit, array(':status' => NODE_NOT_PUBLISHED))->fetchCol();
|
||||
if (!empty($nids)) {
|
||||
db_delete('taxonomy_index')
|
||||
->condition('nid', $nids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Update our progress information for the batch update.
|
||||
$sandbox['progress'] += $limit;
|
||||
|
||||
// Indicate our current progress to the batch update system, if the update is
|
||||
// not yet complete.
|
||||
if ($sandbox['progress'] < $sandbox['max']) {
|
||||
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-7.x-extra".
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@ function taxonomy_help($path, $arg) {
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Creating vocabularies') . '</dt>';
|
||||
$output .= '<dd>' . t('Users with sufficient <a href="@perm">permissions</a> can create <em>vocabularies</em> and <em>terms</em> through the <a href="@taxo">Taxonomy page</a>. The page listing the terms provides a drag-and-drop interface for controlling the order of the terms and sub-terms within a vocabulary, in a hierarchical fashion. A <em>controlled vocabulary</em> classifying music by genre with terms and sub-terms could look as follows:', array('@taxo' => url('admin/structure/taxonomy'), '@perm' => url('admin/people/permissions', array('fragment'=>'module-taxonomy'))));
|
||||
$output .= '<dd>' . t('Users with sufficient <a href="@perm">permissions</a> can create <em>vocabularies</em> and <em>terms</em> through the <a href="@taxo">Taxonomy page</a>. The page listing the terms provides a drag-and-drop interface for controlling the order of the terms and sub-terms within a vocabulary, in a hierarchical fashion. A <em>controlled vocabulary</em> classifying music by genre with terms and sub-terms could look as follows:', array('@taxo' => url('admin/structure/taxonomy'), '@perm' => url('admin/people/permissions', array('fragment' => 'module-taxonomy'))));
|
||||
$output .= '<ul><li>' . t('<em>vocabulary</em>: Music') . '</li>';
|
||||
$output .= '<ul><li>' . t('<em>term</em>: Jazz') . '</li>';
|
||||
$output .= '<ul><li>' . t('<em>sub-term</em>: Swing') . '</li>';
|
||||
@@ -140,7 +140,7 @@ function taxonomy_entity_info() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity URI callback.
|
||||
* Implements callback_entity_info_uri().
|
||||
*/
|
||||
function taxonomy_term_uri($term) {
|
||||
return array(
|
||||
@@ -283,6 +283,8 @@ function taxonomy_menu() {
|
||||
'title' => 'Taxonomy term',
|
||||
'title callback' => 'taxonomy_term_title',
|
||||
'title arguments' => array(2),
|
||||
// The page callback also invokes drupal_set_title() in case
|
||||
// the menu router's title is overridden by a menu link.
|
||||
'page callback' => 'taxonomy_term_page',
|
||||
'page arguments' => array(2),
|
||||
'access arguments' => array('access content'),
|
||||
@@ -457,7 +459,12 @@ function taxonomy_vocabulary_save($vocabulary) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a vocabulary.
|
||||
* Deletes a vocabulary.
|
||||
*
|
||||
* This will update all Taxonomy fields so that they don't reference the
|
||||
* deleted vocabulary. It also will delete fields that have no remaining
|
||||
* vocabulary references. All taxonomy terms of the deleted vocabulary
|
||||
* will be deleted as well.
|
||||
*
|
||||
* @param $vid
|
||||
* A vocabulary ID.
|
||||
@@ -748,7 +755,7 @@ function taxonomy_term_delete($tid) {
|
||||
* @param term
|
||||
* A taxonomy term object.
|
||||
* @return
|
||||
* A $page element suitable for use by drupal_page_render().
|
||||
* A $page element suitable for use by drupal_render().
|
||||
*/
|
||||
function taxonomy_term_show($term) {
|
||||
return taxonomy_term_view_multiple(array($term->tid => $term), 'full');
|
||||
@@ -771,15 +778,26 @@ function taxonomy_term_show($term) {
|
||||
* An array in the format expected by drupal_render().
|
||||
*/
|
||||
function taxonomy_term_view_multiple($terms, $view_mode = 'teaser', $weight = 0, $langcode = NULL) {
|
||||
field_attach_prepare_view('taxonomy_term', $terms, $view_mode, $langcode);
|
||||
entity_prepare_view('taxonomy_term', $terms, $langcode);
|
||||
$build = array();
|
||||
$entities_by_view_mode = entity_view_mode_prepare('taxonomy_term', $terms, $view_mode, $langcode);
|
||||
foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
|
||||
field_attach_prepare_view('taxonomy_term', $entities, $entity_view_mode, $langcode);
|
||||
entity_prepare_view('taxonomy_term', $entities, $langcode);
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
$build['taxonomy_terms'][$entity->tid] = taxonomy_term_view($entity, $entity_view_mode, $langcode);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($terms as $term) {
|
||||
$build['taxonomy_terms'][$term->tid] = taxonomy_term_view($term, $view_mode, $langcode);
|
||||
$build['taxonomy_terms'][$term->tid]['#weight'] = $weight;
|
||||
$weight++;
|
||||
}
|
||||
// Sort here, to preserve the input order of the entities that were passed to
|
||||
// this function.
|
||||
uasort($build['taxonomy_terms'], 'element_sort');
|
||||
$build['taxonomy_terms']['#sorted'] = TRUE;
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
@@ -812,12 +830,7 @@ function taxonomy_term_build_content($term, $view_mode = 'full', $langcode = NUL
|
||||
$term->content = array();
|
||||
|
||||
// Allow modules to change the view mode.
|
||||
$context = array(
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'entity' => $term,
|
||||
'langcode' => $langcode,
|
||||
);
|
||||
drupal_alter('entity_view_mode', $view_mode, $context);
|
||||
$view_mode = key(entity_view_mode_prepare('taxonomy_term', array($term->tid => $term), $view_mode, $langcode));
|
||||
|
||||
// Add the term description if the term has one and it is visible.
|
||||
$type = 'taxonomy_term';
|
||||
@@ -1012,7 +1025,7 @@ function taxonomy_get_parents($tid) {
|
||||
$query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid');
|
||||
$query->addField('t', 'tid');
|
||||
$query->condition('h.tid', $tid);
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$query->orderBy('t.weight');
|
||||
$query->orderBy('t.name');
|
||||
$tids = $query->execute()->fetchCol();
|
||||
@@ -1070,7 +1083,7 @@ function taxonomy_get_children($tid, $vid = 0) {
|
||||
if ($vid) {
|
||||
$query->condition('t.vid', $vid);
|
||||
}
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$query->orderBy('t.weight');
|
||||
$query->orderBy('t.name');
|
||||
$tids = $query->execute()->fetchCol();
|
||||
@@ -1118,7 +1131,7 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities
|
||||
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
|
||||
$result = $query
|
||||
->addTag('translatable')
|
||||
->addTag('term_access')
|
||||
->addTag('taxonomy_term_access')
|
||||
->fields('t')
|
||||
->fields('h', array('parent'))
|
||||
->condition('t.vid', $vid)
|
||||
@@ -1238,7 +1251,7 @@ class TaxonomyTermController extends DrupalDefaultEntityController {
|
||||
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
|
||||
$query = parent::buildQuery($ids, $conditions, $revision_id);
|
||||
$query->addTag('translatable');
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
// When name is passed as a condition use LIKE.
|
||||
if (isset($conditions['name'])) {
|
||||
$query_conditions = &$query->conditions();
|
||||
@@ -1703,13 +1716,15 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
|
||||
}
|
||||
|
||||
/**
|
||||
* Title callback for term pages.
|
||||
* Title callback: Returns the title of the taxonomy term.
|
||||
*
|
||||
* @param $term
|
||||
* A term object.
|
||||
*
|
||||
* @return
|
||||
* The term name to be used as the page title.
|
||||
* An unsanitized string that is the title of the taxonomy term.
|
||||
*
|
||||
* @see taxonomy_menu()
|
||||
*/
|
||||
function taxonomy_term_title($term) {
|
||||
return $term->name;
|
||||
|
||||
@@ -150,7 +150,7 @@ function taxonomy_autocomplete($field_name = '', $tags_typed = '') {
|
||||
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
$query->addTag('translatable');
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
|
||||
// Do not select already entered terms.
|
||||
if (!empty($tags_typed)) {
|
||||
|
||||
@@ -170,7 +170,8 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase {
|
||||
|
||||
// Check the created vocabulary.
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
$vid = $vocabularies[count($vocabularies) - 1]->vid;
|
||||
$vocabularies_keys = array_keys($vocabularies);
|
||||
$vid = $vocabularies[end($vocabularies_keys)]->vid;
|
||||
entity_get_controller('taxonomy_vocabulary')->resetCache();
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
$this->assertTrue($vocabulary, 'Vocabulary found in database.');
|
||||
@@ -689,15 +690,20 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
|
||||
$term_objects[$key] = reset($term_objects[$key]);
|
||||
}
|
||||
|
||||
// Test editing the node.
|
||||
$node = $this->drupalGetNodeByTitle($edit["title"]);
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||
foreach ($terms as $term) {
|
||||
$this->assertText($term, 'The term was retained after edit and still appears on the node page.');
|
||||
}
|
||||
|
||||
// Delete term 1.
|
||||
$this->drupalPost('taxonomy/term/' . $term_objects['term1']->tid . '/edit', array(), t('Delete'));
|
||||
$this->drupalPost(NULL, NULL, t('Delete'));
|
||||
$term_names = array($term_objects['term2']->name, $term_objects['term3']->name);
|
||||
|
||||
// Get the node.
|
||||
$node = $this->drupalGetNodeByTitle($edit["title"]);
|
||||
// Get the node and verify that the terms that should be there still are.
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
|
||||
foreach ($term_names as $term_name) {
|
||||
$this->assertText($term_name, format_string('The term %name appears on the node page after one term %deleted was deleted', array('%name' => $term_name, '%deleted' => $term_objects['term1']->name)));
|
||||
}
|
||||
@@ -1019,7 +1025,7 @@ class TaxonomyRSSTestCase extends TaxonomyWebTestCase {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy');
|
||||
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access', 'administer content types'));
|
||||
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access', 'administer content types', 'administer fields'));
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->vocabulary = $this->createVocabulary();
|
||||
|
||||
@@ -1977,3 +1983,113 @@ class TaxonomyEFQTestCase extends TaxonomyWebTestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that appropriate query tags are added.
|
||||
*/
|
||||
class TaxonomyQueryAlterTestCase extends TaxonomyWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Taxonomy query tags',
|
||||
'description' => 'Verifies that taxonomy_term_access tags are added to queries.',
|
||||
'group' => 'Taxonomy',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('taxonomy_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that appropriate tags are added when querying the database.
|
||||
*/
|
||||
public function testTaxonomyQueryAlter() {
|
||||
// Create a new vocabulary and add a few terms to it.
|
||||
$vocabulary = $this->createVocabulary();
|
||||
$terms = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$terms[$i] = $this->createTerm($vocabulary);
|
||||
}
|
||||
|
||||
// Set up hierarchy. Term 2 is a child of 1.
|
||||
$terms[2]->parent = array($terms[1]->tid);
|
||||
taxonomy_term_save($terms[2]);
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_term = taxonomy_term_load($terms[0]->tid);
|
||||
$this->assertEqual($loaded_term->tid, $terms[0]->tid, 'First term was loaded');
|
||||
$this->assertQueryTagTestResult(1, 'taxonomy_term_load()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = taxonomy_get_tree($vocabulary->vid);
|
||||
$this->assertEqual(count($loaded_terms), count($terms), 'All terms were loaded');
|
||||
$this->assertQueryTagTestResult(1, 'taxonomy_get_tree()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = taxonomy_get_parents($terms[2]->tid);
|
||||
$this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded');
|
||||
$this->assertQueryTagTestResult(2, 'taxonomy_get_parents()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = taxonomy_get_children($terms[1]->tid);
|
||||
$this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded');
|
||||
$this->assertQueryTagTestResult(2, 'taxonomy_get_children()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
$query->addField('t', 'tid');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$tids = $query->execute()->fetchCol();
|
||||
$this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 'custom db_select() with taxonomy_term_access tag (preferred)');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = db_select('taxonomy_term_data', 't');
|
||||
$query->addField('t', 'tid');
|
||||
$query->addTag('term_access');
|
||||
$tids = $query->execute()->fetchCol();
|
||||
$this->assertEqual(count($tids), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 'custom db_select() with term_access tag (deprecated)');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = new EntityFieldQuery();
|
||||
$query->entityCondition('entity_type', 'taxonomy_term');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$result = $query->execute();
|
||||
$this->assertEqual(count($result['taxonomy_term']), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 'custom EntityFieldQuery with taxonomy_term_access tag (preferred)');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = new EntityFieldQuery();
|
||||
$query->entityCondition('entity_type', 'taxonomy_term');
|
||||
$query->addTag('term_access');
|
||||
$result = $query->execute();
|
||||
$this->assertEqual(count($result['taxonomy_term']), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 'custom EntityFieldQuery with term_access tag (deprecated)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the hooks in the test module.
|
||||
*/
|
||||
protected function setupQueryTagTestHooks() {
|
||||
taxonomy_terms_static_reset();
|
||||
variable_set('taxonomy_test_query_alter', 0);
|
||||
variable_set('taxonomy_test_query_term_access_alter', 0);
|
||||
variable_set('taxonomy_test_query_taxonomy_term_access_alter', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies invocation of the hooks in the test module.
|
||||
*
|
||||
* @param int $expected_invocations
|
||||
* The number of times the hooks are expected to have been invoked.
|
||||
* @param string $method
|
||||
* A string describing the invoked function which generated the query.
|
||||
*/
|
||||
protected function assertQueryTagTestResult($expected_invocations, $method) {
|
||||
$this->assertIdentical($expected_invocations, variable_get('taxonomy_test_query_alter'), 'hook_query_alter() invoked when executing ' . $method);
|
||||
$this->assertIdentical($expected_invocations, variable_get('taxonomy_test_query_term_access_alter'), 'Deprecated hook_query_term_access_alter() invoked when executing ' . $method);
|
||||
$this->assertIdentical($expected_invocations, variable_get('taxonomy_test_query_taxonomy_term_access_alter'), 'Preferred hook_query_taxonomy_term_access_alter() invoked when executing ' . $method);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user