You are here

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

Test duration select widget.

File

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

Class

AuthcacheTestAdminWidgets
Cover authcache module.

Code

public function testDurationSelect() {
  $durations = array(
    0,
    mt_rand(10, 100),
    mt_rand(100, 1000),
    mt_rand(1000, 10000),
  );
  $form = system_settings_form(array(
    'maxage' => array(
      '#title' => $this
        ->randomName(8),
      '#description' => $this
        ->randomName(32),
      '#type' => 'authcache_duration_select',
      '#zero_duration' => $this
        ->randomName(16),
      '#durations' => $durations,
    ),
  ));
  $form_stub = $this->stubmod
    ->hook('form', $form);
  $this
    ->drupalGet('authcache-widget-test-form');
  $this
    ->assertStub($form_stub, HookStub::once());
  $this
    ->assertText($form['maxage']['#title']);
  $this
    ->assertText($form['maxage']['#description']);

  // Durations are expected to have been converted in select options formatted
  // with format_interval.
  $elements = $this
    ->xpath('//select[@id=:id]', array(
    ':id' => 'edit-maxage-select',
  ));
  $this
    ->assertEqual(1, count($elements));
  $options = array();
  foreach ($this
    ->getAllOptions($elements[0]) as $option) {
    $options[(string) $option
      ->attributes()->value] = (string) $option;
  }
  $expect_options = array();
  foreach ($durations as $seconds) {
    $expect_options[$seconds] = format_interval($seconds);
  }
  $expect_options[0] = $form['maxage']['#zero_duration'];
  $expect_options['custom'] = t('Custom');
  $this
    ->assertEqual($expect_options, $options);

  // Custom field should be empty.
  $this
    ->assertFieldById('edit-maxage-custom', '');
}