summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-01-27 17:28:25 (GMT)
committerAlex Pott2015-01-27 17:28:25 (GMT)
commitbce75ca0827a4ada81302ee3a2db70452319f1d4 (patch)
treeec2ca4f1c66c6c061d4c1439413225f3c5304d83
parentf2fa574ce5e0694e42b32c3103760989915b0aa8 (diff)
Issue #2282035 by hussainweb, RavindraSingh, joachim: Title not shown during a batch operation
-rw-r--r--core/modules/system/src/Controller/BatchController.php11
-rw-r--r--core/modules/system/src/Tests/Batch/PageTest.php14
-rw-r--r--core/modules/system/system.routing.yml1
-rw-r--r--core/modules/system/tests/modules/batch_test/batch_test.module15
-rw-r--r--core/modules/system/tests/modules/batch_test/batch_test.routing.yml7
-rw-r--r--core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php18
6 files changed, 66 insertions, 0 deletions
diff --git a/core/modules/system/src/Controller/BatchController.php b/core/modules/system/src/Controller/BatchController.php
index ccafd85..9a0e8f0 100644
--- a/core/modules/system/src/Controller/BatchController.php
+++ b/core/modules/system/src/Controller/BatchController.php
@@ -75,4 +75,15 @@ class BatchController implements ContainerInjectionInterface {
}
}
+ /**
+ * The _title_callback for the system.batch_page.normal route.
+ *
+ * @return string
+ * The page title.
+ */
+ public function batchPageTitle() {
+ $current_set = _batch_current_set();
+ return !empty($current_set['title']) ? $current_set['title'] : '';
+ }
+
}
diff --git a/core/modules/system/src/Tests/Batch/PageTest.php b/core/modules/system/src/Tests/Batch/PageTest.php
index 1dd7628..ad5d83a 100644
--- a/core/modules/system/src/Tests/Batch/PageTest.php
+++ b/core/modules/system/src/Tests/Batch/PageTest.php
@@ -47,4 +47,18 @@ class PageTest extends WebTestBase {
// page.
$this->assertEqual(batch_test_stack(), array('seven'), 'A progressive batch correctly uses the theme of the page that started the batch.');
}
+
+ /**
+ * Tests that the batch API progress page shows the title correctly.
+ */
+ function testBatchProgressPageTitle() {
+ // Visit an administrative page that runs a test batch, and check that the
+ // title shown during batch execution (which the batch callback function
+ // saved as a variable) matches the theme used on the administrative page.
+ $this->drupalGet('batch-test/test-title');
+ // The stack should contain the title shown on the progress page.
+ $this->assertEqual(batch_test_stack(), ['Batch Test'], 'The batch title is shown on the batch page.');
+ $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
+ }
+
}
diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml
index 798cc89..2bb9e62 100644
--- a/core/modules/system/system.routing.yml
+++ b/core/modules/system/system.routing.yml
@@ -426,6 +426,7 @@ system.batch_page.html:
path: '/batch'
defaults:
_controller: '\Drupal\system\Controller\BatchController::batchPage'
+ _title_callback: '\Drupal\system\Controller\BatchController::batchPageTitle'
requirements:
_access: 'TRUE'
_format: 'html'
diff --git a/core/modules/system/tests/modules/batch_test/batch_test.module b/core/modules/system/tests/modules/batch_test/batch_test.module
index 3cf5f20..e3d1c95 100644
--- a/core/modules/system/tests/modules/batch_test/batch_test.module
+++ b/core/modules/system/tests/modules/batch_test/batch_test.module
@@ -167,6 +167,21 @@ function _batch_test_theme_callback() {
}
/**
+ * Tests the title on the progress page by performing a batch callback.
+ */
+function _batch_test_title_callback() {
+ // Because drupalGet() steps through the full progressive batch before
+ // returning control to the test function, we cannot test that the correct
+ // title is being used on the batch processing page by viewing that page
+ // directly. Instead, we save the title being used in a variable here, so
+ // that it can be loaded and inspected in the thread running the test.
+ $request = \Drupal::request();
+ $route_match = \Drupal::routeMatch();
+ $title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
+ batch_test_stack($title);
+}
+
+/**
* Helper function: Stores or retrieves traced execution data.
*/
function batch_test_stack($data = NULL, $reset = FALSE) {
diff --git a/core/modules/system/tests/modules/batch_test/batch_test.routing.yml b/core/modules/system/tests/modules/batch_test/batch_test.routing.yml
index 6736289..638d6fe 100644
--- a/core/modules/system/tests/modules/batch_test/batch_test.routing.yml
+++ b/core/modules/system/tests/modules/batch_test/batch_test.routing.yml
@@ -70,3 +70,10 @@ batch_test.test_theme:
_controller: '\Drupal\batch_test\Controller\BatchTestController::testThemeBatch'
requirements:
_access: 'TRUE'
+
+batch_test.test_title:
+ path: '/batch-test/test-title'
+ defaults:
+ _controller: '\Drupal\batch_test\Controller\BatchTestController::testTitleBatch'
+ requirements:
+ _access: 'TRUE'
diff --git a/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php b/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php
index df3a672..19ea6e9 100644
--- a/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php
+++ b/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php
@@ -113,4 +113,22 @@ class BatchTestController {
return batch_process('batch-test/redirect');
}
+ /**
+ * Runs a batch for testing the title shown on the progress page.
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
+ * A redirect response if the batch is progressive. No return value otherwise.
+ */
+ public function testTitleBatch() {
+ batch_test_stack(NULL, TRUE);
+ $batch = [
+ 'title' => 'Batch Test',
+ 'operations' => [
+ ['_batch_test_title_callback', []],
+ ],
+ ];
+ batch_set($batch);
+ return batch_process('batch-test/redirect');
+ }
+
}