? dbtngtest.txt
? get_term_by_name.patch
? patch
? taxonomy_permissions.module
? taxonomy_tlm_typo.patch
? modules/node/.node.module.swo
? modules/node/.node.module.swp
? modules/node/node_docs.txt
? modules/taxonomy/taxonomy_docs.txt
? sites/all/modules
? sites/default/files
? sites/default/settings.php
Index: modules/simpletest/tests/taxonomy_test.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/taxonomy_test.test,v
retrieving revision 1.3
diff -u -p -r1.3 taxonomy_test.test
--- modules/simpletest/tests/taxonomy_test.test	25 Nov 2008 13:14:28 -0000	1.3
+++ modules/simpletest/tests/taxonomy_test.test	7 Dec 2008 02:00:42 -0000
@@ -32,8 +32,7 @@ class TaxonomyHooksTestCase extends Drup
       'antonyms' => 'Long',
     );
     $this->drupalPost('admin/content/taxonomy/1/add', $edit, t('Save'));
-    $terms = taxonomy_get_term_by_name($edit['name']);
-    $term = taxonomy_term_load($terms[0]->tid);
+    $term = reset(taxonomy_get_term_by_name($edit['name']));
     $this->assertEqual($term->antonyms[0], $edit['antonyms'], t('Antonyms were loaded into the term object'));
 
     // Update the term with a different antonym.
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.445
diff -u -p -r1.445 taxonomy.module
--- modules/taxonomy/taxonomy.module	5 Dec 2008 22:18:46 -0000	1.445
+++ modules/taxonomy/taxonomy.module	7 Dec 2008 02:00:44 -0000
@@ -1015,13 +1015,7 @@ function _taxonomy_term_children($tid) {
  *   An array of matching term objects.
  */
 function taxonomy_get_term_by_name($name) {
-  $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) = LOWER('%s')", 't', 'tid'), trim($name));
-  $result = array();
-  while ($term = db_fetch_object($db_result)) {
-    $result[] = $term;
-  }
-
-  return $result;
+  return taxonomy_term_load_multiple(array(), array('name' => trim($name)));
 }
 
 /**
@@ -1125,9 +1119,13 @@ function taxonomy_term_load_multiple($ti
 
   // Remove any loaded terms from the array if they don't match $conditions.
   if ($conditions) {
+    // Name matching is case insensitive.
     foreach ($terms as $term) {
       $term_values = (array) $term;
-      if (array_diff_assoc($conditions, $term_values)) {
+      if (isset($conditions['name']) && strcasecmp($conditions['name'], $term_values['name'] !== 0)) {
+        unset($terms[$term->tid]);
+      }
+      elseif (array_diff_assoc($conditions, $term_values)) {
         unset($terms[$term->tid]);
       }
     }
@@ -1147,6 +1145,11 @@ function taxonomy_term_load_multiple($ti
 
     // If the conditions array is populated, add those to the query.
     if ($conditions) {
+      // When name is passed as a condition use LIKE.
+      if (isset($conditions['name'])) {
+        $query->condition('t.name', $conditions['name'], 'LIKE');
+        unset($conditions['name']);
+      }
       foreach ($conditions as $field => $value) {
         $query->conditions('t.' . $field, $value);
       }
Index: modules/taxonomy/taxonomy.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.test,v
retrieving revision 1.17
diff -u -p -r1.17 taxonomy.test
--- modules/taxonomy/taxonomy.test	5 Dec 2008 22:18:46 -0000	1.17
+++ modules/taxonomy/taxonomy.test	7 Dec 2008 02:00:44 -0000
@@ -404,7 +404,7 @@ class TaxonomyTermTestCase extends Taxon
     // Create the term to edit.
     $this->drupalPost('admin/content/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save'));
 
-    $term = taxonomy_get_term_by_name($edit['name']);
+    $term = reset(taxonomy_get_term_by_name($edit['name']));
     $this->assertNotNull($term, t('Term found in database'));
 
     // Submitting a term takes us to the add page; we need the List page.
@@ -425,13 +425,44 @@ class TaxonomyTermTestCase extends Taxon
     );
 
     // Edit the term.
-    $this->drupalPost('taxonomy/term/' . $term[0]->tid . '/edit', $edit, t('Save'));
+    $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
 
     // View the term and check that it is correct.
-    $this->drupalGet('taxonomy/term/' . $term[0]->tid);
+    $this->drupalGet('taxonomy/term/' . $term->tid);
     $this->assertText($edit['name'], t('The randomly generated term name is present.'));
     $this->assertText($edit['description'], t('The randomly generated term description is present.'));
   }
+
+  /**
+   * Test taxonomy_get_term_by_name().
+   */
+  function testTaxonomyGetTermByName() {
+    $term = $this->createTerm($this->vocabulary->vid);
+
+    // Load the term with the exact name.
+    $terms = taxonomy_get_term_by_name($term->name);
+    $this->assertTrue(isset($terms[$term->tid]), t('Term loaded using exact name.'));
+
+    // Load the term with space concatenated.
+    $terms  = taxonomy_get_term_by_name('  ' . $term->name . '   ');
+    $this->assertTrue(isset($terms[$term->tid]), t('Term loaded with extra whitespace.'));
+
+    // Load the term with name uppercased.
+    $terms = taxonomy_get_term_by_name(strtoupper($term->name));
+    $this->assertTrue(isset($terms[$term->tid]), t('Term loaded with uppercased name.'));
+
+    // Load the term with name lowercased.
+    $terms = taxonomy_get_term_by_name(strtolower($term->name));
+    $this->assertTrue(isset($terms[$term->tid]), t('Term loaded with lowercased name.'));
+
+    // Try to load an invalid term name.
+    $terms = taxonomy_get_term_by_name('Banana');
+    $this->assertFalse($terms);
+
+    // Try to load the term using a substring of the name.
+    $terms = taxonomy_get_term_by_name(drupal_substr($term->name, 2));
+    $this->assertFalse($terms);
+  }
 }
 
 /**
