wiki.techinc.nl/tests/phpunit/includes/externalstore/ExternalStoreTest.php
Aaron Schulz baafb5adb4 Make ExternalStore wrap ExternalStoreFactory and create access class
* Inject settings and global instances as dependencies to the
  ExternalStoreMedium instances. This includes the local wiki
  domain, so that wfWikiId() calls are not scattered around.
* Create ExternalStoreAccess service for read/write logic.
* Deprecate the ExternalStore wrapper methods.
* Add some exception cases for bogus store URLs are used instead
  of just giving PHP warnings and failing later.
* Make moveToExternal.php require the type/protocol to decide
  which ExternalStoreMedium to use instead of assuming "DB".
* Convert logging calls to use LoggerInterface.

Change-Id: I40c3b5534fc8a31116c4c5eb64ee6e4903a6197a
2019-06-28 14:31:44 -07:00

53 lines
1.3 KiB
PHP

<?php
class ExternalStoreTest extends MediaWikiTestCase {
/**
* @covers ExternalStore::fetchFromURL
*/
public function testExternalFetchFromURL_noExternalStores() {
$this->setService(
'ExternalStoreFactory',
new ExternalStoreFactory( [], [], 'test-id' )
);
$this->assertFalse(
ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
'Deny if wgExternalStores is not set to a non-empty array'
);
}
/**
* @covers ExternalStore::fetchFromURL
*/
public function testExternalFetchFromURL_someExternalStore() {
$this->setService(
'ExternalStoreFactory',
new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
);
$this->assertEquals(
'Hello',
ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
'Allow FOO://cluster1/200'
);
$this->assertEquals(
'Hello',
ExternalStore::fetchFromURL( 'ForTesting://cluster1/300/0' ),
'Allow FOO://cluster1/300/0'
);
# Assertions for r68900
$this->assertFalse(
ExternalStore::fetchFromURL( 'ftp.example.org' ),
'Deny domain ftp.example.org'
);
$this->assertFalse(
ExternalStore::fetchFromURL( '/example.txt' ),
'Deny path /example.txt'
);
$this->assertFalse(
ExternalStore::fetchFromURL( 'http://' ),
'Deny protocol http://'
);
}
}