Projet

Général

Profil

Révision 42e6daf3

Ajouté par Julien Enselme il y a environ 10 ans

Update drupal 7.26 -> 7.27

Voir les différences:

drupal7/modules/simpletest/tests/ajax.test
497 497
  }
498 498
}
499 499

  
500
/**
501
 * Test Ajax forms when page caching for anonymous users is turned on.
502
 */
503
class AJAXFormPageCacheTestCase extends AJAXTestCase {
504
  protected $profile = 'testing';
505

  
506
  public static function getInfo() {
507
    return array(
508
      'name' => 'AJAX forms on cached pages',
509
      'description' => 'Tests that AJAX forms work properly for anonymous users on cached pages.',
510
      'group' => 'AJAX',
511
    );
512
  }
513

  
514
  public function setUp() {
515
    parent::setUp();
516

  
517
    variable_set('cache', TRUE);
518
  }
519

  
520
  /**
521
   * Return the build id of the current form.
522
   */
523
  protected function getFormBuildId() {
524
    $build_id_fields = $this->xpath('//input[@name="form_build_id"]');
525
    $this->assertEqual(count($build_id_fields), 1, 'One form build id field on the page');
526
    return (string) $build_id_fields[0]['value'];
527
  }
528

  
529
  /**
530
   * Create a simple form, then POST to system/ajax to change to it.
531
   */
532
  public function testSimpleAJAXFormValue() {
533
    $this->drupalGet('ajax_forms_test_get_form');
534
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
535
    $build_id_initial = $this->getFormBuildId();
536

  
537
    $edit = array('select' => 'green');
538
    $commands = $this->drupalPostAJAX(NULL, $edit, 'select');
539
    $build_id_first_ajax = $this->getFormBuildId();
540
    $this->assertNotEqual($build_id_initial, $build_id_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
541
    $expected = array(
542
      'command' => 'updateBuildId',
543
      'old' => $build_id_initial,
544
      'new' => $build_id_first_ajax,
545
    );
546
    $this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');
547

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

  
553
    // Repeat the test sequence but this time with a page loaded from the cache.
554
    $this->drupalGet('ajax_forms_test_get_form');
555
    $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
556
    $build_id_from_cache_initial = $this->getFormBuildId();
557
    $this->assertEqual($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request');
558

  
559
    $edit = array('select' => 'green');
560
    $commands = $this->drupalPostAJAX(NULL, $edit, 'select');
561
    $build_id_from_cache_first_ajax = $this->getFormBuildId();
562
    $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');
563
    $this->assertNotEqual($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused');
564
    $expected = array(
565
      'command' => 'updateBuildId',
566
      'old' => $build_id_from_cache_initial,
567
      'new' => $build_id_from_cache_first_ajax,
568
    );
569
    $this->assertCommand($commands, $expected, 'Build id change command issued on first AJAX submission');
570

  
571
    $edit = array('select' => 'red');
572
    $commands = $this->drupalPostAJAX(NULL, $edit, 'select');
573
    $build_id_from_cache_second_ajax = $this->getFormBuildId();
574
    $this->assertEqual($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id remains the same on subsequent AJAX submissions');
575
  }
576
}
577

  
578

  
500 579
/**
501 580
 * Miscellaneous Ajax tests using ajax_test module.
502 581
 */

Formats disponibles : Unified diff