Verified Commit cb28194e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3429403 by Spokje: Tighten ParameterBag classes in PHPUnit tests

(cherry picked from commit 1feb9327)
parent a5826e68
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\FileBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;

@@ -967,7 +967,7 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state

            $request = $this->requestStack->getCurrentRequest();
            // Do not trust any POST data.
            $request->request = new ParameterBag();
            $request->request = new InputBag();
            // Make sure file uploads do not get processed.
            $request->files = new FileBag();
            // Ensure PHP globals reflect these changes.
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ServerBag;
use Symfony\Component\Routing\Route;
@@ -106,7 +106,7 @@ public function testGetLangcode() {
    // Case 2: A request is available, but the languageManager is not set and
    // the static::QUERY_PARAMETER is not provided as a named parameter.
    $request = Request::create('/de/foo', 'GET');
    $request->query = new ParameterBag();
    $request->query = new InputBag();
    $this->assertEquals(NULL, $languageNegotiationContentEntity->getLangcode($request));

    // Case 3: A request is available, the languageManager is set, but the
+2 −10
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\InputBag;
use Symfony\Component\HttpFoundation\Request;

/**
@@ -50,18 +50,10 @@ public function testViewsForm(): void {
    $container->set('string_translation', $this->createMock(TranslationInterface::class));
    \Drupal::setContainer($container);

    $query = $this->getMockBuilder(ParameterBag::class)
      ->onlyMethods(['all'])
      ->disableOriginalConstructor()
      ->getMock();
    $query->expects($this->any())
      ->method('all')
      ->willReturn([]);

    $request = $this->getMockBuilder(Request::class)
      ->disableOriginalConstructor()
      ->getMock();
    $request->query = $query;
    $request->query = new InputBag();

    $view = $this->getMockBuilder(ViewExecutable::class)
      ->onlyMethods(['getRequest', 'initStyle', 'getDisplay'])
+2 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Core\Logger\LoggerChannel;
use Drupal\Core\Session\AccountInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Psr\Log\LoggerInterface;
@@ -142,7 +143,7 @@ public function providerTestLog() {
    $request_mock->expects($this->any())
      ->method('getClientIp')
      ->willReturn('127.0.0.1');
    $request_mock->headers = $this->createMock('Symfony\Component\HttpFoundation\ParameterBag');
    $request_mock->headers = $this->createMock(HeaderBag::class);

    // No request or account.
    $cases[] = [
+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@

use Drupal\Core\Routing\ContentTypeHeaderMatcher;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;

@@ -130,7 +130,7 @@ public function testContentTypeRequestHeaderMissing() {
    $routes = $this->fixtures->contentRouteCollection();
    $request = Request::create('path/two', 'POST');
    // Delete all request headers that Request::create() sets by default.
    $request->headers = new ParameterBag();
    $request->headers = new HeaderBag();
    $this->expectException(UnsupportedMediaTypeHttpException::class);
    $this->expectExceptionMessage('No "Content-Type" request header specified');
    $matcher->filter($routes, $request);
Loading