From 25171a17f626695ecf984cc44b60d3eae1310b4c Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Thu, 5 Aug 2010 23:53:39 +0000 Subject: Reverting #500866. Needs more discussion. --- modules/simpletest/tests/actions.test | 20 +- modules/simpletest/tests/ajax.test | 32 +- modules/simpletest/tests/batch.test | 70 +-- modules/simpletest/tests/bootstrap.test | 164 +++--- modules/simpletest/tests/cache.test | 65 ++- modules/simpletest/tests/common.test | 458 +++++++-------- modules/simpletest/tests/database_test.test | 629 ++++++++++---------- modules/simpletest/tests/entity_query.test | 146 ++--- modules/simpletest/tests/error.test | 20 +- modules/simpletest/tests/file.test | 646 ++++++++++----------- modules/simpletest/tests/filetransfer.test | 2 +- modules/simpletest/tests/form.test | 192 +++--- modules/simpletest/tests/graph.test | 12 +- modules/simpletest/tests/image.test | 72 +-- modules/simpletest/tests/lock.test | 20 +- modules/simpletest/tests/mail.test | 2 +- modules/simpletest/tests/menu.test | 156 ++--- modules/simpletest/tests/module.test | 28 +- modules/simpletest/tests/path.test | 10 +- modules/simpletest/tests/registry.test | 6 +- modules/simpletest/tests/schema.test | 42 +- modules/simpletest/tests/session.test | 72 +-- modules/simpletest/tests/theme.test | 36 +- modules/simpletest/tests/unicode.test | 22 +- modules/simpletest/tests/update.test | 18 +- modules/simpletest/tests/upgrade/upgrade.poll.test | 14 +- modules/simpletest/tests/upgrade/upgrade.test | 13 +- modules/simpletest/tests/xmlrpc.test | 4 +- 28 files changed, 1497 insertions(+), 1474 deletions(-) (limited to 'modules/simpletest/tests') diff --git a/modules/simpletest/tests/actions.test b/modules/simpletest/tests/actions.test index 5d279daa7..8e0220d4f 100644 --- a/modules/simpletest/tests/actions.test +++ b/modules/simpletest/tests/actions.test @@ -32,8 +32,8 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { $this->drupalPost('admin/config/system/actions/configure/' . drupal_hash_base64('system_goto_action'), $edit, t('Save')); // Make sure that the new complex action was saved properly. - $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully saved the complex action."); - $this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action."); + $this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action.")); + $this->assertText($action_label, t("Make sure the action label appears on the configuration page after we've saved the complex action.")); // Make another POST request to the action edit page. $this->clickLink(t('configure')); @@ -46,9 +46,9 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { $this->drupalPost(NULL, $edit, t('Save')); // Make sure that the action updated properly. - $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action."); - $this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action."); - $this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action."); + $this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action.")); + $this->assertNoText($action_label, t("Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.")); + $this->assertText($new_action_label, t("Make sure the action label appears on the configuration page after we've updated the complex action.")); // Make sure that deletions work properly. $this->clickLink(t('delete')); @@ -56,11 +56,11 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { $this->drupalPost("admin/config/system/actions/delete/$aid", $edit, t('Delete')); // Make sure that the action was actually deleted. - $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), 'Make sure that we get a delete confirmation message.'); + $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), t('Make sure that we get a delete confirmation message.')); $this->drupalGet('admin/config/system/actions/manage'); - $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action."); + $this->assertNoText($new_action_label, t("Make sure the action label does not appear on the overview page after we've deleted the action.")); $exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchField(); - $this->assertFalse($exists, 'Make sure the action is gone from the database after being deleted.'); + $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.')); } } @@ -120,8 +120,8 @@ class ActionLoopTestCase extends DrupalWebTestCase { $loop_started = FALSE; foreach ($result as $row) { $expected_message = array_shift($expected); - $this->assertEqual($row->message, $expected_message, 'Expected message ' . $expected_message . ', got ' . $row->message . '.'); + $this->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message))); } - $this->assertTrue(empty($expected), 'All expected messages found.'); + $this->assertTrue(empty($expected), t('All expected messages found.')); } } diff --git a/modules/simpletest/tests/ajax.test b/modules/simpletest/tests/ajax.test index e711eec37..91572bda0 100644 --- a/modules/simpletest/tests/ajax.test +++ b/modules/simpletest/tests/ajax.test @@ -44,9 +44,9 @@ class AJAXFrameworkTestCase extends AJAXTestCase { function testAJAXRender() { $result = $this->drupalGetAJAX('ajax-test/render'); // Verify that JavaScript settings are contained (always first). - $this->assertIdentical($result[0]['command'], 'settings', 'drupal_add_js() settings are contained first.'); + $this->assertIdentical($result[0]['command'], 'settings', t('drupal_add_js() settings are contained first.')); // Verify that basePath is contained in JavaScript settings. - $this->assertEqual($result[0]['settings']['basePath'], base_path(), 'Base path is contained in JavaScript settings.'); + $this->assertEqual($result[0]['settings']['basePath'], base_path(), t('Base path is contained in JavaScript settings.')); } /** @@ -55,14 +55,14 @@ class AJAXFrameworkTestCase extends AJAXTestCase { function testAJAXRenderError() { $result = $this->discardSettings($this->drupalGetAJAX('ajax-test/render-error')); // Verify default error message. - $this->assertEqual($result[0]['command'], 'alert', 'ajax_render_error() invokes alert command.'); - $this->assertEqual($result[0]['text'], t('An error occurred while handling the request: The server received invalid input.'), 'Default error message is output.'); + $this->assertEqual($result[0]['command'], 'alert', t('ajax_render_error() invokes alert command.')); + $this->assertEqual($result[0]['text'], t('An error occurred while handling the request: The server received invalid input.'), t('Default error message is output.')); // Verify custom error message. $edit = array( 'message' => 'Custom error message.', ); $result = $this->discardSettings($this->drupalGetAJAX('ajax-test/render-error', array('query' => $edit))); - $this->assertEqual($result[0]['text'], $edit['message'], 'Custom error message is output.'); + $this->assertEqual($result[0]['text'], $edit['message'], t('Custom error message is output.')); } } @@ -86,9 +86,9 @@ class AJAXCommandsTestCase extends AJAXTestCase { $commands[] = ajax_command_settings(array('foo' => 42)); $result = $this->drupalGetAJAX('ajax-test/render', array('query' => array('commands' => $commands))); // Verify that JavaScript settings are contained (always first). - $this->assertIdentical($result[0]['command'], 'settings', 'drupal_add_js() settings are contained first.'); + $this->assertIdentical($result[0]['command'], 'settings', t('drupal_add_js() settings are contained first.')); // Verify that the custom setting is contained. - $this->assertEqual($result[1]['settings']['foo'], 42, 'Custom setting is output.'); + $this->assertEqual($result[1]['settings']['foo'], 42, t('Custom setting is output.')); } /** @@ -192,7 +192,7 @@ class AJAXFormValuesTestCase extends AJAXTestCase { */ function testSimpleAJAXFormValue() { // Verify form values of a select element. - foreach (array('red', 'green', 'blue') as $item) { + foreach(array('red', 'green', 'blue') as $item) { $edit = array( 'select' => $item, ); @@ -202,7 +202,7 @@ class AJAXFormValuesTestCase extends AJAXTestCase { } // Verify form values of a checkbox element. - foreach (array(FALSE, TRUE) as $item) { + foreach(array(FALSE, TRUE) as $item) { $edit = array( 'checkbox' => $item, ); @@ -270,8 +270,8 @@ class AJAXMultiFormTestCase extends AJAXTestCase { // each form. $this->drupalGet('form-test/two-instances-of-same-form'); foreach ($field_xpaths as $form_id => $field_xpath) { - $this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == 1, 'Found the correct number of field items on the initial page.'); - $this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, 'Found the "add more" button on the initial page.'); + $this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == 1, t('Found the correct number of field items on the initial page.')); + $this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, t('Found the "add more" button on the initial page.')); } $this->assertNoDuplicateIds(t('Initial page contains unique IDs'), 'Other'); @@ -282,13 +282,13 @@ class AJAXMultiFormTestCase extends AJAXTestCase { preg_match('/jQuery\.extend\(Drupal\.settings, (.*?)\);/', $this->content, $matches); $settings = drupal_json_decode($matches[1]); foreach ($field_xpaths as $form_id => $field_xpath) { - for ($i = 0; $i < 2; $i++) { + for ($i=0; $i<2; $i++) { $button = $this->xpath($field_xpath . $button_xpath_suffix); $button_id = (string) $button[0]['id']; $commands = $this->drupalPostAJAX(NULL, array(), array($button_name => $button_value), 'system/ajax', array(), array(), $form_id, $settings['ajax'][$button_id]); $settings = array_merge_recursive($settings, $commands[0]['settings']); - $this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == $i + 2, 'Found the correct number of field items after an AJAX submission.'); - $this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, 'Found the "add more" button after an AJAX submission.'); + $this->assert(count($this->xpath($field_xpath . $field_items_xpath_suffix)) == $i+2, t('Found the correct number of field items after an AJAX submission.')); + $this->assertFieldByXPath($field_xpath . $button_xpath_suffix, NULL, t('Found the "add more" button after an AJAX submission.')); $this->assertNoDuplicateIds(t('Updated page contains unique IDs'), 'Other'); } } @@ -322,8 +322,8 @@ class AJAXElementValidation extends AJAXTestCase { // Post with 'drivertext' as the triggering element. $post_result = $this->drupalPostAJAX('ajax_validation_test', $edit, 'drivertext'); // Look for a validation failure in the resultant JSON. - $this->assertNoText(t('Error message'), "No error message in resultant JSON"); - $this->assertText('ajax_forms_test_validation_form_callback invoked', 'The correct callback was invoked'); + $this->assertNoText(t('Error message'), t("No error message in resultant JSON")); + $this->assertText('ajax_forms_test_validation_form_callback invoked', t('The correct callback was invoked')); } } diff --git a/modules/simpletest/tests/batch.test b/modules/simpletest/tests/batch.test index f14f56ba9..451575cf2 100644 --- a/modules/simpletest/tests/batch.test +++ b/modules/simpletest/tests/batch.test @@ -28,9 +28,9 @@ class BatchProcessingTestCase extends DrupalWebTestCase { function testBatchNoForm() { // Displaying the page triggers batch 1. $this->drupalGet('batch_test/no_form'); - $this->assertBatchMessages($this->_resultMessages(1), 'Batch for step 2 performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages(1), t('Batch for step 2 performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); } /** @@ -40,36 +40,36 @@ class BatchProcessingTestCase extends DrupalWebTestCase { // Batch 0: no operation. $edit = array('batch' => 'batch_0'); $this->drupalPost('batch_test/simple', $edit, 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_0'), 'Batch with no operation performed successfully.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_0'), t('Batch with no operation performed successfully.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); // Batch 1: several simple operations. $edit = array('batch' => 'batch_1'); $this->drupalPost('batch_test/simple', $edit, 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch with simple operations performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_1'), t('Batch with simple operations performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); // Batch 2: one multistep operation. $edit = array('batch' => 'batch_2'); $this->drupalPost('batch_test/simple', $edit, 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch with multistep operation performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_2'), t('Batch with multistep operation performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); // Batch 3: simple + multistep combined. $edit = array('batch' => 'batch_3'); $this->drupalPost('batch_test/simple', $edit, 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_3'), 'Batch with simple and multistep operations performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_3'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_3'), t('Batch with simple and multistep operations performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_3'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); // Batch 4: nested batch. $edit = array('batch' => 'batch_4'); $this->drupalPost('batch_test/simple', $edit, 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_4'), 'Nested batch performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_4'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_4'), t('Nested batch performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_4'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); } /** @@ -77,19 +77,19 @@ class BatchProcessingTestCase extends DrupalWebTestCase { */ function testBatchFormMultistep() { $this->drupalGet('batch_test/multistep'); - $this->assertText('step 1', 'Form is displayed in step 1.'); + $this->assertText('step 1', t('Form is displayed in step 1.')); // First step triggers batch 1. $this->drupalPost(NULL, array(), 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 1 performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.'); - $this->assertText('step 2', 'Form is displayed in step 2.'); + $this->assertBatchMessages($this->_resultMessages('batch_1'), t('Batch for step 1 performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), t('Execution order was correct.')); + $this->assertText('step 2', t('Form is displayed in step 2.')); // Second step triggers batch 2. $this->drupalPost(NULL, array(), 'Submit'); - $this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch for step 2 performed successfully.'); - $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertBatchMessages($this->_resultMessages('batch_2'), t('Batch for step 2 performed successfully.')); + $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), t('Execution order was correct.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); } /** @@ -102,11 +102,11 @@ class BatchProcessingTestCase extends DrupalWebTestCase { $edit = array('value' => $value); $this->drupalPost('batch_test/chained', $edit, 'Submit'); // Check that result messages are present and in the correct order. - $this->assertBatchMessages($this->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.'); + $this->assertBatchMessages($this->_resultMessages('chained'), t('Batches defined in separate submit handlers performed successfully.')); // The stack contains execution order of batch callbacks and submit // hanlders and logging of corresponding $form_state[{values']. - $this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), 'Execution order was correct, and $form_state is correctly persisted.'); - $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.'); + $this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), t('Execution order was correct, and $form_state is correctly persisted.')); + $this->assertText('Redirection successful.', t('Redirection after batch execution is correct.')); } /** @@ -120,11 +120,11 @@ class BatchProcessingTestCase extends DrupalWebTestCase { $value = rand(0, 255); $this->drupalGet('batch_test/programmatic/' . $value); // Check that result messages are present and in the correct order. - $this->assertBatchMessages($this->_resultMessages('chained'), 'Batches defined in separate submit handlers performed successfully.'); + $this->assertBatchMessages($this->_resultMessages('chained'), t('Batches defined in separate submit handlers performed successfully.')); // The stack contains execution order of batch callbacks and submit // hanlders and logging of corresponding $form_state[{values']. - $this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), 'Execution order was correct, and $form_state is correctly persisted.'); - $this->assertText('Got out of a programmatic batched form.', 'Page execution continues normally.'); + $this->assertEqual(batch_test_stack(), $this->_resultStack('chained', $value), t('Execution order was correct, and $form_state is correctly persisted.')); + $this->assertText('Got out of a programmatic batched form.', t('Page execution continues normally.')); } /** @@ -135,7 +135,7 @@ class BatchProcessingTestCase extends DrupalWebTestCase { // form. $value = rand(0, 255); $this->drupalGet('batch_test/nested_programmatic/' . $value); - $this->assertEqual(batch_test_stack(), array('mock form submitted with value = ' . $value), 'drupal_form_submit() ran successfully within a batch operation.'); + $this->assertEqual(batch_test_stack(), array('mock form submitted with value = ' . $value), t('drupal_form_submit() ran successfully within a batch operation.')); } /** @@ -149,7 +149,7 @@ class BatchProcessingTestCase extends DrupalWebTestCase { * TRUE on pass, FALSE on fail. */ function assertBatchMessages($texts, $message) { - $pattern = '|' . implode('.*', $texts) . '|s'; + $pattern = '|' . implode('.*', $texts) .'|s'; return $this->assertPattern($pattern, $message); } @@ -282,7 +282,7 @@ class BatchPageTestCase extends DrupalWebTestCase { // administrative page. $this->drupalGet('admin/batch_test/test_theme'); // The stack should contain the name of the the used on the progress page. - $this->assertEqual(batch_test_stack(), array('seven'), 'A progressive batch correctly uses the theme of the page that started the batch.'); + $this->assertEqual(batch_test_stack(), array('seven'), t('A progressive batch correctly uses the theme of the page that started the batch.')); } } @@ -357,10 +357,10 @@ class BatchPercentagesUnitTestCase extends DrupalUnitTestCase { $current = $arguments['current']; $actual_result = _batch_api_percentage($total, $current); if ($actual_result === $expected_result) { - $this->pass('Expected the batch api percentage at the state ' . $current . '/' . $total . ' to be ' . $expected_result . '%, and got ' . $actual_result . '%.'); + $this->pass(t('Expected the batch api percentage at the state @numerator/@denominator to be @expected%, and got @actual%.', array('@numerator' => $current, '@denominator' => $total, '@expected' => $expected_result, '@actual' => $actual_result))); } else { - $this->fail('Expected the batch api percentage at the state ' . $current . '/' . $total . ' to be ' . $expected_result . '%, but got ' . $actual_result . '%.'); + $this->fail(t('Expected the batch api percentage at the state @numerator/@denominator to be @expected%, but got @actual%.', array('@numerator' => $current, '@denominator' => $total, '@expected' => $expected_result, '@actual' => $actual_result))); } } } diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index d41ecf333..d8a9d8c1b 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -42,48 +42,60 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase { function testIPAddressHost() { // Test the normal IP address. $this->assertTrue( - ip_address() == $this->remote_ip, 'Got remote IP address.'); + ip_address() == $this->remote_ip, + t('Got remote IP address.') + ); // Proxy forwarding on but no proxy addresses defined. variable_set('reverse_proxy', 1); $this->assertTrue( - ip_address() == $this->remote_ip, 'Proxy forwarding without trusted proxies got remote IP address.'); + ip_address() == $this->remote_ip, + t('Proxy forwarding without trusted proxies got remote IP address.') + ); // Proxy forwarding on and proxy address not trusted. variable_set('reverse_proxy_addresses', array($this->proxy_ip, $this->proxy2_ip)); drupal_static_reset('ip_address'); $_SERVER['REMOTE_ADDR'] = $this->untrusted_ip; $this->assertTrue( - ip_address() == $this->untrusted_ip, 'Proxy forwarding with untrusted proxy got remote IP address.'); + ip_address() == $this->untrusted_ip, + t('Proxy forwarding with untrusted proxy got remote IP address.') + ); // Proxy forwarding on and proxy address trusted. $_SERVER['REMOTE_ADDR'] = $this->proxy_ip; $_SERVER['HTTP_X_FORWARDED_FOR'] = $this->forwarded_ip; drupal_static_reset('ip_address'); $this->assertTrue( - ip_address() == $this->forwarded_ip, 'Proxy forwarding with trusted proxy got forwarded IP address.'); + ip_address() == $this->forwarded_ip, + t('Proxy forwarding with trusted proxy got forwarded IP address.') + ); // Multi-tier architecture with comma separated values in header. $_SERVER['REMOTE_ADDR'] = $this->proxy_ip; $_SERVER['HTTP_X_FORWARDED_FOR'] = implode(', ', array($this->untrusted_ip, $this->forwarded_ip, $this->proxy2_ip)); drupal_static_reset('ip_address'); $this->assertTrue( - ip_address() == $this->forwarded_ip, 'Proxy forwarding with trusted 2-tier proxy got forwarded IP address.'); + ip_address() == $this->forwarded_ip, + t('Proxy forwarding with trusted 2-tier proxy got forwarded IP address.') + ); // Custom client-IP header. variable_set('reverse_proxy_header', 'HTTP_X_CLUSTER_CLIENT_IP'); $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip; drupal_static_reset('ip_address'); $this->assertTrue( - ip_address() == $this->cluster_ip, 'Cluster environment got cluster client IP.'); + ip_address() == $this->cluster_ip, + t('Cluster environment got cluster client IP.') + ); // Verifies that drupal_valid_http_host() prevents invalid characters. - $this->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), 'HTTP_HOST with / is invalid'); - $this->assertFalse(drupal_valid_http_host('security\\.drupal.org:80'), 'HTTP_HOST with \\ is invalid'); - $this->assertFalse(drupal_valid_http_host('security<.drupal.org:80'), 'HTTP_HOST with < is invalid'); - $this->assertFalse(drupal_valid_http_host('security..drupal.org:80'), 'HTTP_HOST with .. is invalid'); + $this->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), t('HTTP_HOST with / is invalid')); + $this->assertFalse(drupal_valid_http_host('security\\.drupal.org:80'), t('HTTP_HOST with \\ is invalid')); + $this->assertFalse(drupal_valid_http_host('security<.drupal.org:80'), t('HTTP_HOST with < is invalid')); + $this->assertFalse(drupal_valid_http_host('security..drupal.org:80'), t('HTTP_HOST with .. is invalid')); // IPv6 loopback address - $this->assertTrue(drupal_valid_http_host('[::1]:80'), 'HTTP_HOST containing IPv6 loopback is valid'); + $this->assertTrue(drupal_valid_http_host('[::1]:80'), t('HTTP_HOST containing IPv6 loopback is valid')); } } @@ -111,32 +123,32 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { $this->drupalGet(''); $this->drupalHead(''); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $etag = $this->drupalGetHeader('ETag'); $last_modified = $this->drupalGetHeader('Last-Modified'); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag)); - $this->assertResponse(304, 'Conditional request returned 304 Not Modified.'); + $this->assertResponse(304, t('Conditional request returned 304 Not Modified.')); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC822, strtotime($last_modified)), 'If-None-Match: ' . $etag)); - $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); + $this->assertResponse(304, t('Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.')); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC850, strtotime($last_modified)), 'If-None-Match: ' . $etag)); - $this->assertResponse(304, 'Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.'); + $this->assertResponse(304, t('Conditional request with obsolete If-Modified-Since date returned 304 Not Modified.')); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified)); - $this->assertResponse(200, 'Conditional request without If-None-Match returned 200 OK.'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); + $this->assertResponse(200, t('Conditional request without If-None-Match returned 200 OK.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DATE_RFC1123, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag)); - $this->assertResponse(200, 'Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.'); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); + $this->assertResponse(200, t('Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.')); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); $user = $this->drupalCreateUser(); $this->drupalLogin($user); $this->drupalGet('', array(), array('If-Modified-Since: ' . $last_modified, 'If-None-Match: ' . $etag)); - $this->assertResponse(200, 'Conditional request returned 200 OK for authenticated user.'); - $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Absense of Page was not cached.'); + $this->assertResponse(200, t('Conditional request returned 200 OK for authenticated user.')); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Absense of Page was not cached.')); } /** @@ -147,35 +159,35 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { // Fill the cache. $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); - $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary header was sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.'); - $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); - $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.')); + $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary header was sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); // Check cache. $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary: Cookie header was sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.'); - $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); - $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); + $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', t('Vary: Cookie header was sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); // Check replacing default headers. $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Expires', 'value' => 'Fri, 19 Nov 2008 05:00:00 GMT'))); - $this->assertEqual($this->drupalGetHeader('Expires'), 'Fri, 19 Nov 2008 05:00:00 GMT', 'Default header was replaced.'); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Fri, 19 Nov 2008 05:00:00 GMT', t('Default header was replaced.')); $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Vary', 'value' => 'User-Agent'))); - $this->assertEqual($this->drupalGetHeader('Vary'), 'User-Agent,Accept-Encoding', 'Default header was replaced.'); + $this->assertEqual($this->drupalGetHeader('Vary'), 'User-Agent,Accept-Encoding', t('Default header was replaced.')); // Check that authenticated users bypass the cache. $user = $this->drupalCreateUser(); $this->drupalLogin($user); $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); - $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.'); - $this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, 'Vary: Cookie header was not sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Cache-Control header was sent.'); - $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); - $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); + $this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), t('Caching was bypassed.')); + $this->assertTrue(strpos($this->drupalGetHeader('Vary'), 'Cookie') === FALSE, t('Vary: Cookie header was not sent.')); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', t('Cache-Control header was sent.')); + $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.')); + $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', t('Custom header was sent.')); } @@ -191,23 +203,23 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { // Fill the cache and verify that output is compressed. $this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate')); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Page was not cached.')); $this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8))); - $this->assertRaw('', 'Page was gzip compressed.'); + $this->assertRaw('', t('Page was gzip compressed.')); // Verify that cached output is compressed. $this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate')); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->assertEqual($this->drupalGetHeader('Content-Encoding'), 'gzip', 'A Content-Encoding header was sent.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); + $this->assertEqual($this->drupalGetHeader('Content-Encoding'), 'gzip', t('A Content-Encoding header was sent.')); $this->drupalSetContent(gzinflate(substr($this->drupalGetContent(), 10, -8))); - $this->assertRaw('', 'Page was gzip compressed.'); + $this->assertRaw('', t('Page was gzip compressed.')); // Verify that a client without compression support gets an uncompressed page. $this->drupalGet(''); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.'); - $this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), 'Site title matches.'); - $this->assertRaw('', 'Page was not compressed.'); + $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Page was cached.')); + $this->assertFalse($this->drupalGetHeader('Content-Encoding'), t('A Content-Encoding header was not sent.')); + $this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => variable_get('site_name', 'Drupal'))), t('Site title matches.')); + $this->assertRaw('', t('Page was not compressed.')); } } @@ -232,17 +244,17 @@ class BootstrapVariableTestCase extends DrupalWebTestCase { // Setting and retrieving values. $variable = $this->randomName(); variable_set('simpletest_bootstrap_variable_test', $variable); - $this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), 'Setting and retrieving values'); + $this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), t('Setting and retrieving values')); // Make sure the variable persists across multiple requests. $this->drupalGet('system-test/variable-get'); - $this->assertText($variable, 'Variable persists across multiple requests'); + $this->assertText($variable, t('Variable persists across multiple requests')); // Deleting variables. $default_value = $this->randomName(); variable_del('simpletest_bootstrap_variable_test'); $variable = variable_get('simpletest_bootstrap_variable_test', $default_value); - $this->assertIdentical($variable, $default_value, 'Deleting variables'); + $this->assertIdentical($variable, $default_value, t('Deleting variables')); } /** @@ -250,10 +262,10 @@ class BootstrapVariableTestCase extends DrupalWebTestCase { */ function testVariableDefaults() { // Tests passing nothing through to the default. - $this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), 'Variables are correctly defaulting to NULL.'); + $this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), t('Variables are correctly defaulting to NULL.')); // Tests passing 5 to the default parameter. - $this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), 'The default variable parameter is passed through correctly.'); + $this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), t('The default variable parameter is passed through correctly.')); } } @@ -283,29 +295,29 @@ class HookBootExitTestCase extends DrupalWebTestCase { variable_set('cache', 0); $this->drupalGet(''); $calls = 1; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with disabled cache.'); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with disabled cache.'); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with disabled cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with disabled cache.')); // Test with normal cache. Boot and exit should be called. variable_set('cache', 1); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with normal cache.'); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with normal cache.'); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with normal cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with normal cache.')); // Boot and exit should not fire since the page is cached. variable_set('page_cache_invoke_hooks', FALSE); - $this->assertTrue(cache_get(url('', array('absolute' => TRUE)), 'cache_page'), 'Page has been cached.'); + $this->assertTrue(cache_get(url('', array('absolute' => TRUE)), 'cache_page'), t('Page has been cached.')); $this->drupalGet(''); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot not called with agressive cache and a cached page.'); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit not called with agressive cache and a cached page.'); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot not called with agressive cache and a cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit not called with agressive cache and a cached page.')); // Test with page cache cleared, boot and exit should be called. - $this->assertTrue(db_delete('cache_page')->execute(), 'Page cache cleared.'); + $this->assertTrue(db_delete('cache_page')->execute(), t('Page cache cleared.')); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with agressive cache and no cached page.'); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with agressive cache and no cached page.'); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with agressive cache and no cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with agressive cache and no cached page.')); } } @@ -331,16 +343,16 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase { drupal_static_reset('drupal_get_filename'); // Retrieving the location of a module. - $this->assertIdentical(drupal_get_filename('module', 'php'), 'modules/php/php.module', 'Retrieve module location.'); + $this->assertIdentical(drupal_get_filename('module', 'php'), 'modules/php/php.module', t('Retrieve module location.')); // Retrieving the location of a theme. - $this->assertIdentical(drupal_get_filename('theme', 'stark'), 'themes/stark/stark.info', 'Retrieve theme location.'); + $this->assertIdentical(drupal_get_filename('theme', 'stark'), 'themes/stark/stark.info', t('Retrieve theme location.')); // Retrieving the location of a theme engine. - $this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'themes/engines/phptemplate/phptemplate.engine', 'Retrieve theme engine location.'); + $this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'themes/engines/phptemplate/phptemplate.engine', t('Retrieve theme engine location.')); // Retrieving a file that is definitely not stored in the database. - $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', 'Retrieve install profile location.'); + $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', t('Retrieve install profile location.')); } } @@ -362,17 +374,17 @@ class BootstrapTimerTestCase extends DrupalUnitTestCase { function testTimer() { timer_start('test'); sleep(1); - $this->assertTrue(timer_read('test') >= 1000, 'Timer measured 1 second of sleeping while running.'); + $this->assertTrue(timer_read('test') >= 1000, t('Timer measured 1 second of sleeping while running.')); sleep(1); timer_stop('test'); - $this->assertTrue(timer_read('test') >= 2000, 'Timer measured 2 seconds of sleeping after being stopped.'); + $this->assertTrue(timer_read('test') >= 2000, t('Timer measured 2 seconds of sleeping after being stopped.')); timer_start('test'); sleep(1); - $this->assertTrue(timer_read('test') >= 3000, 'Timer measured 3 seconds of sleeping after being restarted.'); + $this->assertTrue(timer_read('test') >= 3000, t('Timer measured 3 seconds of sleeping after being restarted.')); sleep(1); $timer = timer_stop('test'); - $this->assertTrue(timer_read('test') >= 4000, 'Timer measured 4 seconds of sleeping after being stopped for a second time.'); - $this->assertEqual($timer['count'], 2, 'Timer counted 2 instances of being started.'); + $this->assertTrue(timer_read('test') >= 4000, t('Timer measured 4 seconds of sleeping after being stopped for a second time.')); + $this->assertEqual($timer['count'], 2, t('Timer counted 2 instances of being started.')); } } @@ -396,21 +408,21 @@ class BootstrapResettableStaticTestCase extends DrupalUnitTestCase { function testDrupalStatic() { $name = __CLASS__ . '_' . __METHOD__; $var = &drupal_static($name, 'foo'); - $this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.'); + $this->assertEqual($var, 'foo', t('Variable returned by drupal_static() was set to its default.')); // Call the specific reset and the global reset each twice to ensure that // multiple resets can be issued without odd side effects. $var = 'bar'; drupal_static_reset($name); - $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.'); + $this->assertEqual($var, 'foo', t('Variable was reset after first invocation of name-specific reset.')); $var = 'bar'; drupal_static_reset($name); - $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.'); + $this->assertEqual($var, 'foo', t('Variable was reset after second invocation of name-specific reset.')); $var = 'bar'; drupal_static_reset(); - $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.'); + $this->assertEqual($var, 'foo', t('Variable was reset after first invocation of global reset.')); $var = 'bar'; drupal_static_reset(); - $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.'); + $this->assertEqual($var, 'foo', t('Variable was reset after second invocation of global reset.')); } } diff --git a/modules/simpletest/tests/cache.test b/modules/simpletest/tests/cache.test index b45dd85ec..0fc9fe298 100644 --- a/modules/simpletest/tests/cache.test +++ b/modules/simpletest/tests/cache.test @@ -135,7 +135,7 @@ class CacheSavingCase extends CacheTestCase { * Test the saving and restoring of an array. */ function testArray() { - $this->checkVariable(array('drupal1','drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6'))); + $this->checkVariable(array('drupal1', 'drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6'))); } /** @@ -145,11 +145,11 @@ class CacheSavingCase extends CacheTestCase { $test_object = new stdClass(); $test_object->test1 = $this->randomName(100); $test_object->test2 = 100; - $test_object->test3 = array('drupal1','drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6')); + $test_object->test3 = array('drupal1', 'drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6')); cache_set('test_object', $test_object, 'cache'); $cache = cache_get('test_object', 'cache'); - $this->assertTrue(isset($cache->data) && $cache->data == $test_object, 'Object is saved and restored properly.'); + $this->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.')); } /* @@ -158,7 +158,7 @@ class CacheSavingCase extends CacheTestCase { function checkVariable($var) { cache_set('test_var', $var, 'cache'); $cache = cache_get('test_var', 'cache'); - $this->assertTrue(isset($cache->data) && $cache->data === $var, ucfirst(gettype($var)) . ' is saved and restored properly.'); + $this->assertTrue(isset($cache->data) && $cache->data === $var, t('@type is saved and restored properly.', array('@type' => ucfirst(gettype($var))))); } } @@ -188,14 +188,14 @@ class CacheGetMultipleUnitTest extends CacheTestCase { $item2 = $this->randomName(10); cache_set('item1', $item1, $this->default_bin); cache_set('item2', $item2, $this->default_bin); - $this->assertTrue($this->checkCacheExists('item1', $item1), 'Item 1 is cached.'); - $this->assertTrue($this->checkCacheExists('item2', $item2), 'Item 2 is cached.'); + $this->assertTrue($this->checkCacheExists('item1', $item1), t('Item 1 is cached.')); + $this->assertTrue($this->checkCacheExists('item2', $item2), t('Item 2 is cached.')); // Fetch both records from the database with cache_get_multiple(). $item_ids = array('item1', 'item2'); $items = cache_get_multiple($item_ids, $this->default_bin); - $this->assertEqual($items['item1']->data, $item1, 'Item was returned from cache successfully.'); - $this->assertEqual($items['item2']->data, $item2, 'Item was returned from cache successfully.'); + $this->assertEqual($items['item1']->data, $item1, t('Item was returned from cache successfully.')); + $this->assertEqual($items['item2']->data, $item2, t('Item was returned from cache successfully.')); // Remove one item from the cache. cache_clear_all('item2', $this->default_bin); @@ -203,9 +203,9 @@ class CacheGetMultipleUnitTest extends CacheTestCase { // Confirm that only one item is returned by cache_get_multiple(). $item_ids = array('item1', 'item2'); $items = cache_get_multiple($item_ids, $this->default_bin); - $this->assertEqual($items['item1']->data, $item1, 'Item was returned from cache successfully.'); - $this->assertFalse(isset($items['item2']), 'Item was not returned from the cache.'); - $this->assertTrue(count($items) == 1, 'Only valid cache entries returned.'); + $this->assertEqual($items['item1']->data, $item1, t('Item was returned from cache successfully.')); + $this->assertFalse(isset($items['item2']), t('Item was not returned from the cache.')); + $this->assertTrue(count($items) == 1, t('Only valid cache entries returned.')); } } @@ -237,15 +237,17 @@ class CacheClearCase extends CacheTestCase { $this->assertCacheExists(t('Cache was set for clearing cid.'), $this->default_value, 'test_cid_clear'); cache_clear_all('test_cid_clear', $this->default_bin); - $this->assertCacheRemoved('Cache was removed after clearing cid.', 'test_cid_clear'); + $this->assertCacheRemoved(t('Cache was removed after clearing cid.'), 'test_cid_clear'); cache_set('test_cid_clear1', $this->default_value, $this->default_bin); cache_set('test_cid_clear2', $this->default_value, $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches were created for checking cid "*" with wildcard false.'); + && $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches were created for checking cid "*" with wildcard false.')); cache_clear_all('*', $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches still exists after clearing cid "*" with wildcard false.'); + && $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches still exists after clearing cid "*" with wildcard false.')); } /** @@ -255,18 +257,22 @@ class CacheClearCase extends CacheTestCase { cache_set('test_cid_clear1', $this->default_value, $this->default_bin); cache_set('test_cid_clear2', $this->default_value, $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches were created for checking cid "*" with wildcard true.'); + && $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches were created for checking cid "*" with wildcard true.')); cache_clear_all('*', $this->default_bin, TRUE); $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) - || $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches removed after clearing cid "*" with wildcard true.'); + || $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches removed after clearing cid "*" with wildcard true.')); cache_set('test_cid_clear1', $this->default_value, $this->default_bin); cache_set('test_cid_clear2', $this->default_value, $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches were created for checking cid substring with wildcard true.'); + && $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches were created for checking cid substring with wildcard true.')); cache_clear_all('test_', $this->default_bin, TRUE); $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) - || $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two caches removed after clearing cid substring with wildcard true.'); + || $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two caches removed after clearing cid substring with wildcard true.')); } /** @@ -279,14 +285,17 @@ class CacheClearCase extends CacheTestCase { cache_set('test_cid_clear3', $this->default_value, $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) && $this->checkCacheExists('test_cid_clear2', $this->default_value) - && $this->checkCacheExists('test_cid_clear3', $this->default_value), 'Three cache entries were created.'); + && $this->checkCacheExists('test_cid_clear3', $this->default_value), + t('Three cache entries were created.')); // Clear two entries using an array. cache_clear_all(array('test_cid_clear1', 'test_cid_clear2'), $this->default_bin); $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) - || $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two cache entries removed after clearing with an array.'); + || $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two cache entries removed after clearing with an array.')); - $this->assertTrue($this->checkCacheExists('test_cid_clear3', $this->default_value), 'Entry was not cleared from the cache'); + $this->assertTrue($this->checkCacheExists('test_cid_clear3', $this->default_value), + t('Entry was not cleared from the cache')); // Set the cache clear threshold to 2 to confirm that the full bin is cleared // when the threshold is exceeded. @@ -294,11 +303,13 @@ class CacheClearCase extends CacheTestCase { cache_set('test_cid_clear1', $this->default_value, $this->default_bin); cache_set('test_cid_clear2', $this->default_value, $this->default_bin); $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), 'Two cache entries were created.'); + && $this->checkCacheExists('test_cid_clear2', $this->default_value), + t('Two cache entries were created.')); cache_clear_all(array('test_cid_clear1', 'test_cid_clear2', 'test_cid_clear3'), $this->default_bin); $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) || $this->checkCacheExists('test_cid_clear2', $this->default_value) - || $this->checkCacheExists('test_cid_clear3', $this->default_value), 'All cache entries removed when the array exceeded the cache clear threshold.'); + || $this->checkCacheExists('test_cid_clear3', $this->default_value), + t('All cache entries removed when the array exceeded the cache clear threshold.')); } } @@ -327,14 +338,14 @@ class CacheIsEmptyCase extends CacheTestCase { function testIsEmpty() { // Clear the cache bin. cache_clear_all('*', $this->default_bin); - $this->assertTrue(cache_is_empty($this->default_bin), 'The cache bin is empty'); + $this->assertTrue(cache_is_empty($this->default_bin), t('The cache bin is empty')); // Add some data to the cache bin. cache_set($this->default_cid, $this->default_value, $this->default_bin); $this->assertCacheExists(t('Cache was set.'), $this->default_value, $this->default_cid); - $this->assertFalse(cache_is_empty($this->default_bin), 'The cache bin is not empty'); + $this->assertFalse(cache_is_empty($this->default_bin), t('The cache bin is not empty')); // Remove the cached data. cache_clear_all($this->default_cid, $this->default_bin); - $this->assertCacheRemoved('Cache was removed.', $this->default_cid); - $this->assertTrue(cache_is_empty($this->default_bin), 'The cache bin is empty'); + $this->assertCacheRemoved(t('Cache was removed.'), $this->default_cid); + $this->assertTrue(cache_is_empty($this->default_bin), t('The cache bin is empty')); } } diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 24a681924..35c5bbc3b 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -37,13 +37,13 @@ class DrupalAlterTestCase extends DrupalWebTestCase { $array_copy = $array; $array_expected = array('foo' => 'Drupal theme'); drupal_alter('drupal_alter', $array_copy); - $this->assertEqual($array_copy, $array_expected, 'Single array was altered.'); + $this->assertEqual($array_copy, $array_expected, t('Single array was altered.')); $entity_copy = clone $entity; $entity_expected = clone $entity; $entity_expected->foo = 'Drupal theme'; drupal_alter('drupal_alter', $entity_copy); - $this->assertEqual($entity_copy, $entity_expected, 'Single object was altered.'); + $this->assertEqual($entity_copy, $entity_expected, t('Single object was altered.')); // Verify alteration of multiple arguments. $array_copy = $array; @@ -54,9 +54,9 @@ class DrupalAlterTestCase extends DrupalWebTestCase { $array2_copy = $array; $array2_expected = array('foo' => 'Drupal theme'); drupal_alter('drupal_alter', $array_copy, $entity_copy, $array2_copy); - $this->assertEqual($array_copy, $array_expected, 'First argument to drupal_alter() was altered.'); - $this->assertEqual($entity_copy, $entity_expected, 'Second argument to drupal_alter() was altered.'); - $this->assertEqual($array2_copy, $array2_expected, 'Third argument to drupal_alter() was altered.'); + $this->assertEqual($array_copy, $array_expected, t('First argument to drupal_alter() was altered.')); + $this->assertEqual($entity_copy, $entity_expected, t('Second argument to drupal_alter() was altered.')); + $this->assertEqual($array2_copy, $array2_expected, t('Third argument to drupal_alter() was altered.')); } } @@ -83,7 +83,7 @@ class CommonURLUnitTest extends DrupalWebTestCase { $path = ""; $link = l($text, $path); $sanitized_path = check_url(url($path)); - $this->assertTrue(strpos($link, $sanitized_path) !== FALSE, 'XSS attack ' . $path . ' was filtered'); + $this->assertTrue(strpos($link, $sanitized_path) !== FALSE, t('XSS attack @path was filtered', array('@path' => $path))); } /* @@ -91,7 +91,7 @@ class CommonURLUnitTest extends DrupalWebTestCase { */ function testLActiveClass() { $link = l($this->randomName(), $_GET['q']); - $this->assertTrue($this->hasClass($link, 'active'), 'Class ' . 'active' . ' is present on link to the current page'); + $this->assertTrue($this->hasClass($link, 'active'), t('Class @class is present on link to the current page', array('@class' => 'active'))); } /** @@ -100,8 +100,8 @@ class CommonURLUnitTest extends DrupalWebTestCase { function testLCustomClass() { $class = $this->randomName(); $link = l($this->randomName(), $_GET['q'], array('attributes' => array('class' => array($class)))); - $this->assertTrue($this->hasClass($link, $class), 'Custom class ' . $class . ' is present on link when requested'); - $this->assertTrue($this->hasClass($link, 'active'), 'Class ' . 'active' . ' is present on link to the current page'); + $this->assertTrue($this->hasClass($link, $class), t('Custom class @class is present on link when requested', array('@class' => $class))); + $this->assertTrue($this->hasClass($link, 'active'), t('Class @class is present on link to the current page', array('@class' => 'active'))); } private function hasClass($link, $class) { @@ -127,42 +127,42 @@ class CommonURLUnitTest extends DrupalWebTestCase { // Default arguments. $result = $_GET; unset($result['q']); - $this->assertEqual(drupal_get_query_parameters(), $result, "\$_GET['q'] was removed."); + $this->assertEqual(drupal_get_query_parameters(), $result, t("\$_GET['q'] was removed.")); // Default exclusion. $result = $original; unset($result['q']); - $this->assertEqual(drupal_get_query_parameters($original), $result, "'q' was removed."); + $this->assertEqual(drupal_get_query_parameters($original), $result, t("'q' was removed.")); // First-level exclusion. $result = $original; unset($result['b']); - $this->assertEqual(drupal_get_query_parameters($original, array('b')), $result, "'b' was removed."); + $this->assertEqual(drupal_get_query_parameters($original, array('b')), $result, t("'b' was removed.")); // Second-level exclusion. $result = $original; unset($result['b']['d']); - $this->assertEqual(drupal_get_query_parameters($original, array('b[d]')), $result, "'b[d]' was removed."); + $this->assertEqual(drupal_get_query_parameters($original, array('b[d]')), $result, t("'b[d]' was removed.")); // Third-level exclusion. $result = $original; unset($result['b']['e']['f']); - $this->assertEqual(drupal_get_query_parameters($original, array('b[e][f]')), $result, "'b[e][f]' was removed."); + $this->assertEqual(drupal_get_query_parameters($original, array('b[e][f]')), $result, t("'b[e][f]' was removed.")); // Multiple exclusions. $result = $original; unset($result['a'], $result['b']['e'], $result['c']); - $this->assertEqual(drupal_get_query_parameters($original, array('a', 'b[e]', 'c')), $result, "'a', 'b[e]', 'c' were removed."); + $this->assertEqual(drupal_get_query_parameters($original, array('a', 'b[e]', 'c')), $result, t("'a', 'b[e]', 'c' were removed.")); } /** * Test drupal_http_build_query(). */ function testDrupalHttpBuildQuery() { - $this->assertEqual(drupal_http_build_query(array('a' => ' &#//+%20@۞')), 'a=%20%26%23//%2B%2520%40%DB%9E', 'Value was properly encoded.'); - $this->assertEqual(drupal_http_build_query(array(' &#//+%20@۞' => 'a')), '%20%26%23%2F%2F%2B%2520%40%DB%9E=a', 'Key was properly encoded.'); - $this->assertEqual(drupal_http_build_query(array('a' => '1', 'b' => '2', 'c' => '3')), 'a=1&b=2&c=3', 'Multiple values were properly concatenated.'); - $this->assertEqual(drupal_http_build_query(array('a' => array('b' => '2', 'c' => '3'), 'd' => 'foo')), 'a[b]=2&a[c]=3&d=foo', 'Nested array was properly encoded.'); + $this->assertEqual(drupal_http_build_query(array('a' => ' &#//+%20@۞')), 'a=%20%26%23//%2B%2520%40%DB%9E', t('Value was properly encoded.')); + $this->assertEqual(drupal_http_build_query(array(' &#//+%20@۞' => 'a')), '%20%26%23%2F%2F%2B%2520%40%DB%9E=a', t('Key was properly encoded.')); + $this->assertEqual(drupal_http_build_query(array('a' => '1', 'b' => '2', 'c' => '3')), 'a=1&b=2&c=3', t('Multiple values were properly concatenated.')); + $this->assertEqual(drupal_http_build_query(array('a' => array('b' => '2', 'c' => '3'), 'd' => 'foo')), 'a[b]=2&a[c]=3&d=foo', t('Nested array was properly encoded.')); } /** @@ -176,7 +176,7 @@ class CommonURLUnitTest extends DrupalWebTestCase { 'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''), 'fragment' => 'foo', ); - $this->assertEqual(drupal_parse_url($url), $result, 'Relative URL parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL parsed correctly.')); // Relative URL that is known to confuse parse_url(). $url = 'foo/bar:1'; @@ -185,7 +185,7 @@ class CommonURLUnitTest extends DrupalWebTestCase { 'query' => array(), 'fragment' => '', ); - $this->assertEqual(drupal_parse_url($url), $result, 'Relative URL parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL parsed correctly.')); // Absolute URL. $url = '/foo/bar?foo=bar&bar=baz&baz#foo'; @@ -194,13 +194,13 @@ class CommonURLUnitTest extends DrupalWebTestCase { 'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''), 'fragment' => 'foo', ); - $this->assertEqual(drupal_parse_url($url), $result, 'Absolute URL parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Absolute URL parsed correctly.')); // External URL testing. $url = 'http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo'; // Test that drupal can recognize an absolute URL. Used to prevent attack vectors. - $this->assertTrue(url_is_external($url), 'Correctly identified an external URL.'); + $this->assertTrue(url_is_external($url), t('Correctly identified an external URL.')); // Test the parsing of absolute URLs. $result = array( @@ -208,7 +208,7 @@ class CommonURLUnitTest extends DrupalWebTestCase { 'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''), 'fragment' => 'foo', ); - $this->assertEqual(drupal_parse_url($url), $result, 'External URL parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('External URL parsed correctly.')); // Verify proper parsing of URLs when clean URLs are disabled. $result = array( @@ -218,19 +218,19 @@ class CommonURLUnitTest extends DrupalWebTestCase { ); // Non-clean URLs #1: Absolute URL generated by url(). $url = $GLOBALS['base_url'] . '/?q=foo/bar&bar=baz#foo'; - $this->assertEqual(drupal_parse_url($url), $result, 'Absolute URL with clean URLs disabled parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Absolute URL with clean URLs disabled parsed correctly.')); // Non-clean URLs #2: Relative URL generated by url(). $url = '?q=foo/bar&bar=baz#foo'; - $this->assertEqual(drupal_parse_url($url), $result, 'Relative URL with clean URLs disabled parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL with clean URLs disabled parsed correctly.')); // Non-clean URLs #3: URL generated by url() on non-Apache webserver. $url = 'index.php?q=foo/bar&bar=baz#foo'; - $this->assertEqual(drupal_parse_url($url), $result, 'Relative URL on non-Apache webserver with clean URLs disabled parsed correctly.'); + $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL on non-Apache webserver with clean URLs disabled parsed correctly.')); // Test that drupal_parse_url() does not allow spoofing a URL to force a malicious redirect. $parts = drupal_parse_url('forged:http://cwe.mitre.org/data/definitions/601.html'); - $this->assertFalse(valid_url($parts['path'], TRUE), 'drupal_parse_url() correctly parsed a forged URL.'); + $this->assertFalse(valid_url($parts['path'], TRUE), t('drupal_parse_url() correctly parsed a forged URL.')); } /** @@ -310,30 +310,30 @@ class CommonURLUnitTest extends DrupalWebTestCase { // Verify external URL can contain a fragment. $url = $test_url . '#drupal'; $result = url($url); - $this->assertEqual($url, $result, 'External URL with fragment works without a fragment in $options.'); + $this->assertEqual($url, $result, t('External URL with fragment works without a fragment in $options.')); // Verify fragment can be overidden in an external URL. $url = $test_url . '#drupal'; $fragment = $this->randomName(10); $result = url($url, array('fragment' => $fragment)); - $this->assertEqual($test_url . '#' . $fragment, $result, 'External URL fragment is overidden with a custom fragment in $options.'); + $this->assertEqual($test_url . '#' . $fragment, $result, t('External URL fragment is overidden with a custom fragment in $options.')); // Verify external URL can contain a query string. $url = $test_url . '?drupal=awesome'; $result = url($url); - $this->assertEqual($url, $result, 'External URL with query string works without a query string in $options.'); + $this->assertEqual($url, $result, t('External URL with query string works without a query string in $options.')); // Verify external URL can be extended with a query string. $url = $test_url; $query = array($this->randomName(5) => $this->randomName(5)); $result = url($url, array('query' => $query)); - $this->assertEqual($url . '?' . http_build_query($query, '', '&'), $result, 'External URL can be extended with a query string in $options.'); + $this->assertEqual($url . '?' . http_build_query($query, '', '&'), $result, t('External URL can be extended with a query string in $options.')); // Verify query string can be extended in an external URL. $url = $test_url . '?drupal=awesome'; $query = array($this->randomName(5) => $this->randomName(5)); $result = url($url, array('query' => $query)); - $this->assertEqual($url . '&' . http_build_query($query, '', '&'), $result, 'External URL query string can be extended with a custom query string in $options.'); + $this->assertEqual($url . '&' . http_build_query($query, '', '&'), $result, t('External URL query string can be extended with a custom query string in $options.')); } } @@ -354,23 +354,23 @@ class CommonXssUnitTest extends DrupalUnitTestCase { * Check that invalid multi-byte sequences are rejected. */ function testInvalidMultiByte() { - // Ignore PHP 5.3+ invalid multibyte sequence warning. - $text = @check_plain("Foo\xC0barbaz"); - $this->assertEqual($text, '', 'check_plain() rejects invalid sequence "Foo\xC0barbaz"'); - $text = check_plain("Fooÿñ"); - $this->assertEqual($text, "Fooÿñ", 'check_plain() accepts valid sequence "Fooÿñ"'); - $text = filter_xss("Foo\xC0barbaz"); - $this->assertEqual($text, '', 'filter_xss() rejects invalid sequence "Foo\xC0barbaz"'); - $text = filter_xss("Fooÿñ"); - $this->assertEqual($text, "Fooÿñ", 'filter_xss() accepts valid sequence Fooÿñ'); + // Ignore PHP 5.3+ invalid multibyte sequence warning. + $text = @check_plain("Foo\xC0barbaz"); + $this->assertEqual($text, '', 'check_plain() rejects invalid sequence "Foo\xC0barbaz"'); + $text = check_plain("Fooÿñ"); + $this->assertEqual($text, "Fooÿñ", 'check_plain() accepts valid sequence "Fooÿñ"'); + $text = filter_xss("Foo\xC0barbaz"); + $this->assertEqual($text, '', 'filter_xss() rejects invalid sequence "Foo\xC0barbaz"'); + $text = filter_xss("Fooÿñ"); + $this->assertEqual($text, "Fooÿñ", 'filter_xss() accepts valid sequence Fooÿñ'); } /** * Check that special characters are escaped. */ function testEscaping() { - $text = check_plain("