You are here

public function AdminUITest::doFlagChangeWeights in Flag 8.4

Create further flags and change the weights using the draggable list.

1 call to AdminUITest::doFlagChangeWeights()
AdminUITest::testFlagAdmin in tests/src/Functional/AdminUITest.php
Test basic flag admin.

File

tests/src/Functional/AdminUITest.php, line 207

Class

AdminUITest
Tests the Flag admin UI.

Namespace

Drupal\Tests\flag\Functional

Code

public function doFlagChangeWeights() {
  $flag_weights_to_set = [];

  // We have one flag already.
  $flag_weights_to_set[$this->flagId] = 0;
  foreach (range(1, 10) as $i) {
    $flag = $this
      ->createFlag();
    $flag_weights_to_set[$flag
      ->id()] = -$i;
  }
  $edit = [];
  foreach ($flag_weights_to_set as $id => $weight) {
    $edit['flags[' . $id . '][weight]'] = $weight;
  }

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

  // Load the all the flags.
  $all_flags = $this->container
    ->get('entity_type.manager')
    ->getStorage('flag')
    ->loadMultiple();

  // Check that the weights for each flag are saved in the database correctly.
  foreach ($all_flags as $id => $flag) {
    $this
      ->assertEqual($all_flags[$id]
      ->get('weight'), $flag_weights_to_set[$id], 'The flag weight was changed.');
  }
}