Chris@0: drupalLogin($this->drupalCreateUser(['administer taxonomy'])); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Create a vocabulary and some taxonomy terms, ensuring they're loaded Chris@0: * correctly using entity_load_multiple(). Chris@0: */ Chris@0: public function testTaxonomyTermMultipleLoad() { Chris@0: // Create a vocabulary. Chris@0: $vocabulary = $this->createVocabulary(); Chris@0: Chris@0: // Create five terms in the vocabulary. Chris@0: $i = 0; Chris@0: while ($i < 5) { Chris@0: $i++; Chris@0: $this->createTerm($vocabulary); Chris@0: } Chris@0: // Load the terms from the vocabulary. Chris@0: $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]); Chris@0: $count = count($terms); Chris@0: $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', ['@count' => $count])); Chris@0: Chris@0: // Load the same terms again by tid. Chris@0: $terms2 = Term::loadMultiple(array_keys($terms)); Chris@0: $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.'); Chris@0: $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.'); Chris@0: Chris@0: // Remove one term from the array, then delete it. Chris@0: $deleted = array_shift($terms2); Chris@0: $deleted->delete(); Chris@0: $deleted_term = Term::load($deleted->id()); Chris@0: $this->assertFalse($deleted_term); Chris@0: Chris@0: // Load terms from the vocabulary by vid. Chris@0: $terms3 = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]); Chris@0: $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.'); Chris@0: $this->assertFalse(isset($terms3[$deleted->id()])); Chris@0: Chris@0: // Create a single term and load it by name. Chris@0: $term = $this->createTerm($vocabulary); Chris@0: $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $term->getName()]); Chris@0: $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.'); Chris@0: $loaded_term = reset($loaded_terms); Chris@0: $this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.'); Chris@0: } Chris@0: Chris@0: }