You are here

public function SlickTestCase::testOptionSetForm in Slick Carousel 7.2

Tests Slick optionset form.

File

tests/slick.test, line 206
Provides test cases for Slick carousel based on flexslider.test.

Class

SlickTestCase
Tests the Slick optionsets, configuration options and permission controls.

Code

public function testOptionSetForm() {
  module_load_include('inc', 'slick', 'includes/slick.admin');

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

  // Test the optionset add.
  // Load create form.
  $this
    ->drupalGet('admin/config/media/slick/add');
  $this
    ->assertResponse(200, 'Administrative user can reach the "Add" form.');

  // Save the new optionset.
  $optionset = array();
  $optionset['label'] = 'Testset';
  $optionset['name'] = 'testset';
  $this
    ->drupalPost('admin/config/media/slick/add', $optionset, t('Save'));
  $this
    ->assertResponse(200);
  $this
    ->assertTrue(slick_optionset_exists($optionset['name']), t('Successfully created the new optionset: @label', array(
    '@label' => $optionset['label'],
  )));

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

  // Test the optionset edit.
  $options = $this
    ->getOptions();
  foreach ($options['valid'] as $edit) {

    // Attempts to save each option value.
    $xpath = array();
    foreach ($edit as $key => $value) {
      $xpath["options[settings][{$key}]"] = $value;
    }
    $this
      ->drupalPost('admin/config/media/slick/list/default/edit', $xpath, t('Save'));
    $this
      ->assertResponse(200, 'Default optionset overriden.');

    // Test saved values loaded into form.
    $this
      ->drupalGet('admin/config/media/slick/list/default/edit');
    $this
      ->assertResponse(200, 'Default optionset reloaded.');
    foreach ($edit as $v => $value) {
      $read_value = $this
        ->getPrintedValue($value);
      $this
        ->assertFieldByName("options[settings][{$v}]", $value, t("@v:<strong>@value</strong> inserted correctly.", array(
        '@value' => $read_value,
        '@v' => $v,
      )));
    }
  }

  // Test the optionset delete.
  $testset = slick_optionset_load('testset');

  // Test the delete workflow.
  $this
    ->drupalGet("admin/config/media/slick/list/{$testset->name}/delete");
  $this
    ->assertResponse(200);
  $this
    ->assertText("Are you sure you want to delete {$testset->name}?", 'Delete confirmation form loaded.');
  $this
    ->drupalPost("admin/config/media/slick/list/{$testset->name}/delete", '', 'Delete');
  $this
    ->assertResponse(200);
  $this
    ->assertText("The item has been deleted.", 'Deleted Testset using form.');
}