Commit bce75ca0 authored by alexpott's avatar alexpott

Issue #2282035 by hussainweb, RavindraSingh, joachim: Title not shown during a batch operation

parent f2fa574c
......@@ -75,4 +75,15 @@ public function batchPage(Request $request) {
}
}
/**
* 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'] : '';
}
}
......@@ -47,4 +47,18 @@ function testBatchProgressPageTheme() {
// 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.');
}
}
......@@ -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'
......
......@@ -166,6 +166,21 @@ function _batch_test_theme_callback() {
batch_test_stack($theme);
}
/**
* 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.
*/
......
......@@ -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'
......@@ -113,4 +113,22 @@ public function testThemeBatch() {
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');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment