diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test index 747d822..dcb8a17 100644 --- a/core/modules/taxonomy/taxonomy.test +++ b/core/modules/taxonomy/taxonomy.test @@ -641,6 +641,41 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Tests term autocompletion edge cases with slashes in the names. + */ + function testTermAutocompletion() { + // Add a term with a slash in the name. + $first_term = $this->createTerm($this->vocabulary); + $first_term->name = '10/16/2011'; + taxonomy_term_save($first_term); + // Add another term that differs after the slash character. + $second_term = $this->createTerm($this->vocabulary); + $second_term->name = '10/17/2011'; + taxonomy_term_save($second_term); + + // Try to autocomplete a term name that matches both terms. + // We should get both term in a json encoded string. + $input = '10/'; + $path = 'taxonomy/autocomplete/taxonomy_'; + $path .= $this->vocabulary->machine_name . '/' . $input; + // The result order is not guaranteed, so check each term separately. + $url = url($path, array('absolute' => TRUE)); + $result = drupal_http_request($url); + $data = drupal_json_decode($result->data); + $this->assertEqual($data[$first_term->name], check_plain($first_term->name), t('Autocomplete returned the first matching term')); + $this->assertEqual($data[$second_term->name], check_plain($second_term->name), t('Autocomplete returned the second matching term')); + + // Try to autocomplete a term name that matches first term. + // We should only get the first term in a json encoded string. + $input = '10/16'; + $url = 'taxonomy/autocomplete/taxonomy_'; + $url .= $this->vocabulary->machine_name . '/' . $input; + $this->drupalGet($url); + $target = array($first_term->name => check_plain($first_term->name)); + $this->assertRaw(drupal_json_encode($target), t('Autocomplete returns only the expected matching term.')); + } + + /** * Save, edit and delete a term using the user interface. */ function testTermInterface() {