summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2015-02-13 20:03:54 (GMT)
committerwebchick2015-02-13 20:03:54 (GMT)
commit30432a03b74b9e682ef931e07cb951bdea4befa8 (patch)
treed23376e330145bacbd91cc9bfadfda2e51c626a1
parentb911f7210ee58f2b1af3258273d084242f9812ab (diff)
Issue #1986330 by subhojit777, marcelodornelas, wheatpenny, kasperg, timaholt, stefank, AkshayKalose, develCuy, valthebald, moymilo, YesCT, dawehner, tstoeckler: When Batch ID doesn't exist, Drupal should emit a 404
-rw-r--r--core/includes/batch.inc5
-rw-r--r--core/tests/Drupal/Tests/Core/Batch/BatchNotFoundTest.php76
2 files changed, 79 insertions, 2 deletions
diff --git a/core/includes/batch.inc b/core/includes/batch.inc
index 7d905cd..89bd7e4 100644
--- a/core/includes/batch.inc
+++ b/core/includes/batch.inc
@@ -15,6 +15,7 @@
*/
use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Timer;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Batch\Percentage;
@@ -23,6 +24,7 @@ use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Renders the batch processing page based on the current state of the batch.
@@ -43,8 +45,7 @@ function _batch_page(Request $request) {
if (!$batch) {
$batch = \Drupal::service('batch.storage')->load($request_id);
if (!$batch) {
- drupal_set_message(t('No active batch.'), 'error');
- return new RedirectResponse(\Drupal::url('<front>', [], ['absolute' => TRUE]));
+ throw new NotFoundHttpException(String::format('Batch %id requested, but not found.', array('%id' => $request_id)));
}
}
// Restore safe strings from previous batches.
diff --git a/core/tests/Drupal/Tests/Core/Batch/BatchNotFoundTest.php b/core/tests/Drupal/Tests/Core/Batch/BatchNotFoundTest.php
new file mode 100644
index 0000000..2105599
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Batch/BatchNotFoundTest.php
@@ -0,0 +1,76 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Batch\BatchNotFoundTest.
+ */
+
+namespace Drupal\Tests\Core\Batch;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests if Drupal returns page not found error when batch ID does not exist.
+ *
+ * @group Batch
+ */
+class BatchNotFoundTest extends WebTestBase {
+
+ /**
+ * The main user for testing.
+ *
+ * @var object
+ */
+ protected $userToBeDeleted;
+
+ /**
+ * Administrator user.
+ *
+ * @var object
+ */
+ protected $adminUser;
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('views');
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->adminUser = $this->drupalCreateUser(array('administer users'));;
+ $this->userToBeDeleted = $this->drupalCreateUser();
+ }
+
+ /**
+ * Tests for page not found error if batch ID does not exist.
+ */
+ public function testBatchNotFound() {
+ $this->drupalLogin($this->adminUser);
+
+ // Replicate a batch process by cancelling a user.
+ $edit = array(
+ 'action' => 'user_cancel_user_action',
+ 'user_bulk_form[2]' => TRUE,
+ );
+ $this->drupalPostForm('admin/people', $edit, t('Apply'));
+ $this->drupalPostForm(NULL, array(), t('Cancel accounts'));
+
+ $batch_id = db_next_id();
+
+ $this->drupalGet('batch', array(
+ 'query' => array(
+ 'op' => 'start',
+ 'id' => $batch_id,
+ ),
+ ));
+
+ $this->assertResponse(404);
+ }
+
+}