Loading core/misc/batch.js +6 −2 Changes for core/misc/batch.js: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -19,7 +19,9 @@ function updateCallback(progress, status, pb) { if (progress === '100') { pb.stopMonitoring(); window.location = `${batch.uri}&op=finished`; const url = new URL(batch.uri, window.location.origin); url.searchParams.set('op', 'finished'); window.location = url.toString(); } } Loading @@ -36,7 +38,9 @@ errorCallback, ); progressBar.setProgress(-1, batch.initMessage); progressBar.startMonitoring(`${batch.uri}&op=do`, 10); const url = new URL(batch.uri, window.location.origin); url.searchParams.set('op', 'do'); progressBar.startMonitoring(url.toString(), 10); // Remove HTML from no-js progress bar. $progress.empty(); // Append the JS progressbar element. Loading core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php +43 −0 Changes for core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php: 43 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -127,6 +127,24 @@ public function callback8(bool $throw_exception): void { } } /** * Implements callback_batch_operation(). * * Performs a simple batch operation. */ public function callback9(array &$context): void { if (!isset($context['sandbox']['count'])) { $context['sandbox']['count'] = 0; } // No-op, but ensure the batch takes a couple iterations. // Batch needs time to run for the test, so sleep a bit. usleep(500); $context['sandbox']['count']++; $context['finished'] = $context['sandbox']['count'] / 5; $context['results'][] = \Drupal::request()->getUri(); } /** * Implements callback_batch_operation(). * Loading Loading @@ -268,4 +286,29 @@ public function finished7($success, $results, $operations, $elapsed): void { $this->finishedHelper(7, $success, $results, $operations, $elapsed); } /** * Implements callback_batch_finished(). * * Triggers 'finished' callback for batch 9. */ public function finished9($success, $results, $operations, $elapsed): void { // Use item list template to render the messages. $message = [ '#type' => 'inline_template', '#template' => 'Finished Url: <span class="batch-finished-url">{{ finished_url }}</span><br/ >Batch URLs: {{ urls }}', '#context' => [ 'finished_url' => \Drupal::request()->getUri(), 'urls' => [ '#theme' => 'item_list', '#items' => $results, '#attributes' => [ 'class' => ['batch-urls'], ], ], ], ]; \Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderInIsolation($message)); } } core/modules/system/tests/modules/batch_test/src/BatchTestDefinitions.php +10 −0 Changes for core/modules/system/tests/modules/batch_test/src/BatchTestDefinitions.php: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -188,4 +188,14 @@ public function batch8(): array { return $batch_builder->toArray() + ['batch_test_id' => 'batch8']; } /** * Batch 9: Displays URLs. */ public function batch9(): array { $batch_builder = (new BatchBuilder()) ->addOperation(BatchTestCallbacks::class . ':callback9') ->setFinishCallback(BatchTestCallbacks::class . ':finished9'); return $batch_builder->toArray(); } } core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php +1 −0 Changes for core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'batch6' => 'batch 6', 'batch7' => 'batch 7', 'batch8' => 'batch 8', 'batch9' => 'batch 9', ], '#multiple' => TRUE, ]; Loading core/modules/system/tests/src/FunctionalJavascript/Batch/ProcessingTest.php +18 −0 Changes for core/modules/system/tests/src/FunctionalJavascript/Batch/ProcessingTest.php: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,4 +41,22 @@ public function testLinkToErrorPageAppears(): void { $this->assertSession()->pageTextContains('Redirection successful.'); } /** * Tests that JS batches replace the op in the URL and do not add to it. */ public function testBatchUrls(): void { $edit = ['batch' => 'batch9']; $this->drupalGet('batch-test'); $this->submitForm($edit, 'Submit'); $this->assertSession()->waitForElementVisible('css', '.batch-urls'); $batch_url_list = $this->assertSession()->elementExists('css', '.batch-urls'); $batch_url_list_items = $batch_url_list->findAll('css', 'li'); $this->assertCount(5, $batch_url_list_items); foreach ($batch_url_list_items as $batch_url_list_item) { $this->assertStringEndsWith('/batch?_format=json&id=1&op=do', $batch_url_list_item->getText()); } $batch_finished_url = $this->assertSession()->elementExists('css', '.batch-finished-url'); $this->assertStringEndsWith('/batch?id=1&op=finished', $batch_finished_url->getText()); } } Loading
core/misc/batch.js +6 −2 Changes for core/misc/batch.js: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -19,7 +19,9 @@ function updateCallback(progress, status, pb) { if (progress === '100') { pb.stopMonitoring(); window.location = `${batch.uri}&op=finished`; const url = new URL(batch.uri, window.location.origin); url.searchParams.set('op', 'finished'); window.location = url.toString(); } } Loading @@ -36,7 +38,9 @@ errorCallback, ); progressBar.setProgress(-1, batch.initMessage); progressBar.startMonitoring(`${batch.uri}&op=do`, 10); const url = new URL(batch.uri, window.location.origin); url.searchParams.set('op', 'do'); progressBar.startMonitoring(url.toString(), 10); // Remove HTML from no-js progress bar. $progress.empty(); // Append the JS progressbar element. Loading
core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php +43 −0 Changes for core/modules/system/tests/modules/batch_test/src/BatchTestCallbacks.php: 43 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -127,6 +127,24 @@ public function callback8(bool $throw_exception): void { } } /** * Implements callback_batch_operation(). * * Performs a simple batch operation. */ public function callback9(array &$context): void { if (!isset($context['sandbox']['count'])) { $context['sandbox']['count'] = 0; } // No-op, but ensure the batch takes a couple iterations. // Batch needs time to run for the test, so sleep a bit. usleep(500); $context['sandbox']['count']++; $context['finished'] = $context['sandbox']['count'] / 5; $context['results'][] = \Drupal::request()->getUri(); } /** * Implements callback_batch_operation(). * Loading Loading @@ -268,4 +286,29 @@ public function finished7($success, $results, $operations, $elapsed): void { $this->finishedHelper(7, $success, $results, $operations, $elapsed); } /** * Implements callback_batch_finished(). * * Triggers 'finished' callback for batch 9. */ public function finished9($success, $results, $operations, $elapsed): void { // Use item list template to render the messages. $message = [ '#type' => 'inline_template', '#template' => 'Finished Url: <span class="batch-finished-url">{{ finished_url }}</span><br/ >Batch URLs: {{ urls }}', '#context' => [ 'finished_url' => \Drupal::request()->getUri(), 'urls' => [ '#theme' => 'item_list', '#items' => $results, '#attributes' => [ 'class' => ['batch-urls'], ], ], ], ]; \Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderInIsolation($message)); } }
core/modules/system/tests/modules/batch_test/src/BatchTestDefinitions.php +10 −0 Changes for core/modules/system/tests/modules/batch_test/src/BatchTestDefinitions.php: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -188,4 +188,14 @@ public function batch8(): array { return $batch_builder->toArray() + ['batch_test_id' => 'batch8']; } /** * Batch 9: Displays URLs. */ public function batch9(): array { $batch_builder = (new BatchBuilder()) ->addOperation(BatchTestCallbacks::class . ':callback9') ->setFinishCallback(BatchTestCallbacks::class . ':finished9'); return $batch_builder->toArray(); } }
core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php +1 −0 Changes for core/modules/system/tests/modules/batch_test/src/Form/BatchTestSimpleForm.php: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'batch6' => 'batch 6', 'batch7' => 'batch 7', 'batch8' => 'batch 8', 'batch9' => 'batch 9', ], '#multiple' => TRUE, ]; Loading
core/modules/system/tests/src/FunctionalJavascript/Batch/ProcessingTest.php +18 −0 Changes for core/modules/system/tests/src/FunctionalJavascript/Batch/ProcessingTest.php: 18 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -41,4 +41,22 @@ public function testLinkToErrorPageAppears(): void { $this->assertSession()->pageTextContains('Redirection successful.'); } /** * Tests that JS batches replace the op in the URL and do not add to it. */ public function testBatchUrls(): void { $edit = ['batch' => 'batch9']; $this->drupalGet('batch-test'); $this->submitForm($edit, 'Submit'); $this->assertSession()->waitForElementVisible('css', '.batch-urls'); $batch_url_list = $this->assertSession()->elementExists('css', '.batch-urls'); $batch_url_list_items = $batch_url_list->findAll('css', 'li'); $this->assertCount(5, $batch_url_list_items); foreach ($batch_url_list_items as $batch_url_list_item) { $this->assertStringEndsWith('/batch?_format=json&id=1&op=do', $batch_url_list_item->getText()); } $batch_finished_url = $this->assertSession()->elementExists('css', '.batch-finished-url'); $this->assertStringEndsWith('/batch?id=1&op=finished', $batch_finished_url->getText()); } }