You are here

function AsafCommonTests::testAjaxButtons in Asaf (ajax submit for any form) 7

Same name and namespace in other branches
  1. 8 tests/asaf.test \AsafCommonTests::testAjaxButtons()

File

tests/asaf.test, line 51

Class

AsafCommonTests

Code

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'));
}