You are here

public function GlobalConfigurationTest::testGlobalConfigForm in Collapsiblock 3.x

Same name and namespace in other branches
  1. 4.x tests/src/Functional/GlobalConfigurationTest.php \Drupal\Tests\collapsiblock\Functional\GlobalConfigurationTest::testGlobalConfigForm()

Test the global config form exists and functions correctly.

File

tests/src/Functional/GlobalConfigurationTest.php, line 34

Class

GlobalConfigurationTest
Test the Collapsiblock global configuration form.

Namespace

Drupal\Tests\collapsiblock\Functional

Code

public function testGlobalConfigForm() {
  $this
    ->drupalLogin($this->collapsiblockGlobalAdminUser);
  $this
    ->drupalGet('admin/config/user-interface/collapsiblock');

  // Test that the form controls are present, have the expected options, and
  // are set to the default configuration values.
  $this
    ->assertSession()
    ->checkboxChecked('edit-default-action-1');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-2');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-3');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-4');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-5');
  $this
    ->assertSession()
    ->checkboxNotChecked('active_pages');
  $this
    ->assertSession()
    ->checkboxChecked('edit-slide-type-1');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-slide-type-2');
  $this
    ->assertSession()
    ->selectExists('slide_speed');
  $this
    ->assertSession()
    ->optionExists('slide_speed', 50);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 100);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 200)
    ->hasAttribute('selected');
  $this
    ->assertSession()
    ->optionExists('slide_speed', 300);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 400);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 500);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 700);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 1000);
  $this
    ->assertSession()
    ->optionExists('slide_speed', 1300);

  // Submit the form with new values.
  $configFormValues = [];
  $configFormValues['default_action'] = 2;
  $configFormValues['active_pages'] = 1;
  $configFormValues['slide_type'] = 2;
  $configFormValues['slide_speed'] = 500;
  $this
    ->drupalPostForm('admin/config/user-interface/collapsiblock', $configFormValues, t('Save configuration'));

  // Test that the form controls now show the updated configuration.
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-1');
  $this
    ->assertSession()
    ->checkboxChecked('edit-default-action-2');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-3');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-4');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-default-action-5');
  $this
    ->assertSession()
    ->checkboxChecked('active_pages');
  $this
    ->assertSession()
    ->checkboxNotChecked('edit-slide-type-1');
  $this
    ->assertSession()
    ->checkboxChecked('edit-slide-type-2');
  $this
    ->assertSession()
    ->optionExists('slide_speed', 500)
    ->hasAttribute('selected');
}