Changing weights on the vocabulary overview with two or more vocabularies.
function testTaxonomyAdminChangingWeights() {
// Create some vocabularies.
for ($i = 0; $i < 10; $i++) {
$this
->createVocabulary();
}
// Get all vocabularies and change their weights.
$vocabularies = taxonomy_vocabulary_load_multiple();
$edit = array();
foreach ($vocabularies as $key => $vocabulary) {
$weight = -$vocabulary->weight;
$vocabularies[$key]->weight = $weight;
$edit['vocabularies[' . $key . '][weight]'] = $weight;
}
// Saving the new weights via the interface.
$this
->drupalPost('admin/structure/taxonomy', $edit, t('Save'));
// Load the vocabularies from the database.
$this->container
->get('plugin.manager.entity')
->getStorageController('taxonomy_vocabulary')
->resetCache();
$new_vocabularies = taxonomy_vocabulary_load_multiple();
taxonomy_vocabulary_sort($new_vocabularies);
// Check that the weights are saved in the database correctly.
foreach ($vocabularies as $key => $vocabulary) {
$this
->assertEqual($new_vocabularies[$key]->weight, $vocabularies[$key]->weight, 'The vocabulary weight was changed.');
}
}