wiki.techinc.nl/tests/phpunit/includes/Request/WebResponseTest.php
daniel 24d0aee05e entrypoint: Isolate entry points from PHP runtime for testing
1) Introduce EntryPointEnvironment which wraps functions that interact
with the PHP runtime, so they can be mocked for testing.

2) Allow server info fields to be overwritten in FauxRequest.

3) Make MediaWikiEntryPoint use WebResponse to set headers

Bug: T354216
Change-Id: Ic21950c956de5d2b5a7dd66a1e2de58f807cfd9f
2024-02-02 13:03:29 +01:00

54 lines
1.2 KiB
PHP

<?php
use MediaWiki\Request\WebResponse;
/**
* @covers MediaWiki\Request\WebResponse
*
* @group WebRequest
*/
class WebResponseTest extends MediaWikiIntegrationTestCase {
/**
* Test that no cookies get set post-send.
*/
public function testDisableForPostSend() {
$response = new WebResponse;
$response->disableForPostSend();
$hookWasRun = false;
$this->setTemporaryHook( 'WebResponseSetCookie', static function () use ( &$hookWasRun ) {
$hookWasRun = true;
return true;
} );
$logger = new TestLogger();
$logger->setCollect( true );
$this->setLogger( 'cookie', $logger );
$this->setLogger( 'header', $logger );
$response->setCookie( 'TetsCookie', 'foobar' );
$response->header( 'TestHeader', 'foobar' );
$this->assertFalse( $hookWasRun, 'The WebResponseSetCookie hook should not run' );
$this->assertEquals(
[
[ 'info', 'ignored post-send cookie {cookie}' ],
[ 'info', 'ignored post-send header {header}' ],
],
$logger->getBuffer()
);
}
public function testStatusCode() {
$response = new WebResponse();
$response->statusHeader( 404 );
$this->assertSame( 404, $response->getStatusCode() );
$response->header( 'Test', true, 415 );
$this->assertSame( 415, $response->getStatusCode() );
}
}