Skip to content
Snippets Groups Projects
Verified Commit 787cc8ab authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #1986330 by bhanu951, subhojit777, marcelodornelas, ravi.shankar,...

Issue #1986330 by bhanu951, subhojit777, marcelodornelas, ravi.shankar, immaculatexavier, wheatpenny, nikunjkotecha, shashikant_chauhan, vacho, smagdits, kasperg, aron.beal, andriansyah, suresh prabhu parkala, rajeevk, benjifisher, mangy.fox, cebasqueira, stefank, richardcanoe, quietone, yesct, AkshayKalose, drdam, DevElCuy, john cook, moymilo, alexpott, xjm, dawehner, tstoeckler, webchick, akashkumar07: When Batch ID doesn't exist, Drupal should emit a 404
parent eba0136d
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Renders the batch processing page based on the current state of the batch. * Renders the batch processing page based on the current state of the batch.
...@@ -42,8 +43,8 @@ function _batch_page(Request $request) { ...@@ -42,8 +43,8 @@ function _batch_page(Request $request) {
if (!$batch) { if (!$batch) {
$batch = \Drupal::service('batch.storage')->load($request_id); $batch = \Drupal::service('batch.storage')->load($request_id);
if (!$batch) { if (!$batch) {
\Drupal::messenger()->addError(t('No active batch.')); \Drupal::messenger()->addError(t('No batch with ID @batch exists.', ['@batch' => $request_id]));
return new RedirectResponse(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString()); throw new NotFoundHttpException(sprintf('No batch with ID %s exists.', $request_id));
} }
} }
......
<?php
declare(strict_types=1);
namespace Drupal\Tests\system\Functional\Batch;
use Drupal\Core\Batch\BatchStorageInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Tests if a page not found error is returned when a batch ID does not exist.
*
* @group Batch
*/
class BatchNotFoundTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['batch_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests for page not found error if batch ID does not exist.
*/
public function testBatchNotFound(): void {
$edit = ['batch' => 'batch_0'];
$this->drupalGet('batch-test');
$this->submitForm($edit, 'Submit');
$this->assertSession()->statusCodeEquals(200);
$batch_id = \Drupal::service(BatchStorageInterface::class)->getId();
$this->drupalGet('batch', [
'query' => [
'op' => 'start',
'id' => $batch_id,
],
]);
$this->assertSession()->statusCodeEquals(404);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment