diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-12-05 22:18:46 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-12-05 22:18:46 +0000 |
commit | 58b0235a72859aa433d743a9f284504f24664857 (patch) | |
tree | 524132d2e7ca157baa1059117244a5b27b1f51fb /modules/taxonomy/taxonomy.test | |
parent | 0b06c68b988410c49c9f4ffbf8c3160d4e9da2c7 (diff) | |
download | brdo-58b0235a72859aa433d743a9f284504f24664857.tar.gz brdo-58b0235a72859aa433d743a9f284504f24664857.tar.bz2 |
- Patch #324313 by catch et al: load multiple nodes and terms at once.
Diffstat (limited to 'modules/taxonomy/taxonomy.test')
-rw-r--r-- | modules/taxonomy/taxonomy.test | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index bc85bbe68..9f36b680e 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -344,7 +344,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $this->drupalPost('node/add/article', $edit, t('Save')); // Check that the term is displayed when the node is viewed. - $node = node_load(array('title' => $edit['title'])); + $node = $this->drupalGetNodeByTitle($edit['title']); $this->drupalGet('node/' . $node->nid); $this->assertText($term1->name, t('Term is displayed when viewing the node.')); @@ -433,3 +433,63 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $this->assertText($edit['description'], t('The randomly generated term description is present.')); } } + +/** + * Test the taxonomy_term_load_multiple() function. + */ +class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase { + + function getInfo() { + return array( + 'name' => t('Taxonomy term multiple loading'), + 'description' => t('Test the loading of multiple taxonomy terms at once'), + 'group' => t('Taxonomy'), + ); + } + + function setUp() { + parent::setUp(); + $this->taxonomy_admin = $this->drupalCreateUser(array('administer taxonomy')); + $this->drupalLogin($this->taxonomy_admin); + } + + /** + * Create a vocabulary and some taxonomy terms, ensuring they're loaded + * correctly using taxonomy_term_load_multiple(). + */ + function testTaxonomyTermMultipleLoad() { + // Create a vocabulary. + $vocabulary = $this->createVocabulary(); + + // Create five terms in the vocabulary. + $i = 0; + while ($i < 5) { + $i++; + $this->createTerm($vocabulary->vid); + } + // Load the terms from the vocabulary. + $terms = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid)); + $count = count($terms); + $this->assertTrue($count == 5, t('Correct number of terms were loaded. !count terms.', array('!count' => $count))); + + // Load the same terms again by tid. + $terms2 = taxonomy_term_load_multiple(array_keys($terms)); + $this->assertTrue($count == count($terms2), t('Five terms were loaded by tid')); + $this->assertEqual($terms, $terms2, t('Both arrays contain the same terms')); + + // Load the terms by tid, with a condition on vid. + $terms3 = taxonomy_term_load_multiple(array_keys($terms2), array('vid' => $vocabulary->vid)); + $this->assertEqual($terms2, $terms3); + + // Remove one term from the array, then delete it. + $deleted = array_shift($terms3); + taxonomy_term_delete($deleted->tid); + $deleted_term = taxonomy_term_load($deleted->tid, TRUE); + $this->assertFalse($deleted_term); + + // Load terms from the vocabulary by vid. + $terms4 = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid), TRUE); + $this->assertTrue(count($terms4 == 4), t('Correct number of terms were loaded.')); + $this->assertFalse(isset($terms4[$deleted->tid])); + } +} |