Update to Drupal 8.2.3. For more information, see https://www.drupal.org/project/drupal/releases/8.2.3
This commit is contained in:
parent
507b45a0ed
commit
0a95b8440e
19 changed files with 300 additions and 15 deletions
|
@ -192,7 +192,7 @@ class TaxonomyIndexTid extends ManyToOne {
|
|||
// https://www.drupal.org/node/1821274.
|
||||
->sort('weight')
|
||||
->sort('name')
|
||||
->addTag('term_access');
|
||||
->addTag('taxonomy_term_access');
|
||||
if ($this->options['limit']) {
|
||||
$query->condition('vid', $vocabulary->id());
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ class NodeTermData extends RelationshipPluginBase {
|
|||
$query = db_select('taxonomy_term_field_data', 'td');
|
||||
$query->addJoin($def['type'], 'taxonomy_index', 'tn', 'tn.tid = td.tid');
|
||||
$query->condition('td.vid', array_filter($this->options['vids']), 'IN');
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$query->fields('td');
|
||||
$query->fields('tn', array('nid'));
|
||||
$def['table formula'] = $query;
|
||||
|
|
|
@ -126,7 +126,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
|
|||
$query->addField('t', 'tid');
|
||||
$query->condition('h.tid', $tid);
|
||||
$query->condition('t.default_langcode', 1);
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$query->orderBy('t.weight');
|
||||
$query->orderBy('t.name');
|
||||
if ($ids = $query->execute()->fetchCol()) {
|
||||
|
@ -178,7 +178,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
|
|||
$query->condition('t.vid', $vid);
|
||||
}
|
||||
$query->condition('t.default_langcode', 1);
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$query->orderBy('t.weight');
|
||||
$query->orderBy('t.name');
|
||||
if ($ids = $query->execute()->fetchCol()) {
|
||||
|
@ -204,7 +204,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
|
|||
$query = $this->database->select('taxonomy_term_field_data', 't');
|
||||
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
|
||||
$result = $query
|
||||
->addTag('term_access')
|
||||
->addTag('taxonomy_term_access')
|
||||
->fields('t')
|
||||
->fields('h', array('parent'))
|
||||
->condition('t.vid', $vid)
|
||||
|
@ -320,7 +320,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
|
|||
$query->orderby('td.weight');
|
||||
$query->orderby('td.name');
|
||||
$query->condition('tn.nid', $nids, 'IN');
|
||||
$query->addTag('term_access');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
if (!empty($vocabs)) {
|
||||
$query->condition('td.vid', $vocabs, 'IN');
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class TermViewsData extends EntityViewsData {
|
|||
$data = parent::getViewsData();
|
||||
|
||||
$data['taxonomy_term_field_data']['table']['base']['help'] = $this->t('Taxonomy terms are attached to nodes.');
|
||||
$data['taxonomy_term_field_data']['table']['base']['access query tag'] = 'term_access';
|
||||
$data['taxonomy_term_field_data']['table']['base']['access query tag'] = 'taxonomy_term_access';
|
||||
$data['taxonomy_term_field_data']['table']['wizard_id'] = 'taxonomy_term';
|
||||
|
||||
$data['taxonomy_term_field_data']['table']['join'] = array(
|
||||
|
|
119
core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php
Normal file
119
core/modules/taxonomy/src/Tests/TaxonomyQueryAlterTest.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\taxonomy\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests that appropriate query tags are added.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class TaxonomyQueryAlterTest extends WebTestBase {
|
||||
|
||||
use TaxonomyTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', '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 = $terms[1]->id();
|
||||
$terms[2]->save();
|
||||
|
||||
$term_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_term = $term_storage->load($terms[0]->id());
|
||||
$this->assertEqual($loaded_term->id(), $terms[0]->id(), 'First term was loaded');
|
||||
$this->assertQueryTagTestResult(1, 0, 'TermStorage::load()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = $term_storage->loadTree($vocabulary->id());
|
||||
$this->assertEqual(count($loaded_terms), count($terms), 'All terms were loaded');
|
||||
$this->assertQueryTagTestResult(1, 1, 'TermStorage::loadTree()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = $term_storage->loadParents($terms[2]->id());
|
||||
$this->assertEqual(count($loaded_terms), 1, 'All parent terms were loaded');
|
||||
$this->assertQueryTagTestResult(2, 1, 'TermStorage::loadParents()');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$loaded_terms = $term_storage->loadChildren($terms[1]->id());
|
||||
$this->assertEqual(count($loaded_terms), 1, 'All child terms were loaded');
|
||||
$this->assertQueryTagTestResult(2, 1, 'TermStorage::loadChildren()');
|
||||
|
||||
$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, 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, 1, 'custom db_select() with term_access tag (deprecated)');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = \Drupal::entityQuery('taxonomy_term');
|
||||
$query->addTag('taxonomy_term_access');
|
||||
$result = $query->execute();
|
||||
$this->assertEqual(count($result), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 1, 'custom EntityFieldQuery with taxonomy_term_access tag (preferred)');
|
||||
|
||||
$this->setupQueryTagTestHooks();
|
||||
$query = \Drupal::entityQuery('taxonomy_term');
|
||||
$query->addTag('term_access');
|
||||
$result = $query->execute();
|
||||
$this->assertEqual(count($result), count($terms), 'All term IDs were retrieved');
|
||||
$this->assertQueryTagTestResult(1, 1, 'custom EntityFieldQuery with term_access tag (deprecated)');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the hooks in the test module.
|
||||
*/
|
||||
protected function setupQueryTagTestHooks() {
|
||||
taxonomy_terms_static_reset();
|
||||
\Drupal::state()->set('taxonomy_test_query_alter', 0);
|
||||
\Drupal::state()->set('taxonomy_test_query_term_access_alter', 0);
|
||||
\Drupal::state()->set('taxonomy_test_query_taxonomy_term_access_alter', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies invocation of the hooks in the test module.
|
||||
*
|
||||
* @param int $expected_generic_invocations
|
||||
* The number of times the generic query_alter hook is expected to have
|
||||
* been invoked.
|
||||
* @param int $expected_specific_invocations
|
||||
* The number of times the tag-specific query_alter hooks are expected to
|
||||
* have been invoked.
|
||||
* @param string $method
|
||||
* A string describing the invoked function which generated the query.
|
||||
*/
|
||||
protected function assertQueryTagTestResult($expected_generic_invocations, $expected_specific_invocations, $method) {
|
||||
$this->assertIdentical($expected_generic_invocations, \Drupal::state()->get('taxonomy_test_query_alter'), 'hook_query_alter() invoked when executing ' . $method);
|
||||
$this->assertIdentical($expected_specific_invocations, \Drupal::state()->get('taxonomy_test_query_term_access_alter'), 'Deprecated hook_query_term_access_alter() invoked when executing ' . $method);
|
||||
$this->assertIdentical($expected_specific_invocations, \Drupal::state()->get('taxonomy_test_query_taxonomy_term_access_alter'), 'Preferred hook_query_taxonomy_term_access_alter() invoked when executing ' . $method);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
use Drupal\Component\Utility\Tags;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
name: 'Taxonomy test'
|
||||
type: module
|
||||
description: 'Provides test hook implementations for taxonomy tests'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- taxonomy
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides test hook implementations for taxonomy tests.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Query\AlterableInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_query_alter().
|
||||
*/
|
||||
function taxonomy_test_query_alter(AlterableInterface $query) {
|
||||
$value = \Drupal::state()->get(__FUNCTION__);
|
||||
if (isset($value)) {
|
||||
\Drupal::state()->set(__FUNCTION__, ++$value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*/
|
||||
function taxonomy_test_query_term_access_alter(AlterableInterface $query) {
|
||||
$value = \Drupal::state()->get(__FUNCTION__);
|
||||
if (isset($value)) {
|
||||
\Drupal::state()->set(__FUNCTION__, ++$value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*/
|
||||
function taxonomy_test_query_taxonomy_term_access_alter(AlterableInterface $query) {
|
||||
$value = \Drupal::state()->get(__FUNCTION__);
|
||||
if (isset($value)) {
|
||||
\Drupal::state()->set(__FUNCTION__, ++$value);
|
||||
}
|
||||
}
|
Reference in a new issue