From: Aaron Schulz Date: Tue, 17 Dec 2013 08:06:14 +0000 (-0800) Subject: Added streamFile() unit tests X-Git-Tag: 1.31.0-rc.0~17597^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=976084767225e55a4bdf46378edca1086a02ea7b;p=lhc%2Fweb%2Fwiklou.git Added streamFile() unit tests Change-Id: I2ef5680829048ab4fcc0a9f7ff9064d016800217 --- diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index 072cb7c524..13c906f2fc 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -1114,6 +1114,57 @@ class FileBackendTest extends MediaWikiTestCase { return $cases; } + /** + * @dataProvider provider_testGetFileStat + * @covers FileBackend::streamFile + */ + public function testStreamFile( $path, $content, $alreadyExists ) { + $this->backend = $this->singleBackend; + $this->tearDownFiles(); + $this->doTestStreamFile( $path, $content, $alreadyExists ); + $this->tearDownFiles(); + } + + private function doTestStreamFile( $path, $content ) { + $backendName = $this->backendClass(); + + // Test doStreamFile() directly to avoid header madness + $class = new ReflectionClass( $this->backend ); + $method = $class->getMethod( 'doStreamFile' ); + $method->setAccessible( true ); + + if ( $content !== null ) { + $this->prepare( array( 'dir' => dirname( $path ) ) ); + $status = $this->create( array( 'dst' => $path, 'content' => $content ) ); + $this->assertGoodStatus( $status, + "Creation of file at $path succeeded ($backendName)." ); + + ob_start(); + $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) ); + $data = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals( $content, $data, "Correct content streamed from '$path'" ); + } else { // 404 case + ob_start(); + $method->invokeArgs( $this->backend, array( array( 'src' => $path ) ) ); + $data = ob_get_contents(); + ob_end_clean(); + + $this->assertEquals( '', $data, "Correct content streamed from '$path' ($backendName)" ); + } + } + + public static function provider_testStreamFile() { + $cases = array(); + + $base = self::baseStorePath(); + $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" ); + $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", null ); + + return $cases; + } + /** * @dataProvider provider_testGetFileContents * @covers FileBackend::getFileContents