drupal core updated to 7.28

This commit is contained in:
Bachir Soussi Chiadmi
2014-07-07 18:53:44 +02:00
parent 10de06dd70
commit c3011cef61
263 changed files with 3331 additions and 8894 deletions

View File

@@ -82,6 +82,10 @@ class FormsTestCase extends DrupalWebTestCase {
$form_state['input'][$element] = $empty;
$form_state['input']['form_id'] = $form_id;
$form_state['method'] = 'post';
// The form token CSRF protection should not interfere with this test,
// so we bypass it by marking this test form as programmed.
$form_state['programmed'] = TRUE;
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
$errors = form_get_errors();
@@ -614,6 +618,18 @@ class FormValidationTestCase extends DrupalWebTestCase {
$this->drupalPost(NULL, array(), 'Save');
$this->assertNoFieldByName('name', 'Form element was hidden.');
$this->assertText('Name value: element_validate_access', 'Value for inaccessible form element exists.');
// Verify that #validate handlers don't run if the CSRF token is invalid.
$this->drupalLogin($this->drupalCreateUser());
$this->drupalGet('form-test/validate');
$edit = array(
'name' => 'validate',
'form_token' => 'invalid token'
);
$this->drupalPost(NULL, $edit, 'Save');
$this->assertNoFieldByName('name', '#value changed by #validate', 'Form element #value was not altered.');
$this->assertNoText('Name value: value changed by form_set_value() in #validate', 'Form element value in $form_state was not altered.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
}
/**
@@ -941,6 +957,10 @@ class FormsElementsTableSelectFunctionalTest extends DrupalWebTestCase {
$form_state['input'] = $edit;
$form_state['input']['form_id'] = $form_id;
// The form token CSRF protection should not interfere with this test,
// so we bypass it by marking this test form as programmed.
$form_state['programmed'] = TRUE;
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
@@ -1136,6 +1156,182 @@ class FormsFormStorageTestCase extends DrupalWebTestCase {
$this->assertText('State persisted.');
}
}
/**
* Verify that the form build-id remains the same when validation errors
* occur on a mutable form.
*/
function testMutableForm() {
// Request the form with 'cache' query parameter to enable form caching.
$this->drupalGet('form_test/form-storage', array('query' => array('cache' => 1)));
$buildIdFields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($buildIdFields), 1, 'One form build id field on the page');
$buildId = (string) $buildIdFields[0]['value'];
// Trigger validation error by submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Continue submit');
// Verify that the build-id did not change.
$this->assertFieldByName('form_build_id', $buildId, 'Build id remains the same when form validation fails');
}
/**
* Verifies that form build-id is regenerated when loading an immutable form
* from the cache.
*/
function testImmutableForm() {
// Request the form with 'cache' query parameter to enable form caching.
$this->drupalGet('form_test/form-storage', array('query' => array('cache' => 1, 'immutable' => 1)));
$buildIdFields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($buildIdFields), 1, 'One form build id field on the page');
$buildId = (string) $buildIdFields[0]['value'];
// Trigger validation error by submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Continue submit');
// Verify that the build-id did change.
$this->assertNoFieldByName('form_build_id', $buildId, 'Build id changes when form validation fails');
// Retrieve the new build-id.
$buildIdFields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($buildIdFields), 1, 'One form build id field on the page');
$buildId = (string) $buildIdFields[0]['value'];
// Trigger validation error by again submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Continue submit');
// Verify that the build-id does not change the second time.
$this->assertFieldByName('form_build_id', $buildId, 'Build id remains the same when form validation fails subsequently');
}
/**
* Verify that existing contrib code cannot overwrite immutable form state.
*/
public function testImmutableFormLegacyProtection() {
$this->drupalGet('form_test/form-storage', array('query' => array('cache' => 1, 'immutable' => 1)));
$build_id_fields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($build_id_fields), 1, 'One form build id field on the page');
$build_id = (string) $build_id_fields[0]['value'];
// Try to poison the form cache.
$original = $this->drupalGetAJAX('form_test/form-storage-legacy/' . $build_id);
$this->assertEqual($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded');
$this->assertNotEqual($original['form']['#build_id'], $build_id, 'New build_id was generated');
// Assert that a watchdog message was logged by form_set_cache.
$status = (bool) db_query_range('SELECT 1 FROM {watchdog} WHERE message = :message', 0, 1, array(':message' => 'Form build-id mismatch detected while attempting to store a form in the cache.'));
$this->assert($status, 'A watchdog message was logged by form_set_cache');
// Ensure that the form state was not poisoned by the preceeding call.
$original = $this->drupalGetAJAX('form_test/form-storage-legacy/' . $build_id);
$this->assertEqual($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded');
$this->assertNotEqual($original['form']['#build_id'], $build_id, 'New build_id was generated');
$this->assert(empty($original['form']['#poisoned']), 'Original form structure was preserved');
$this->assert(empty($original['form_state']['poisoned']), 'Original form state was preserved');
}
}
/**
* Test the form storage when page caching for anonymous users is turned on.
*/
class FormsFormStoragePageCacheTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'Forms using form storage on cached pages',
'description' => 'Tests a form using form storage and makes sure validation and caching works when page caching for anonymous users is turned on.',
'group' => 'Form API',
);
}
public function setUp() {
parent::setUp('form_test');
variable_set('cache', TRUE);
}
/**
* Return the build id of the current form.
*/
protected function getFormBuildId() {
$build_id_fields = $this->xpath('//input[@name="form_build_id"]');
$this->assertEqual(count($build_id_fields), 1, 'One form build id field on the page');
return (string) $build_id_fields[0]['value'];
}
/**
* Build-id is regenerated when validating cached form.
*/
public function testValidateFormStorageOnCachedPage() {
$this->drupalGet('form_test/form-storage-page-cache');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$this->assertText('No old build id', 'No old build id on the page');
$build_id_initial = $this->getFormBuildId();
// Trigger validation error by submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText($build_id_initial, 'Old build id on the page');
$build_id_first_validation = $this->getFormBuildId();
$this->assertNotEqual($build_id_initial, $build_id_first_validation, 'Build id changes when form validation fails');
// Trigger validation error by again submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText('No old build id', 'No old build id on the page');
$build_id_second_validation = $this->getFormBuildId();
$this->assertEqual($build_id_first_validation, $build_id_second_validation, 'Build id remains the same when form validation fails subsequently');
// Repeat the test sequence but this time with a page loaded from the cache.
$this->drupalGet('form_test/form-storage-page-cache');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
$this->assertText('No old build id', 'No old build id on the page');
$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');
// Trigger validation error by submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText($build_id_initial, 'Old build id is initial build id');
$build_id_from_cache_first_validation = $this->getFormBuildId();
$this->assertNotEqual($build_id_initial, $build_id_from_cache_first_validation, 'Build id changes when form validation fails');
$this->assertNotEqual($build_id_first_validation, $build_id_from_cache_first_validation, 'Build id from first user is not reused');
// Trigger validation error by again submitting an empty title.
$edit = array('title' => '');
$this->drupalPost(NULL, $edit, 'Save');
$this->assertText('No old build id', 'No old build id on the page');
$build_id_from_cache_second_validation = $this->getFormBuildId();
$this->assertEqual($build_id_from_cache_first_validation, $build_id_from_cache_second_validation, 'Build id remains the same when form validation fails subsequently');
}
/**
* Build-id is regenerated when rebuilding cached form.
*/
public function testRebuildFormStorageOnCachedPage() {
$this->drupalGet('form_test/form-storage-page-cache');
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
$this->assertText('No old build id', 'No old build id on the page');
$build_id_initial = $this->getFormBuildId();
// Trigger rebuild, should regenerate build id.
$edit = array('title' => 'something');
$this->drupalPost(NULL, $edit, 'Rebuild');
$this->assertText($build_id_initial, 'Initial build id as old build id on the page');
$build_id_first_rebuild = $this->getFormBuildId();
$this->assertNotEqual($build_id_initial, $build_id_first_rebuild, 'Build id changes on first rebuild.');
// Trigger subsequent rebuild, should regenerate the build id again.
$edit = array('title' => 'something');
$this->drupalPost(NULL, $edit, 'Rebuild');
$this->assertText($build_id_first_rebuild, 'First build id as old build id on the page');
$build_id_second_rebuild = $this->getFormBuildId();
$this->assertNotEqual($build_id_first_rebuild, $build_id_second_rebuild, 'Build id changes on second rebuild.');
}
}
/**
@@ -1466,6 +1662,16 @@ class FormsProgrammaticTestCase extends DrupalWebTestCase {
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => 2)), TRUE);
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => NULL)), TRUE);
// Test that a programmatic form submission can successfully submit values
// even for fields where the #access property is FALSE.
$this->submitForm(array('textfield' => 'dummy value', 'textfield_no_access' => 'test value'), TRUE);
// Test that #access is respected for programmatic form submissions when
// requested to do so.
$submitted_values = array('textfield' => 'dummy value', 'textfield_no_access' => 'test value');
$expected_values = array('textfield' => 'dummy value', 'textfield_no_access' => 'default value');
$form_state = array('programmed_bypass_access_check' => FALSE);
$this->submitForm($submitted_values, TRUE, $expected_values, $form_state);
// Test that a programmatic form submission can correctly click a button
// that limits validation errors based on user input. Since we do not
// submit any values for "textfield" here and the textfield is required, we
@@ -1488,10 +1694,18 @@ class FormsProgrammaticTestCase extends DrupalWebTestCase {
* @param $valid_input
* A boolean indicating whether or not the form submission is expected to
* be valid.
* @param $expected_values
* (Optional) An array of field values that are expected to be stored by
* the form submit handler. If not set, the submitted $values are assumed
* to also be the expected stored values.
* @param $form_state
* (Optional) A keyed array containing the state of the form, to be sent in
* the call to drupal_form_submit(). The $values parameter is added to
* $form_state['values'] by default, if it is not already set.
*/
private function submitForm($values, $valid_input) {
private function submitForm($values, $valid_input, $expected_values = NULL, $form_state = array()) {
// Programmatically submit the given values.
$form_state = array('values' => $values);
$form_state += array('values' => $values);
drupal_form_submit('form_test_programmatic_form', $form_state);
// Check that the form returns an error when expected, and vice versa.
@@ -1508,7 +1722,10 @@ class FormsProgrammaticTestCase extends DrupalWebTestCase {
// By fetching the values from $form_state['storage'] we ensure that the
// submission handler was properly executed.
$stored_values = $form_state['storage']['programmatic_form_submit'];
foreach ($values as $key => $value) {
if (!isset($expected_values)) {
$expected_values = $values;
}
foreach ($expected_values as $key => $value) {
$this->assertTrue(isset($stored_values[$key]) && $stored_values[$key] == $value, format_string('Submission handler correctly executed: %stored_key is %stored_value', array('%stored_key' => $key, '%stored_value' => print_r($value, TRUE))));
}
}