wiki.techinc.nl/tests/phpunit/unit/includes/shell/ShellboxClientFactoryTest.php
Amir Sarabadani 50888be5f4 Add support for multiple shellbox URLs through a mapping configuration
In order to avoid major disruptions, I introduced default value to
fallback to but in longer term we probably should deprecated it.

Bug: T285105
Change-Id: I81d9ece769c4942ef2ca390a40ff9d2c24c9ece4
2021-06-21 14:14:44 +02:00

84 lines
2 KiB
PHP

<?php
use MediaWiki\Http\HttpRequestFactory;
use MediaWiki\Shell\ShellboxClientFactory;
/**
* @group Shell
* @covers MediaWiki\Shell\ShellboxClientFactory
*/
class ShellboxClientFactoryTest extends MediaWikiUnitTestCase {
/** @dataProvider provideEnabledArgs */
public function testIsEnabled( ?array $urls, ?string $service, bool $expected ): void {
$shellboxClientFactory = new ShellboxClientFactory(
$this->createMock( HttpRequestFactory::class ),
$urls,
'key'
);
$actual = $shellboxClientFactory->isEnabled( $service );
$this->assertSame( $expected, $actual );
}
public function provideEnabledArgs(): iterable {
yield 'not configured, default service' => [
'urls' => null,
'service' => null,
'expected' => false,
];
yield 'not configured, custom service' => [
'urls' => null,
'service' => 'custom',
'expected' => false,
];
yield 'default configured, default service' => [
'urls' => [ 'default' => 'http://example.com' ],
'service' => null,
'expected' => true,
];
yield 'default configured, custom service' => [
'urls' => [ 'default' => 'http://example.com' ],
'service' => 'custom',
'expected' => true,
];
yield 'custom configured, custom service' => [
'urls' => [ 'custom' => 'http://example.com' ],
'service' => 'custom',
'expected' => true,
];
yield 'custom disabled, default service' => [
'urls' => [
'default' => 'http://example.com',
'custom' => false,
],
'service' => 'default',
'expected' => true,
];
yield 'custom disabled, custom service' => [
'urls' => [
'default' => 'http://example.com',
'custom' => false,
],
'service' => 'custom',
'expected' => false,
];
}
public function testIsEnabledWithoutKey(): void {
$shellboxClientFactory = new ShellboxClientFactory(
$this->createMock( HttpRequestFactory::class ),
[ 'default' => 'http://example.com' ],
null
);
$this->assertFalse( $shellboxClientFactory->isEnabled() );
}
}