wiki.techinc.nl/tests/phpunit/includes/filebackend/FileBackendStoreTest.php
Tim Starling ae994ff6ff filebackend: Refactor FileBackendIntegrationTest
FileBackendIntegrationTest was running tests against different backends
in an unconventional way, using a combination of wrapper test cases that
run tests against two different classes, and CLI options which don't
really exist anymore and have an associated fixme.

So:
* Move the bulk of FileBackendIntegrationTest to a new abstract base
  class under tests/phpunit/integration.
* Add subclasses for the FS and multiwrite test cases. This allows us to
  eliminate the wrappers.
* Add a subclass for MemoryFileBackend.
* Add a Swift subclass which replaces the main use case for
  the CLI option --use-filebackend. It is automatically enabled when
  a Swift backend is configured, similar to PostgreSQL tests.
* Some miscellaneous tests with a medium level of integration, not
  requiring backend setup and teardown, were moved to new classes
  FileBackendMultiWriteTest and FileBackendStoreTest.

Change-Id: I0da531349d7627970a7bcb34f3c1f5fd7e05cb21
2024-03-14 20:27:25 +00:00

79 lines
2.2 KiB
PHP

<?php
namespace phpunit\includes\filebackend;
use FileBackend;
use MediaWikiIntegrationTestCase;
use MemoryFileBackend;
use Wikimedia\TestingAccessWrapper;
/**
* @covers \FileBackendStore
*/
class FileBackendStoreTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provider_testGetContentType
*/
public function testGetContentType( $mimeFromString ) {
global $IP;
if ( $mimeFromString ) {
$mimeCallback = [ $this->getServiceContainer()->getFileBackendGroup(), 'guessMimeInternal' ];
} else {
$mimeCallback = null;
}
$be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [
'name' => 'testing',
'class' => MemoryFileBackend::class,
'wikiId' => 'meow',
'mimeCallback' => $mimeCallback,
] ) );
$dst = 'mwstore://testing/container/path/to/file_no_ext';
$src = "$IP/tests/phpunit/data/media/srgb.jpg";
$this->assertEquals( 'image/jpeg', $be->getContentType( $dst, null, $src ) );
$this->assertEquals( $mimeFromString ? 'image/jpeg' : 'unknown/unknown',
$be->getContentType( $dst, file_get_contents( $src ), null ) );
$src = "$IP/tests/phpunit/data/media/Png-native-test.png";
$this->assertEquals( 'image/png', $be->getContentType( $dst, null, $src ) );
$this->assertEquals( $mimeFromString ? 'image/png' : 'unknown/unknown',
$be->getContentType( $dst, file_get_contents( $src ), null ) );
}
public static function provider_testGetContentType() {
return [
[ false ],
[ true ],
];
}
public function testSanitizeOpHeaders() {
$be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [
'name' => 'localtesting',
'wikiId' => 'wikidb',
] ) );
$input = [
'headers' => [
'content-Disposition' => FileBackend::makeContentDisposition( 'inline', 'name' ),
'Content-dUration' => 25.6,
'X-LONG-VALUE' => str_pad( '0', 300 ),
'CONTENT-LENGTH' => 855055,
],
];
$expected = [
'headers' => [
'content-disposition' => FileBackend::makeContentDisposition( 'inline', 'name' ),
'content-duration' => 25.6,
'content-length' => 855055,
],
];
$actual = @$be->sanitizeOpHeaders( $input );
$this->assertEquals( $expected, $actual, "Header sanitized properly" );
}
}