1 ajax.test public AJAXFormPageCacheTestCase::testSimpleAJAXFormValue()

Create a simple form, then POST to system/ajax to change to it.

File

core/modules/simpletest/tests/ajax.test, line 505
Ajax Tests.

Class

AJAXFormPageCacheTestCase
Test Ajax forms when page caching for anonymous users is turned on.

Code

public function testSimpleAJAXFormValue() {
  $this->backdropGet('ajax_forms_test_get_form');
  $this->assertEqual($this->backdropGetHeader('X-Backdrop-Cache'), 'MISS', 'Page was not cached.');
  $build_id_initial = $this->getFormBuildId();

  $edit = array('select' => 'green');
  $commands = $this->backdropPostAJAX(NULL, $edit, 'select');
  $build_id_first_ajax = $this->getFormBuildId();
  $this->assertNotEqual($build_id_initial, $build_id_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
  $expected = array(
    'command' => 'updateBuildId',
    'old' => $build_id_initial,
    'new' => $build_id_first_ajax,
  );
  $this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');

  $edit = array('select' => 'red');
  $commands = $this->backdropPostAJAX(NULL, $edit, 'select');
  $build_id_second_ajax = $this->getFormBuildId();
  $this->assertEqual($build_id_first_ajax, $build_id_second_ajax, 'Build id remains the same on subsequent AJAX submissions');

  // Repeat the test sequence but this time with a page loaded from the cache.
  $this->backdropGet('ajax_forms_test_get_form');
  $this->assertEqual($this->backdropGetHeader('X-Backdrop-Cache'), 'HIT', 'Page was cached.');
  $build_id_from_cache_initial = $this->getFormBuildId();
  $this->assertEqual($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request');

  $edit = array('select' => 'green');
  $commands = $this->backdropPostAJAX(NULL, $edit, 'select');
  $build_id_from_cache_first_ajax = $this->getFormBuildId();
  $this->assertNotEqual($build_id_from_cache_initial, $build_id_from_cache_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
  $this->assertNotEqual($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused');
  $expected = array(
    'command' => 'updateBuildId',
    'old' => $build_id_from_cache_initial,
    'new' => $build_id_from_cache_first_ajax,
  );
  $this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');

  $edit = array('select' => 'red');
  $commands = $this->backdropPostAJAX(NULL, $edit, 'select');
  $build_id_from_cache_second_ajax = $this->getFormBuildId();
  $this->assertEqual($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id remains the same on subsequent AJAX submissions');
}