You are here

class AsafCommonTests in Asaf (ajax submit for any form) 8

Same name and namespace in other branches
  1. 7 tests/asaf.test \AsafCommonTests

Hierarchy

Expanded class hierarchy of AsafCommonTests

File

tests/asaf.test, line 39

View source
class AsafCommonTests extends AsafBaseTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Asaf common tests',
      'description' => 'Asaf tests',
      'group' => 'Asaf',
    );
  }

  /*
   * Check ajax handling
   */
  function testAjaxButtons() {

    // Simples form
    variable_set('asaf_forms', "asaf_example_gui_simplest");
    $this
      ->drupalGet('examples/asaf_example/gui/simplest');
    $settings = $this
      ->drupalGetSettings();
    $buttonIds = array_keys($this
      ->getButtons('asaf-example-gui-simplest'));
    $this
      ->assertTrue(isset($settings['ajax'][reset($buttonIds)]), t('Submit button is ajaxified'));

    // Check single button enabling
    variable_set('asaf_forms', "asaf_example_gui_simplest\nasaf_example_gui_buttons@actions][decrement");
    $this
      ->drupalGet('examples/asaf_example/gui/buttons');
    $settings = $this
      ->drupalGetSettings();
    $buttons = $this
      ->getButtons('asaf-example-gui-buttons');
    $enabledButtons = array_keys(array_intersect_key($buttons, $settings['ajax']));
    $this
      ->assertTrue(count($enabledButtons) == 1 && strpos(reset($enabledButtons), 'actions-decrement') !== FALSE, t('Single button ajaxified correctly'));

    // Check excluded button
    variable_set('asaf_forms', "asaf_example_gui_simplest\nasaf_example_gui_buttons@-actions][multiply");
    $this
      ->drupalGet('examples/asaf_example/gui/buttons');
    $settings = $this
      ->drupalGetSettings();
    $buttons = $this
      ->getButtons('asaf-example-gui-buttons');
    $excludedButtons = array_keys(array_diff_key($buttons, $settings['ajax']));
    $this
      ->assertTrue(reset($excludedButtons) == 'edit-multiply', t('Button excluded correctly'));

    // Check ajax url when pagecache is enabled
    variable_set('cache', TRUE);
    $this
      ->drupalGet('examples/asaf_example/api/simplest');
    $settings = $this
      ->drupalGetSettings();
    $buttonIds = array_keys($this
      ->getButtons('asaf-example-api-simplest'));
    $this
      ->assertTrue($settings['ajax'][reset($buttonIds)]['url'] == '/system/ajax/asaf/pagecache', t('Correct ajax url when pagecache is enabled'));
  }

  /*
   * Check ajax handling
   */
  function testFormSubmit() {
    $this
      ->drupalGet('examples/asaf_example/api/simplest');
    $this
      ->initAsafFormWrapper();
    $buttonIds = array_keys($this
      ->getButtons('asaf-example-api-simplest'));
    $buttonId = reset($buttonIds);
    $settings = $this
      ->drupalGetSettings();
    $ajax_setting = $settings['ajax'][$buttonId];
    $this
      ->drupalPostAJAX(NULL, array(), 'op', NULL, array(), array(), NULL, $ajax_setting);
    $this
      ->assertText('Name field is required.', t('Checking ajax validate'));
    $edit = array(
      'name' => t('Anka'),
    );
    $this
      ->drupalGet('examples/asaf_example/api/simplest');
    $this
      ->initAsafFormWrapper();
    $buttonIds = array_keys($this
      ->getButtons('asaf-example-api-simplest'));
    $buttonId = reset($buttonIds);
    $settings = $this
      ->drupalGetSettings();
    $ajax_setting = $settings['ajax'][$buttonId];
    $this
      ->drupalPostAJAX(NULL, $edit, 'op', NULL, array(), array(), NULL, $ajax_setting);
    $this
      ->assertText('Specified name: Anka', t('Checking ajax submit'));
  }

}

Members