diff options
Diffstat (limited to 'modules/taxonomy/taxonomy.test')
-rw-r--r-- | modules/taxonomy/taxonomy.test | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index ba91e6de2..6264ba824 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -19,6 +19,7 @@ class TaxonomyWebTestCase extends DrupalWebTestCase { $vocabulary = new stdClass(); $vocabulary->name = $this->randomName(); $vocabulary->description = $this->randomName(); + $vocabulary->machine_name = drupal_strtolower($this->randomName()); $vocabulary->help = ''; $vocabulary->nodes = array('article' => 'article'); $vocabulary->weight = mt_rand(0, 10); @@ -29,10 +30,10 @@ class TaxonomyWebTestCase extends DrupalWebTestCase { /** * Returns a new term with random properties in vocabulary $vid. */ - function createTerm($vid) { + function createTerm($vocabulary) { $term = new stdClass(); $term->name = $this->randomName(); - $term->vid = $vid; + $term->vid = $vocabulary->vid; taxonomy_term_save($term); return $term; } @@ -70,6 +71,7 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase { $edit = array(); $edit['name'] = $this->randomName(); $edit['description'] = $this->randomName(); + $edit['machine_name'] = drupal_strtolower($this->randomName()); $edit['help'] = $this->randomName(); $edit['nodes[article]'] = 'article'; $edit['tags'] = 1; @@ -84,10 +86,19 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase { $this->clickLink(t('edit vocabulary')); $edit = array(); $edit['name'] = $this->randomName(); + $edit['machine_name'] = drupal_strtolower($this->randomName()); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name']))); $this->drupalGet('admin/content/taxonomy'); $this->assertText($edit['name'], t('Vocabulary found in the vocabulary overview listing.')); + + // Try to submit a vocabulary with a duplicate machine name. + $this->drupalPost('admin/content/taxonomy/add', $edit, t('Save')); + $this->assertText(t('This machine-readable name is already in use by another vocabulary and must be unique.'), t('Duplicate machine name validation was successful')); + + // Try to submit an invalid machine name. + $edit['machine_name'] = '!&^%'; + $this->drupalPost('admin/content/taxonomy/add', $edit, t('Save')); + $this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.')); } /** @@ -125,13 +136,11 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase { // Delete all vocabularies. $vocabularies = taxonomy_get_vocabularies(); foreach ($vocabularies as $key => $vocabulary) { - $edit = array(); - $this->drupalPost('admin/content/taxonomy/' . $vocabulary->vid, $edit, t('Delete')); - // Submit the confirm form for deletion. - $this->drupalPost(NULL, NULL, t('Delete')); + taxonomy_vocabulary_delete($key); } // Confirm that no vocabularies are found in the database. $this->assertFalse(taxonomy_get_vocabularies(), t('No vocabularies found in the database')); + $this->drupalGet('admin/content/taxonomy'); // Check the default message for no vocabularies. $this->assertText(t('No vocabularies available.'), t('No vocabularies were found.')); } @@ -143,6 +152,7 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase { // Create a vocabulary. $edit = array( 'name' => $this->randomName(), + 'machine_name' => drupal_strtolower($this->randomName()), 'nodes[article]' => 'article', ); $this->drupalPost('admin/content/taxonomy/add', $edit, t('Save')); @@ -257,6 +267,12 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase { $vocabulary3->weight = 2; taxonomy_vocabulary_save($vocabulary3); + // Fetch the names for all vocabularies, confirm that they are keyed by + // machine name. + $names = taxonomy_vocabulary_get_names(); + $this->assertTrue(in_array($vocabulary1->name, $names), t('Vocabulary 1 name found.')); + $this->assertTrue(isset($names[$vocabulary1->machine_name]), t('Vocabulary names are keyed by machine name.')); + // Fetch all of the vocabularies using taxonomy_get_vocabularies(). // Confirm that the vocabularies are ordered by weight. $vocabularies = taxonomy_get_vocabularies(); @@ -306,9 +322,9 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase { function testTaxonomyTermCountNodes() { // Create a vocabulary with three terms. $vocabulary = $this->createVocabulary(); - $term1 = $this->createTerm($vocabulary->vid); - $term2 = $this->createTerm($vocabulary->vid); - $term3 = $this->createTerm($vocabulary->vid); + $term1 = $this->createTerm($vocabulary); + $term2 = $this->createTerm($vocabulary); + $term3 = $this->createTerm($vocabulary); // Attach term1 to a node. $node1 = $this->drupalCreateNode(array('type' => 'page')); @@ -396,8 +412,8 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { */ function testTaxonomyTermRelations() { // Create two taxonomy terms. - $term1 = $this->createTerm($this->vocabulary->vid); - $term2 = $this->createTerm($this->vocabulary->vid); + $term1 = $this->createTerm($this->vocabulary); + $term2 = $this->createTerm($this->vocabulary); // Edit $term1 and add $term2 as a relationship. $edit = array(); @@ -406,7 +422,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $related = taxonomy_get_related($term1->tid); $this->assertTrue(isset($related[$term2->tid]), t('Related term was found')); // Create a third term. - $term3 = $this->createTerm($this->vocabulary->vid); + $term3 = $this->createTerm($this->vocabulary); $edit['relations[]'] = $term3->tid; $this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', $edit, t('Save')); @@ -420,7 +436,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { */ function testTaxonomySynonyms() { // Create a taxonomy term with one synonym. - $term = $this->createTerm($this->vocabulary->vid); + $term = $this->createTerm($this->vocabulary); $term->synonyms = $this->randomName(); taxonomy_term_save($term); @@ -439,8 +455,8 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { */ function testTaxonomyTermHierarchy() { // Create two taxonomy terms. - $term1 = $this->createTerm($this->vocabulary->vid); - $term2 = $this->createTerm($this->vocabulary->vid); + $term1 = $this->createTerm($this->vocabulary); + $term2 = $this->createTerm($this->vocabulary); // Edit $term2, setting $term1 as parent. $edit = array(); @@ -454,7 +470,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $this->assertTrue(isset($parents[$term1->tid]), t('Parent found correctly.')); // Create a third term and save this as a parent of term2. - $term3 = $this->createTerm($this->vocabulary->vid); + $term3 = $this->createTerm($this->vocabulary); $term2->parent = array($term1->tid, $term3->tid); taxonomy_term_save($term2); $parents = taxonomy_get_parents($term2->tid); @@ -468,8 +484,8 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { */ function testTaxonomyNode() { // Create two taxonomy terms. - $term1 = $this->createTerm($this->vocabulary->vid); - $term2 = $this->createTerm($this->vocabulary->vid); + $term1 = $this->createTerm($this->vocabulary); + $term2 = $this->createTerm($this->vocabulary); // Post an article. $edit = array(); @@ -580,7 +596,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { * Test taxonomy_get_term_by_name(). */ function testTaxonomyGetTermByName() { - $term = $this->createTerm($this->vocabulary->vid); + $term = $this->createTerm($this->vocabulary); // Load the term with the exact name. $terms = taxonomy_get_term_by_name($term->name); @@ -639,7 +655,7 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase { $i = 0; while ($i < 5) { $i++; - $this->createTerm($vocabulary->vid); + $this->createTerm($vocabulary); } // Load the terms from the vocabulary. $terms = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid)); @@ -667,7 +683,7 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase { $this->assertFalse(isset($terms4[$deleted->tid])); // Create a single term and load it by name. - $term = $this->createTerm($vocabulary->vid); + $term = $this->createTerm($vocabulary); $loaded_terms = taxonomy_term_load_multiple(array(), array('name' => $term->name)); $this->assertEqual(count($loaded_terms), 1, t('One term was loaded')); $loaded_term = reset($loaded_terms); @@ -678,7 +694,7 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase { /** * Tests for taxonomy hook invocation. */ -class TaxonomyHooksTestCase extends DrupalWebTestCase { +class TaxonomyHooksTestCase extends TaxonomyWebTestCase { public static function getInfo() { return array( 'name' => t('Taxonomy term hooks'), @@ -697,18 +713,14 @@ class TaxonomyHooksTestCase extends DrupalWebTestCase { * Test that hooks are run correctly on creating, editing and deleting a term. */ function testTaxonomyTermHooks() { - // Create a taxonomy vocabulary. - $edit = array( - 'name' => $this->randomName(), - ); - $this->drupalPost('admin/content/taxonomy/add', $edit, t('Save')); + $vocabulary = $this->createVocabulary(); // Create a term with one antonym. $edit = array( 'name' => $this->randomName(), 'antonyms' => 'Long', ); - $this->drupalPost('admin/content/taxonomy/1/add', $edit, t('Save')); + $this->drupalPost('admin/content/taxonomy/' . $vocabulary->vid . '/add', $edit, t('Save')); $term = reset(taxonomy_get_term_by_name($edit['name'])); $this->assertEqual($term->antonyms[0], $edit['antonyms'], t('Antonyms were loaded into the term object')); |