summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/batch.test13
-rw-r--r--modules/simpletest/tests/common.test7
-rw-r--r--modules/simpletest/tests/database_test.test65
-rw-r--r--modules/simpletest/tests/requirements1_test.info2
-rw-r--r--modules/simpletest/tests/requirements2_test.info2
-rw-r--r--modules/simpletest/tests/system_test.module55
-rw-r--r--modules/simpletest/tests/theme.test5
-rw-r--r--modules/simpletest/tests/upgrade/drupal-6.forum.database.php1
-rw-r--r--modules/simpletest/tests/upgrade/drupal-6.menu.database.php10
-rw-r--r--modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php10
-rw-r--r--modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php10
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.forum.test1
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.menu.test44
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.user.test60
14 files changed, 268 insertions, 17 deletions
diff --git a/modules/simpletest/tests/batch.test b/modules/simpletest/tests/batch.test
index d1c0e0b2f..f668e5228 100644
--- a/modules/simpletest/tests/batch.test
+++ b/modules/simpletest/tests/batch.test
@@ -365,6 +365,19 @@ class BatchPercentagesUnitTestCase extends DrupalUnitTestCase {
'99.95' => array('total' => 2000, 'current' => 1999),
// 19999/20000 should add yet another digit and go to 99.995%.
'99.995' => array('total' => 20000, 'current' => 19999),
+ // The next five test cases simulate a batch with a single operation
+ // ('total' equals 1) that takes several steps to complete. Within the
+ // operation, we imagine that there are 501 items to process, and 100 are
+ // completed during each step. The percentages we get back should be
+ // rounded the usual way for the first few passes (i.e., 20%, 40%, etc.),
+ // but for the last pass through, when 500 out of 501 items have been
+ // processed, we do not want to round up to 100%, since that would
+ // erroneously indicate that the processing is complete.
+ '20' => array('total' => 1, 'current' => 100/501),
+ '40' => array('total' => 1, 'current' => 200/501),
+ '60' => array('total' => 1, 'current' => 300/501),
+ '80' => array('total' => 1, 'current' => 400/501),
+ '99.8' => array('total' => 1, 'current' => 500/501),
);
require_once DRUPAL_ROOT . '/includes/batch.inc';
parent::setUp();
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index d618ddb00..177e45733 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -1000,6 +1000,13 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase {
$redirect_307 = drupal_http_request(url('system-test/redirect/307', array('absolute' => TRUE)), array('max_redirects' => 0));
$this->assertFalse(isset($redirect_307->redirect_code), t('drupal_http_request does not follow 307 redirect if max_redirects = 0.'));
+
+ $multiple_redirect_final_url = url('system-test/multiple-redirects/0', array('absolute' => TRUE));
+ $multiple_redirect_1 = drupal_http_request(url('system-test/multiple-redirects/1', array('absolute' => TRUE)), array('max_redirects' => 1));
+ $this->assertEqual($multiple_redirect_1->redirect_url, $multiple_redirect_final_url, t('redirect_url contains the final redirection location after 1 redirect.'));
+
+ $multiple_redirect_3 = drupal_http_request(url('system-test/multiple-redirects/3', array('absolute' => TRUE)), array('max_redirects' => 3));
+ $this->assertEqual($multiple_redirect_3->redirect_url, $multiple_redirect_final_url, t('redirect_url contains the final redirection location after 3 redirects.'));
}
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index c22d1fc5d..143640d60 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -3251,8 +3251,10 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
* Suffix to add to field values to differentiate tests.
* @param $rollback
* Whether or not to try rolling back the transaction when we're done.
+ * @param $ddl_statement
+ * Whether to execute a DDL statement during the inner transaction.
*/
- protected function transactionOuterLayer($suffix, $rollback = FALSE) {
+ protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statement = FALSE) {
$connection = Database::getConnection();
$depth = $connection->transactionDepth();
$txn = db_transaction();
@@ -3269,7 +3271,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
// We're already in a transaction, but we call ->transactionInnerLayer
// to nest another transaction inside the current one.
- $this->transactionInnerLayer($suffix, $rollback);
+ $this->transactionInnerLayer($suffix, $rollback, $ddl_statement);
$this->assertTrue($connection->inTransaction(), t('In transaction after calling nested transaction.'));
@@ -3289,12 +3291,12 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
* Suffix to add to field values to differentiate tests.
* @param $rollback
* Whether or not to try rolling back the transaction when we're done.
+ * @param $ddl_statement
+ * Whether to execute a DDL statement during the transaction.
*/
- protected function transactionInnerLayer($suffix, $rollback = FALSE) {
+ protected function transactionInnerLayer($suffix, $rollback = FALSE, $ddl_statement = FALSE) {
$connection = Database::getConnection();
- $this->assertTrue($connection->inTransaction(), t('In transaction in nested transaction.'));
-
$depth = $connection->transactionDepth();
// Start a transaction. If we're being called from ->transactionOuterLayer,
// then we're already in a transaction. Normally, that would make starting
@@ -3315,6 +3317,22 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$this->assertTrue($connection->inTransaction(), t('In transaction inside nested transaction.'));
+ if ($ddl_statement) {
+ $table = array(
+ 'fields' => array(
+ 'id' => array(
+ 'type' => 'serial',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+ db_create_table('database_test_1', $table);
+
+ $this->assertTrue($connection->inTransaction(), t('In transaction inside nested transaction.'));
+ }
+
if ($rollback) {
// Roll back the transaction, if requested.
// This rollback should propagate to the last savepoint.
@@ -3396,6 +3414,43 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
$this->fail($e->getMessage());
}
}
+
+ /**
+ * Test the compatibility of transactions with DDL statements.
+ */
+ function testTransactionWithDdlStatement() {
+ // First, test that a commit works normally, even with DDL statements.
+ try {
+ $this->transactionOuterLayer('D', FALSE, TRUE);
+
+ // Because we committed, the inserted rows should both be present.
+ $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidD'))->fetchField();
+ $this->assertIdentical($saved_age, '24', t('Can retrieve DavidD row after commit.'));
+ $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielD'))->fetchField();
+ $this->assertIdentical($saved_age, '19', t('Can retrieve DanielD row after commit.'));
+ // The created table should also exist.
+ $count = db_query('SELECT COUNT(id) FROM {database_test_1}')->fetchField();
+ $this->assertIdentical($count, '0', t('Table was successfully created inside a transaction.'));
+ }
+ catch (Exception $e) {
+ $this->fail($e->getMessage());
+ }
+
+ // If we rollback the transaction, an exception might be thrown.
+ try {
+ $this->transactionOuterLayer('E', TRUE, TRUE);
+
+ // Because we rolled back, the inserted rows shouldn't be present.
+ $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidE'))->fetchField();
+ $this->assertNotIdentical($saved_age, '24', t('Cannot retrieve DavidE row after rollback.'));
+ $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielE'))->fetchField();
+ $this->assertNotIdentical($saved_age, '19', t('Cannot retrieve DanielE row after rollback.'));
+ }
+ catch (Exception $e) {
+ // An exception also lets the test pass.
+ $this->assertTrue(true, t('Exception thrown on rollback after a DDL statement was executed.'));
+ }
+ }
}
diff --git a/modules/simpletest/tests/requirements1_test.info b/modules/simpletest/tests/requirements1_test.info
index ef3953517..b659b21c7 100644
--- a/modules/simpletest/tests/requirements1_test.info
+++ b/modules/simpletest/tests/requirements1_test.info
@@ -1,6 +1,6 @@
name = Requirements 1 Test
description = "Tests that a module is not installed when it fails hook_requirements('install')."
-package = Core
+package = Testing
version = VERSION
core = 7.x
hidden = TRUE
diff --git a/modules/simpletest/tests/requirements2_test.info b/modules/simpletest/tests/requirements2_test.info
index 0cf86478e..a66e04be9 100644
--- a/modules/simpletest/tests/requirements2_test.info
+++ b/modules/simpletest/tests/requirements2_test.info
@@ -2,7 +2,7 @@ name = Requirements 2 Test
description = "Tests that a module is not installed when the one it depends on fails hook_requirements('install)."
dependencies[] = requirements1_test
dependencies[] = comment
-package = Core
+package = Testing
version = VERSION
core = 7.x
hidden = TRUE
diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module
index 76841fb6b..9516c9183 100644
--- a/modules/simpletest/tests/system_test.module
+++ b/modules/simpletest/tests/system_test.module
@@ -28,6 +28,13 @@ function system_test_menu() {
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
+ $items['system-test/multiple-redirects/%'] = array(
+ 'title' => 'Redirect',
+ 'page callback' => 'system_test_multiple_redirects',
+ 'page arguments' => array(2),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
$items['system-test/set-header'] = array(
'page callback' => 'system_test_set_header',
'access arguments' => array('access content'),
@@ -122,6 +129,30 @@ function system_test_redirect($code) {
return '';
}
+/**
+ * Menu callback; sends a redirect header to itself until $count argument is 0.
+ *
+ * Emulates the variable number of redirects (given by initial $count argument)
+ * to the final destination URL by continuous sending of 301 HTTP redirect
+ * headers to itself together with decrementing the $count parameter until the
+ * $count parameter reaches 0. After that it returns an empty string to render
+ * the final destination page.
+ *
+ * @param $count
+ * The count of redirects left until the final destination page.
+ *
+ * @returns
+ * The location redirect if the $count > 0, otherwise an empty string.
+ */
+function system_test_multiple_redirects($count) {
+ $count = (int) $count;
+ if ($count > 0) {
+ header("location: " . url('system-test/multiple-redirects/' . --$count, array('absolute' => TRUE)), TRUE, 301);
+ exit;
+ }
+ return '';
+}
+
function system_test_set_header() {
drupal_add_http_header($_GET['name'], $_GET['value']);
return t('The following header was set: %name: %value', array('%name' => $_GET['name'], '%value' => $_GET['value']));
@@ -146,8 +177,10 @@ function system_test_redirect_invalid_scheme() {
* Implements hook_modules_installed().
*/
function system_test_modules_installed($modules) {
- if (in_array('aggregator', $modules)) {
- drupal_set_message(t('hook_modules_installed fired for aggregator'));
+ if (variable_get('test_verbose_module_hooks')) {
+ foreach ($modules as $module) {
+ drupal_set_message(t('hook_modules_installed fired for @module', array('@module' => $module)));
+ }
}
}
@@ -155,8 +188,10 @@ function system_test_modules_installed($modules) {
* Implements hook_modules_enabled().
*/
function system_test_modules_enabled($modules) {
- if (in_array('aggregator', $modules)) {
- drupal_set_message(t('hook_modules_enabled fired for aggregator'));
+ if (variable_get('test_verbose_module_hooks')) {
+ foreach ($modules as $module) {
+ drupal_set_message(t('hook_modules_enabled fired for @module', array('@module' => $module)));
+ }
}
}
@@ -164,8 +199,10 @@ function system_test_modules_enabled($modules) {
* Implements hook_modules_disabled().
*/
function system_test_modules_disabled($modules) {
- if (in_array('aggregator', $modules)) {
- drupal_set_message(t('hook_modules_disabled fired for aggregator'));
+ if (variable_get('test_verbose_module_hooks')) {
+ foreach ($modules as $module) {
+ drupal_set_message(t('hook_modules_disabled fired for @module', array('@module' => $module)));
+ }
}
}
@@ -173,8 +210,10 @@ function system_test_modules_disabled($modules) {
* Implements hook_modules_uninstalled().
*/
function system_test_modules_uninstalled($modules) {
- if (in_array('aggregator', $modules)) {
- drupal_set_message(t('hook_modules_uninstalled fired for aggregator'));
+ if (variable_get('test_verbose_module_hooks')) {
+ foreach ($modules as $module) {
+ drupal_set_message(t('hook_modules_uninstalled fired for @module', array('@module' => $module)));
+ }
}
}
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index d0ad77d78..f1e1bd58b 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -42,6 +42,11 @@ class ThemeUnitTest extends DrupalWebTestCase {
$args = array('node', "1\0");
$suggestions = theme_get_suggestions($args, 'page');
$this->assertEqual($suggestions, array('page__node', 'page__node__%', 'page__node__1'), t('Removed invalid \\0 from suggestions'));
+ // Define path with hyphens to be used to generate suggestions.
+ $args = array('node', '1', 'hyphen-path');
+ $result = array('page__node', 'page__node__%', 'page__node__1', 'page__node__hyphen_path');
+ $suggestions = theme_get_suggestions($args, 'page');
+ $this->assertEqual($suggestions, $result, t('Found expected page suggestions for paths containing hyphens.'));
}
/**
diff --git a/modules/simpletest/tests/upgrade/drupal-6.forum.database.php b/modules/simpletest/tests/upgrade/drupal-6.forum.database.php
index 07dfcb341..5a2cc3324 100644
--- a/modules/simpletest/tests/upgrade/drupal-6.forum.database.php
+++ b/modules/simpletest/tests/upgrade/drupal-6.forum.database.php
@@ -1,5 +1,4 @@
<?php
-// $Id$
/**
* Database additions for forum tests.
diff --git a/modules/simpletest/tests/upgrade/drupal-6.menu.database.php b/modules/simpletest/tests/upgrade/drupal-6.menu.database.php
new file mode 100644
index 000000000..d10c4eec4
--- /dev/null
+++ b/modules/simpletest/tests/upgrade/drupal-6.menu.database.php
@@ -0,0 +1,10 @@
+<?php
+db_insert('variable')->fields(array(
+ 'name',
+ 'value',
+))
+->values(array(
+ 'name' => 'menu_default_node_menu',
+ 'value' => 's:15:"secondary-links";',
+))
+->execute();
diff --git a/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php b/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php
new file mode 100644
index 000000000..646319462
--- /dev/null
+++ b/modules/simpletest/tests/upgrade/drupal-6.user-no-password-token.database.php
@@ -0,0 +1,10 @@
+<?php
+db_insert('variable')->fields(array(
+ 'name',
+ 'value',
+))
+->values(array(
+ 'name' => 'user_mail_register_no_approval_required_body',
+ 'value' => 's:86:"!username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.";',
+))
+->execute();
diff --git a/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php b/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php
new file mode 100644
index 000000000..367c70481
--- /dev/null
+++ b/modules/simpletest/tests/upgrade/drupal-6.user-password-token.database.php
@@ -0,0 +1,10 @@
+<?php
+db_insert('variable')->fields(array(
+ 'name',
+ 'value',
+))
+->values(array(
+ 'name' => 'user_mail_register_no_approval_required_body',
+ 'value' => 's:97:"!password, !username, !site, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.";',
+))
+->execute();
diff --git a/modules/simpletest/tests/upgrade/upgrade.forum.test b/modules/simpletest/tests/upgrade/upgrade.forum.test
index 827988dab..99269d9f4 100644
--- a/modules/simpletest/tests/upgrade/upgrade.forum.test
+++ b/modules/simpletest/tests/upgrade/upgrade.forum.test
@@ -1,5 +1,4 @@
<?php
-// $Id$
/**
* Upgrade test for forum.module.
diff --git a/modules/simpletest/tests/upgrade/upgrade.menu.test b/modules/simpletest/tests/upgrade/upgrade.menu.test
new file mode 100644
index 000000000..beb20277a
--- /dev/null
+++ b/modules/simpletest/tests/upgrade/upgrade.menu.test
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * Upgrade test for menu.module.
+ */
+class MenuUpgradePathTestCase extends UpgradePathTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Menu upgrade path',
+ 'description' => 'Menu upgrade path tests.',
+ 'group' => 'Upgrade path',
+ );
+ }
+
+ public function setUp() {
+ // Path to the database dump files.
+ $this->databaseDumpFiles = array(
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.menu.database.php',
+ );
+ parent::setUp();
+
+ $this->uninstallModulesExcept(array('menu'));
+ }
+
+ /**
+ * Test a successful upgrade.
+ */
+ public function testMenuUpgrade() {
+ $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
+
+ // Test the migration of "Default menu for content" setting to individual node types.
+ $this->drupalGet("admin/structure/types/manage/page/edit");
+ $this->assertNoFieldChecked('edit-menu-options-management', 'Management menu is not selected as available menu');
+ $this->assertNoFieldChecked('edit-menu-options-navigation', 'Navigation menu is not selected as available menu');
+ $this->assertNoFieldChecked('edit-menu-options-primary-links', 'Primary Links menu is not selected as available menu');
+ $this->assertFieldChecked('edit-menu-options-secondary-links', 'Secondary Links menu is selected as available menu');
+ $this->assertNoFieldChecked('edit-menu-options-user-menu', 'User menu is not selected as available menu');
+ $this->assertOptionSelected('edit-menu-parent', 'secondary-links:0', 'Secondary links is selected as default parent item');
+
+ $this->assertEqual(variable_get('menu_default_node_menu'), NULL, 'Redundant variable menu_default_node_menu has been removed');
+
+ }
+}
diff --git a/modules/simpletest/tests/upgrade/upgrade.user.test b/modules/simpletest/tests/upgrade/upgrade.user.test
new file mode 100644
index 000000000..6c669219a
--- /dev/null
+++ b/modules/simpletest/tests/upgrade/upgrade.user.test
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Upgrade test for user.module (password token involved).
+ */
+class UserUpgradePathPasswordTokenTestCase extends UpgradePathTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'User upgrade path (password token involved)',
+ 'description' => 'User upgrade path tests (password token involved).',
+ 'group' => 'Upgrade path',
+ );
+ }
+
+ public function setUp() {
+ // Path to the database dump files.
+ $this->databaseDumpFiles = array(
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.bare.database.php',
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.user-password-token.database.php',
+ );
+ parent::setUp();
+ }
+
+ /**
+ * Test a successful upgrade.
+ */
+ public function testUserUpgrade() {
+ $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
+ $this->assertEqual(variable_get('user_mail_register_no_approval_required_body'), ', [user:name], [site:name], [site:url], [site:url-brief], [user:mail], [date:medium], [site:login-url], [user:edit-url], [user:one-time-login-url].', 'Existing email templates have been modified (password token involved).');
+ }
+}
+
+/**
+ * Upgrade test for user.module (password token not involved).
+ */
+class UserUpgradePathNoPasswordTokenTestCase extends UpgradePathTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'User upgrade path (password token not involved)',
+ 'description' => 'User upgrade path tests (password token not involved).',
+ 'group' => 'Upgrade path',
+ );
+ }
+
+ public function setUp() {
+ // Path to the database dump files.
+ $this->databaseDumpFiles = array(
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.bare.database.php',
+ drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.user-no-password-token.database.php',
+ );
+ parent::setUp();
+ }
+
+ /**
+ * Test a successful upgrade.
+ */
+ public function testUserUpgrade() {
+ $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
+ $this->assertEqual(variable_get('user_mail_register_no_approval_required_body'), '[user:name], [site:name], [site:url], [site:url-brief], [user:mail], [date:medium], [site:login-url], [user:edit-url], [user:one-time-login-url].', 'Existing email templates have been modified (password token not involved).');
+ }
+}