You are here

function VocabularyUiTest::testTaxonomyAdminChangingWeights in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/Tests/VocabularyUiTest.php \Drupal\taxonomy\Tests\VocabularyUiTest::testTaxonomyAdminChangingWeights()

Changing weights on the vocabulary overview with two or more vocabularies.

File

core/modules/taxonomy/src/Tests/VocabularyUiTest.php, line 89
Contains \Drupal\taxonomy\Tests\VocabularyUiTest.

Class

VocabularyUiTest
Tests the taxonomy vocabulary interface.

Namespace

Drupal\taxonomy\Tests

Code

function testTaxonomyAdminChangingWeights() {

  // Create some vocabularies.
  for ($i = 0; $i < 10; $i++) {
    $this
      ->createVocabulary();
  }

  // Get all vocabularies and change their weights.
  $vocabularies = Vocabulary::loadMultiple();
  $edit = array();
  foreach ($vocabularies as $key => $vocabulary) {
    $weight = -$vocabulary
      ->get('weight');
    $vocabularies[$key]
      ->set('weight', $weight);
    $edit['vocabularies[' . $key . '][weight]'] = $weight;
  }

  // Saving the new weights via the interface.
  $this
    ->drupalPostForm('admin/structure/taxonomy', $edit, t('Save'));

  // Load the vocabularies from the database.
  $this->container
    ->get('entity.manager')
    ->getStorage('taxonomy_vocabulary')
    ->resetCache();
  $new_vocabularies = Vocabulary::loadMultiple();

  // Check that the weights are saved in the database correctly.
  foreach ($vocabularies as $key => $vocabulary) {
    $this
      ->assertEqual($new_vocabularies[$key]
      ->get('weight'), $vocabularies[$key]
      ->get('weight'), 'The vocabulary weight was changed.');
  }
}