Mercurial > hg > isophonics-drupal-site
view core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line source
<?php namespace Drupal\Tests\taxonomy\Functional; use Drupal\taxonomy\Entity\Term; /** * Tests the loading of multiple taxonomy terms at once. * * @group taxonomy */ class LoadMultipleTest extends TaxonomyTestBase { protected function setUp() { parent::setUp(); $this->drupalLogin($this->drupalCreateUser(['administer taxonomy'])); } /** * Create a vocabulary and some taxonomy terms, ensuring they're loaded * correctly using entity_load_multiple(). */ public function testTaxonomyTermMultipleLoad() { // Create a vocabulary. $vocabulary = $this->createVocabulary(); // Create five terms in the vocabulary. $i = 0; while ($i < 5) { $i++; $this->createTerm($vocabulary); } // Load the terms from the vocabulary. $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]); $count = count($terms); $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', ['@count' => $count])); // Load the same terms again by tid. $terms2 = Term::loadMultiple(array_keys($terms)); $this->assertEqual($count, count($terms2), 'Five terms were loaded by tid.'); $this->assertEqual($terms, $terms2, 'Both arrays contain the same terms.'); // Remove one term from the array, then delete it. $deleted = array_shift($terms2); $deleted->delete(); $deleted_term = Term::load($deleted->id()); $this->assertFalse($deleted_term); // Load terms from the vocabulary by vid. $terms3 = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]); $this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.'); $this->assertFalse(isset($terms3[$deleted->id()])); // Create a single term and load it by name. $term = $this->createTerm($vocabulary); $loaded_terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $term->getName()]); $this->assertEqual(count($loaded_terms), 1, 'One term was loaded.'); $loaded_term = reset($loaded_terms); $this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.'); } }