summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-02 15:57:33 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-02 15:57:33 +0000
commit032fe0a66d97469609f5fe7cc6be242765042a63 (patch)
treee4c3fb97ff1319a39b6086f29673d357f3f0fcfe /modules
parent4363c22b0398472b62a87f9f5c2b7ed88a393a77 (diff)
downloadbrdo-032fe0a66d97469609f5fe7cc6be242765042a63.tar.gz
brdo-032fe0a66d97469609f5fe7cc6be242765042a63.tar.bz2
#539022 follow-up by David_Rothstein: Batch API should use the current theme to run the batches.
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/batch.test34
-rw-r--r--modules/simpletest/tests/system_test.module33
-rw-r--r--modules/system/system.admin.inc4
-rw-r--r--modules/system/system.module17
4 files changed, 84 insertions, 4 deletions
diff --git a/modules/simpletest/tests/batch.test b/modules/simpletest/tests/batch.test
index a3ace7b9e..897e8a803 100644
--- a/modules/simpletest/tests/batch.test
+++ b/modules/simpletest/tests/batch.test
@@ -7,6 +7,40 @@
*/
/**
+ * Tests for the batch API progress page theme.
+ */
+class BatchAPIThemeTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Batch API progress page theme',
+ 'description' => 'Tests that while a progressive batch is running, it correctly uses the theme of the page that started the batch.',
+ 'group' => 'Batch API',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('system_test');
+ // Make sure that the page which starts the batch (an administrative page)
+ // is using a different theme than would normally be used by the batch API.
+ variable_set('theme_default', 'garland');
+ variable_set('admin_theme', 'seven');
+ }
+
+ /**
+ * Tests that the batch API progress page uses the correct theme.
+ */
+ function testBatchAPIProgressPageTheme() {
+ // Visit an administrative page that runs a test batch, and check that the
+ // theme that was used during batch execution (which the batch callback
+ // function saved as a variable) matches the theme used on the
+ // administrative page.
+ $this->drupalGet('admin/system-test/batch-theme');
+ $batch_theme_used = variable_get('system_test_batch_theme_used', 'garland');
+ $this->assertEqual($batch_theme_used, 'seven', t('A progressive batch correctly uses the theme of the page that started the batch.'));
+ }
+}
+
+/**
* Tests the function _batch_api_percentage() to make sure that the rounding
* works properly in all cases.
*/
diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module
index be4d443f5..670305536 100644
--- a/modules/simpletest/tests/system_test.module
+++ b/modules/simpletest/tests/system_test.module
@@ -5,6 +5,11 @@
* Implement hook_menu().
*/
function system_test_menu() {
+ $items['admin/system-test/batch-theme'] = array(
+ 'page callback' => 'system_test_batch_theme',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
$items['system-test/sleep/%'] = array(
'page callback' => 'system_test_sleep',
'page arguments' => array(2),
@@ -97,6 +102,34 @@ function system_test_menu() {
return $items;
}
+/**
+ * Menu callback; start a new batch for testing the batch progress page theme.
+ */
+function system_test_batch_theme() {
+ $batch = array(
+ 'operations' => array(
+ array('system_test_batch_theme_callback', array()),
+ ),
+ );
+ batch_set($batch);
+ // Force the batch to redirect to some page other than this one (to avoid an
+ // infinite loop).
+ batch_process('node');
+}
+
+/**
+ * Batch callback function for testing the theme used by a batch.
+ */
+function system_test_batch_theme_callback() {
+ // Because drupalGet() steps through the full progressive batch before
+ // returning control to the test function, we cannot test that the correct
+ // theme is being used on the batch processing page by viewing that page
+ // directly. Instead, we save the theme being used in a variable here, so
+ // that it can be loaded and inspected in the thread running the test.
+ global $theme;
+ variable_set('system_test_batch_theme_used', $theme);
+}
+
function system_test_sleep($seconds) {
sleep($seconds);
}
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index aa1d2e9d1..7e672950f 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -2054,10 +2054,6 @@ function system_batch_page() {
require_once DRUPAL_ROOT . '/includes/batch.inc';
$output = _batch_page();
- // Use the same theme that the page that started the batch.
- $batch = &batch_get();
- $GLOBALS['custom_theme'] = $batch['theme'];
-
if ($output === FALSE) {
drupal_access_denied();
}
diff --git a/modules/system/system.module b/modules/system/system.module
index 4b69e964b..7398653ad 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -993,6 +993,7 @@ function system_menu() {
$items['batch'] = array(
'page callback' => 'system_batch_page',
'access callback' => TRUE,
+ 'theme callback' => '_system_batch_theme',
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
@@ -1000,6 +1001,22 @@ function system_menu() {
}
/**
+ * Theme callback for the default batch page.
+ */
+function _system_batch_theme() {
+ // Retrieve the current state of the batch.
+ $batch = &batch_get();
+ if (!$batch && isset($_REQUEST['id'])) {
+ require_once DRUPAL_ROOT . '/includes/batch.inc';
+ $batch = batch_load($_REQUEST['id']);
+ }
+ // Use the same theme as the page that started the batch.
+ if (!empty($batch['theme'])) {
+ return $batch['theme'];
+ }
+}
+
+/**
* Implementation of hook_library().
*/
function system_library() {