You are here

public function AuthcacheTestAdminWidgets::testDurationSelectDefaultValue in Authenticated User Page Caching (Authcache) 7.2

Test duration select widget.

File

tests/authcache.widget.test, line 412
Test cases for pluggable cache backends.

Class

AuthcacheTestAdminWidgets
Cover authcache module.

Code

public function testDurationSelectDefaultValue() {
  $durations = array(
    60,
    3600,
  );
  $form = system_settings_form(array(
    'maxage' => array(
      '#title' => $this
        ->randomName(8),
      '#description' => $this
        ->randomName(32),
      '#type' => 'authcache_duration_select',
      '#durations' => $durations,
      '#default_value' => 60,
    ),
  ));
  $form_stub = $this->stubmod
    ->hook('form', $form);
  $this
    ->drupalGet('authcache-widget-test-form');
  $this
    ->assertStub($form_stub, HookStub::once());
  $this
    ->assertOptionSelected('edit-maxage-select', 60);
  $this
    ->assertNoOptionSelected('edit-maxage-select', 3600);
  $this
    ->assertNoOptionSelected('edit-maxage-select', 'custom');
  $this
    ->assertFieldById('edit-maxage-custom', '');

  // Default value is custom timespan.
  $form = system_settings_form(array(
    'maxage' => array(
      '#title' => $this
        ->randomName(8),
      '#description' => $this
        ->randomName(32),
      '#type' => 'authcache_duration_select',
      '#durations' => $durations,
      '#default_value' => 42,
    ),
  ));
  $form_stub = $this->stubmod
    ->hook('form', $form);
  $this
    ->drupalGet('authcache-widget-test-form');
  $this
    ->assertStub($form_stub, HookStub::once());
  $this
    ->assertNoOptionSelected('edit-maxage-select', 60);
  $this
    ->assertNoOptionSelected('edit-maxage-select', 3600);
  $this
    ->assertOptionSelected('edit-maxage-select', 'custom');
  $this
    ->assertFieldById('edit-maxage-custom', '42');
}