ContentLengthTest.php

Same filename in this branch
  1. 10 core/modules/big_pipe/tests/src/Unit/StackMiddleware/ContentLengthTest.php
  2. 10 core/tests/Drupal/Tests/Core/StackMiddleware/ContentLengthTest.php
Same filename in other branches
  1. 11.x core/modules/big_pipe/tests/src/Unit/StackMiddleware/ContentLengthTest.php
  2. 11.x core/tests/Drupal/FunctionalTests/HttpKernel/ContentLengthTest.php
  3. 11.x core/tests/Drupal/Tests/Core/StackMiddleware/ContentLengthTest.php

Namespace

Drupal\FunctionalTests\HttpKernel

File

core/tests/Drupal/FunctionalTests/HttpKernel/ContentLengthTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\FunctionalTests\HttpKernel;

use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;

/**
 * Tests Content-Length set by Drupal.
 *
 * @group Http
 */
class ContentLengthTest extends BrowserTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'system',
        'http_middleware_test',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    public function testContentLength() : void {
        // Fire off a request.
        $this->drupalGet(Url::fromRoute('http_middleware_test.test_response'));
        $this->assertSession()
            ->statusCodeEquals(200);
        $this->assertSession()
            ->responseHeaderEquals('Content-Length', '40');
        $this->setContainerParameter('no-alter-content-length', TRUE);
        $this->rebuildContainer();
        // Fire the same exact request but this time length is different.
        $this->drupalGet(Url::fromRoute('http_middleware_test.test_response'));
        $this->assertSession()
            ->statusCodeEquals(200);
        $this->assertSession()
            ->responseHeaderEquals('Content-Length', '41');
    }

}

Classes

Title Deprecated Summary
ContentLengthTest Tests Content-Length set by Drupal.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.