| 1 |
<?php |
| 2 |
namespace MediaWiki\Tests; |
| 3 |
|
| 4 |
use MediaWiki\Context\RequestContext; |
| 5 |
use MediaWiki\MediaWikiEntryPoint; |
| 6 |
use MediaWiki\MediaWikiServices; |
| 7 |
use MediaWiki\Request\FauxRequest; |
| 8 |
use MediaWikiIntegrationTestCase; |
| 9 |
use Wikimedia\TestingAccessWrapper; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class MediaWikiEntryPointTest extends MediaWikiIntegrationTestCase { |
| 15 |
|
| 16 |
private function newEntryPoint(): MediaWikiEntryPoint { |
| 17 |
$context = new RequestContext(); |
| 18 |
$context->setRequest( new FauxRequest() ); |
| 19 |
$environment = new MockEnvironment(); |
| 20 |
$services = $this->createMock( MediaWikiServices::class ); |
| 21 |
|
| 22 |
$mw = $this->getMockBuilder( MediaWikiEntryPoint::class ) |
| 23 |
->onlyMethods( [ 'execute' ] ) |
| 24 |
->setConstructorArgs( [ $context, $environment, $services ] ) |
| 25 |
->getMockForAbstractClass(); |
| 26 |
|
| 27 |
return $mw; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function testOutputBuffer() { |
| 42 |
$oldLevel = ob_get_level(); |
| 43 |
|
| 44 |
$mw = TestingAccessWrapper::newFromObject( $this->newEntryPoint() ); |
| 45 |
$mw->enableOutputCapture(); |
| 46 |
|
| 47 |
$mw->startOutputBuffer(); |
| 48 |
$this->assertSame( 1, $mw->getOutputBufferLevel(), 'getOutputBufferLevel' ); |
| 49 |
|
| 50 |
print 'Testing test'; |
| 51 |
$this->assertSame( 12, $mw->getOutputBufferLength(), 'getOutputBufferLength' ); |
| 52 |
|
| 53 |
$mw->flushOutputBuffer(); |
| 54 |
|
| 55 |
$this->assertSame( $oldLevel, ob_get_level(), 'ob_get_level' ); |
| 56 |
$this->assertSame( 'Testing test', $mw->drainOutputBuffer() ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function testFlushOutputBuffers_sent() { |
| 64 |
$mw = TestingAccessWrapper::newFromObject( $this->newEntryPoint() ); |
| 65 |
$mw->enableOutputCapture(); |
| 66 |
|
| 67 |
ob_start( null, 0, PHP_OUTPUT_HANDLER_STDFLAGS & ~PHP_OUTPUT_HANDLER_FLUSHABLE ); |
| 68 |
print 'Testing test'; |
| 69 |
|
| 70 |
$mw->enterPostSendMode(); |
| 71 |
|
| 72 |
$this->expectPHPError( |
| 73 |
E_USER_NOTICE, |
| 74 |
static function () use ( $mw ) { |
| 75 |
$mw->flushOutputBuffer(); |
| 76 |
} |
| 77 |
); |
| 78 |
|
| 79 |
$this->assertSame( '', $mw->drainOutputBuffer() ); |
| 80 |
} |
| 81 |
|
| 82 |
} |