Skip to content
Snippets Groups Projects
Verified Commit e354dcb5 authored by Juraj Nemec's avatar Juraj Nemec
Browse files

Issue #2644276 by poker10, pashupathi nath gajawada, henryhu: Mixed case...

Issue #2644276 by poker10, pashupathi nath gajawada, henryhu: Mixed case taxonomy terms not loaded from the internal entity cache
parent c32d02fe
Branches
Tags
1 merge request!7330Issue #3306390 by poker10, catch, Fabianx, pwolanin, rvtraveller: [D7]...
......@@ -139,3 +139,14 @@ function taxonomy_test_query_taxonomy_term_access_alter(QueryAlterableInterface
variable_set(__FUNCTION__, ++$value);
}
}
/**
* Test controller class for taxonomy terms.
*
* The main purpose is to make cacheGet() method available for testing.
*/
class TestTaxonomyTermController extends TaxonomyTermController {
public function loadFromCache($ids, $conditions = array()) {
return parent::cacheGet($ids, $conditions);
}
}
......@@ -1274,7 +1274,7 @@ protected function cacheGet($ids, $conditions = array()) {
// LOWER() and drupal_strtolower() may return different results.
foreach ($terms as $term) {
$term_values = (array) $term;
if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($term_values['name']))) {
if (isset($conditions['name']) && drupal_strtolower($conditions['name']) != drupal_strtolower($term_values['name'])) {
unset($terms[$term->tid]);
}
}
......
......@@ -2131,3 +2131,42 @@ class TaxonomyQueryAlterTestCase extends TaxonomyWebTestCase {
}
}
/**
* Tests for taxonomy terms cache usage.
*/
class TaxonomyTermCacheUsageTestCase extends TaxonomyWebTestCase {
public static function getInfo() {
return array(
'name' => 'Taxonomy term cache usage',
'description' => 'Tests for taxonomy term cache usage.',
'group' => 'Taxonomy',
);
}
function setUp() {
parent::setUp('taxonomy', 'taxonomy_test');
}
/**
* Test taxonomy_get_term_by_name() cache usage.
*/
function testTaxonomyGetTermByNameCacheUsage() {
// Create vocabulary and term.
$new_vocabulary = $this->createVocabulary();
$new_term = new stdClass();
$new_term->name = 'MixedCaseTerm';
$new_term->vid = $new_vocabulary->vid;
taxonomy_term_save($new_term);
// Try to load term with mixed case letters from the cache.
$taxonomy_controller = new TestTaxonomyTermController('taxonomy_term');
// First load to warm the cache.
$terms = $taxonomy_controller->load(array(), array('name' => $new_term->name));
$this->assertTrue(isset($terms[$new_term->tid]), 'Term loaded using exact name and vocabulary machine name.');
// Second load should load the $new_term from the cache.
$terms = $taxonomy_controller->loadFromCache(array(), array('name' => $new_term->name));
$this->assertTrue(isset($terms[$new_term->tid]), 'Term loaded using the cache.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment