public function VocabularyUiTest::testTaxonomyAdminChangingWeights in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php \Drupal\Tests\taxonomy\Functional\VocabularyUiTest::testTaxonomyAdminChangingWeights()
Changing weights on the vocabulary overview with two or more vocabularies.
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ VocabularyUiTest.php, line 93
Class
- VocabularyUiTest
- Tests the taxonomy vocabulary interface.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
public function testTaxonomyAdminChangingWeights() {
// Create some vocabularies.
for ($i = 0; $i < 10; $i++) {
$this
->createVocabulary();
}
// Get all vocabularies and change their weights.
$vocabularies = Vocabulary::loadMultiple();
$edit = [];
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
->drupalGet('admin/structure/taxonomy');
$this
->submitForm($edit, 'Save');
// Load the vocabularies from the database.
$this->container
->get('entity_type.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
->assertEquals($new_vocabularies[$key]
->get('weight'), $vocabularies[$key]
->get('weight'), 'The vocabulary weight was changed.');
}
}