You are here

public function FlexsliderTest::testOptionSetForm in Flex Slider 8.2

Test the option set form.

File

tests/src/Functional/FlexsliderTest.php, line 168

Class

FlexsliderTest
Test the FlexSlider presets, configuration options and permission controls.

Namespace

Drupal\Tests\flexslider\Functional

Code

public function testOptionSetForm() {

  // Login with admin user.
  $this
    ->drupalLogin($this->adminUser);

  // ------------ Test Option Set Add ------------ //
  // Load create form.
  $this
    ->drupalGet('admin/config/media/flexslider/add');
  $this
    ->assertResponse(200);

  // Save new optionset.
  $optionset = [];
  $optionset['label'] = $this
    ->t('testset');
  $optionset['id'] = 'testset';
  $this
    ->drupalPostForm('admin/config/media/flexslider/add', $optionset, $this
    ->t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertText('Created the testset FlexSlider optionset.');

  // Attempt to save option set of the same name again.
  $this
    ->drupalPostForm('admin/config/media/flexslider/add', $optionset, $this
    ->t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertText('The machine-readable name is already in use. It must be unique.');

  // ------------ Test Option Set Edit ------------ //
  // Attempt to save each option value.
  $options = $this
    ->getTestOptions();
  foreach ($options['valid'] as $testset) {
    $this
      ->drupalPostForm('admin/config/media/flexslider/default', $testset, $this
      ->t('Save'));
    $this
      ->assertResponse(200);

    // Test saved values loaded into form.
    $this
      ->drupalGet('admin/config/media/flexslider/default');
    $this
      ->assertResponse(200);
    foreach ($testset as $key => $option) {
      $this
        ->assertFieldByName($key, $option);
    }
  }

  // ------------ Test Option Set Delete ------------ //.
  $testset = Flexslider::load('testset');

  // Test the delete workflow.
  $this
    ->drupalGet("admin/config/media/flexslider/{$testset->id()}/delete");
  $this
    ->assertResponse(200);
  $this
    ->assertText("Are you sure you want to delete {$testset->label()}?");
  $this
    ->drupalPostForm("admin/config/media/flexslider/{$testset->id()}/delete", [], $this
    ->t('Delete'));
  $this
    ->assertResponse(200);
  $this
    ->assertText("Deleted the {$testset->label()} FlexSlider optionset.");
}