mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(phpunit): Remove some more withConsecutive calls
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
9ccb70174c
commit
522be60ff0
8 changed files with 183 additions and 240 deletions
|
|
@ -45,7 +45,7 @@ class EnableTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function dataEnable() {
|
||||
public static function dataEnable(): array {
|
||||
return [
|
||||
['no', null, [], true, 'Encryption enabled', 'No encryption module is loaded'],
|
||||
['yes', null, [], false, 'Encryption is already enabled', 'No encryption module is loaded'],
|
||||
|
|
@ -57,15 +57,8 @@ class EnableTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataEnable
|
||||
*
|
||||
* @param string $oldStatus
|
||||
* @param string $defaultModule
|
||||
* @param array $availableModules
|
||||
* @param bool $isUpdating
|
||||
* @param string $expectedString
|
||||
* @param string $expectedDefaultModuleString
|
||||
*/
|
||||
public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpdating, $expectedString, $expectedDefaultModuleString): void {
|
||||
public function testEnable(string $oldStatus, ?string $defaultModule, array $availableModules, bool $isUpdating, string $expectedString, string $expectedDefaultModuleString): void {
|
||||
if ($isUpdating) {
|
||||
$this->config->expects($this->once())
|
||||
->method('setAppValue')
|
||||
|
|
@ -79,27 +72,30 @@ class EnableTest extends TestCase {
|
|||
if (empty($availableModules)) {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('core', 'encryption_enabled', $this->anything())
|
||||
->willReturn($oldStatus);
|
||||
->willReturnMap([
|
||||
['core', 'encryption_enabled', 'no', $oldStatus],
|
||||
]);
|
||||
} else {
|
||||
$this->config->expects($this->exactly(2))
|
||||
->method('getAppValue')
|
||||
->withConsecutive(
|
||||
['core', 'encryption_enabled', $this->anything()],
|
||||
['core', 'default_encryption_module', $this->anything()],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
$oldStatus,
|
||||
$defaultModule,
|
||||
);
|
||||
->willReturnMap([
|
||||
['core', 'encryption_enabled', 'no', $oldStatus],
|
||||
['core', 'default_encryption_module', null, $defaultModule],
|
||||
]);
|
||||
}
|
||||
|
||||
$calls = [
|
||||
[$expectedString, 0],
|
||||
['', 0],
|
||||
[$expectedDefaultModuleString, 0],
|
||||
];
|
||||
$this->consoleOutput->expects($this->exactly(3))
|
||||
->method('writeln')
|
||||
->withConsecutive(
|
||||
[$this->stringContains($expectedString)],
|
||||
[''],
|
||||
[$this->stringContains($expectedDefaultModuleString)],
|
||||
);
|
||||
->willReturnCallback(function (string $message, int $level) use (&$calls): void {
|
||||
$call = array_shift($calls);
|
||||
$this->assertStringContainsString($call[0], $message);
|
||||
$this->assertSame($call[1], $level);
|
||||
});
|
||||
|
||||
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class ManageTest extends TestCase {
|
|||
self::invokePrivate($this->command, 'validateTimezone', ['Mars/OlympusMons']);
|
||||
}
|
||||
|
||||
public function convertLevelStringProvider() {
|
||||
public static function dataConvertLevelString(): array {
|
||||
return [
|
||||
['dEbug', 0],
|
||||
['inFO', 1],
|
||||
|
|
@ -100,9 +100,9 @@ class ManageTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider convertLevelStringProvider
|
||||
* @dataProvider dataConvertLevelString
|
||||
*/
|
||||
public function testConvertLevelString($levelString, $expectedInt): void {
|
||||
public function testConvertLevelString(string $levelString, int $expectedInt): void {
|
||||
$this->assertEquals($expectedInt,
|
||||
self::invokePrivate($this->command, 'convertLevelString', [$levelString])
|
||||
);
|
||||
|
|
@ -115,7 +115,7 @@ class ManageTest extends TestCase {
|
|||
self::invokePrivate($this->command, 'convertLevelString', ['abc']);
|
||||
}
|
||||
|
||||
public function convertLevelNumberProvider() {
|
||||
public static function dataConvertLevelNumber(): array {
|
||||
return [
|
||||
[0, 'Debug'],
|
||||
[1, 'Info'],
|
||||
|
|
@ -126,9 +126,9 @@ class ManageTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider convertLevelNumberProvider
|
||||
* @dataProvider dataConvertLevelNumber
|
||||
*/
|
||||
public function testConvertLevelNumber($levelNum, $expectedString): void {
|
||||
public function testConvertLevelNumber(int $levelNum, string $expectedString): void {
|
||||
$this->assertEquals($expectedString,
|
||||
self::invokePrivate($this->command, 'convertLevelNumber', [$levelNum])
|
||||
);
|
||||
|
|
@ -144,23 +144,23 @@ class ManageTest extends TestCase {
|
|||
public function testGetConfiguration(): void {
|
||||
$this->config->expects($this->exactly(3))
|
||||
->method('getSystemValue')
|
||||
->withConsecutive(
|
||||
['log_type', 'file'],
|
||||
['loglevel', 2],
|
||||
['logtimezone', 'UTC'],
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
'log_type_value',
|
||||
0,
|
||||
'logtimezone_value'
|
||||
);
|
||||
->willReturnMap([
|
||||
['log_type', 'file', 'log_type_value'],
|
||||
['loglevel', 2, 0],
|
||||
['logtimezone', 'UTC', 'logtimezone_value'],
|
||||
]);
|
||||
|
||||
$calls = [
|
||||
['Enabled logging backend: log_type_value'],
|
||||
['Log level: Debug (0)'],
|
||||
['Log timezone: logtimezone_value'],
|
||||
];
|
||||
$this->consoleOutput->expects($this->exactly(3))
|
||||
->method('writeln')
|
||||
->withConsecutive(
|
||||
['Enabled logging backend: log_type_value'],
|
||||
['Log level: Debug (0)'],
|
||||
['Log timezone: logtimezone_value'],
|
||||
);
|
||||
->willReturnCallback(function (string $message) use (&$calls): void {
|
||||
$call = array_shift($calls);
|
||||
$this->assertStringContainsString($call[0], $message);
|
||||
});
|
||||
|
||||
self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ class DeleteTest extends TestCase {
|
|||
public function testDeleteTokenById(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', 42);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', '42']
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
@ -59,8 +61,10 @@ class DeleteTest extends TestCase {
|
|||
public function testDeleteTokenByIdRequiresTokenId(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', null);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', null]
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
@ -78,8 +82,10 @@ class DeleteTest extends TestCase {
|
|||
public function testDeleteTokensLastUsedBefore(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', null);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', null]
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
@ -97,8 +103,10 @@ class DeleteTest extends TestCase {
|
|||
public function testLastUsedBeforeAcceptsIso8601Expanded(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', null);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', null]
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
@ -116,8 +124,10 @@ class DeleteTest extends TestCase {
|
|||
public function testLastUsedBeforeAcceptsYmd(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', null);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', null]
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
@ -135,8 +145,10 @@ class DeleteTest extends TestCase {
|
|||
public function testIdAndLastUsedBeforeAreMutuallyExclusive(): void {
|
||||
$this->consoleInput->expects($this->exactly(2))
|
||||
->method('getArgument')
|
||||
->withConsecutive(['uid'], ['id'])
|
||||
->willReturnOnConsecutiveCalls('user', 42);
|
||||
->willReturnMap([
|
||||
['uid', 'user'],
|
||||
['id', '42']
|
||||
]);
|
||||
|
||||
$this->consoleInput->expects($this->once())
|
||||
->method('getOption')
|
||||
|
|
|
|||
|
|
@ -42,13 +42,14 @@ class NavigationControllerTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataGetNavigation() {
|
||||
public static function dataGetNavigation(): array {
|
||||
return [
|
||||
[false], [true]
|
||||
[false],
|
||||
[true],
|
||||
];
|
||||
}
|
||||
/** @dataProvider dataGetNavigation */
|
||||
public function testGetAppNavigation($absolute): void {
|
||||
public function testGetAppNavigation(bool $absolute): void {
|
||||
$this->navigationManager->expects($this->once())
|
||||
->method('getAll')
|
||||
->with('link')
|
||||
|
|
@ -59,11 +60,10 @@ class NavigationControllerTest extends TestCase {
|
|||
->willReturn('http://localhost/');
|
||||
$this->urlGenerator->expects($this->exactly(2))
|
||||
->method('getAbsoluteURL')
|
||||
->withConsecutive(['/index.php/apps/files'], ['icon'])
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'http://localhost/index.php/apps/files',
|
||||
'http://localhost/icon'
|
||||
);
|
||||
->willReturnMap([
|
||||
['/index.php/apps/files', 'http://localhost/index.php/apps/files'],
|
||||
['icon', 'http://localhost/icon'],
|
||||
]);
|
||||
$actual = $this->controller->getAppsNavigation($absolute);
|
||||
$this->assertInstanceOf(DataResponse::class, $actual);
|
||||
$this->assertEquals('http://localhost/index.php/apps/files', $actual->getData()[0]['href']);
|
||||
|
|
@ -77,7 +77,7 @@ class NavigationControllerTest extends TestCase {
|
|||
}
|
||||
|
||||
/** @dataProvider dataGetNavigation */
|
||||
public function testGetSettingsNavigation($absolute): void {
|
||||
public function testGetSettingsNavigation(bool $absolute): void {
|
||||
$this->navigationManager->expects($this->once())
|
||||
->method('getAll')
|
||||
->with('settings')
|
||||
|
|
@ -88,14 +88,10 @@ class NavigationControllerTest extends TestCase {
|
|||
->willReturn('http://localhost/');
|
||||
$this->urlGenerator->expects($this->exactly(2))
|
||||
->method('getAbsoluteURL')
|
||||
->withConsecutive(
|
||||
['/index.php/settings/user'],
|
||||
['/core/img/settings.svg']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'http://localhost/index.php/settings/user',
|
||||
'http://localhost/core/img/settings.svg'
|
||||
);
|
||||
->willReturnMap([
|
||||
['/index.php/settings/user', 'http://localhost/index.php/settings/user'],
|
||||
['/core/img/settings.svg', 'http://localhost/core/img/settings.svg']
|
||||
]);
|
||||
$actual = $this->controller->getSettingsNavigation($absolute);
|
||||
$this->assertInstanceOf(DataResponse::class, $actual);
|
||||
$this->assertEquals('http://localhost/index.php/settings/user', $actual->getData()[0]['href']);
|
||||
|
|
|
|||
|
|
@ -49,11 +49,7 @@ class RequestIdTest extends \Test\TestCase {
|
|||
$this->secureRandom->expects($this->once())
|
||||
->method('generate')
|
||||
->with('20')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
'GeneratedByNextcloudItself1',
|
||||
'GeneratedByNextcloudItself2',
|
||||
'GeneratedByNextcloudItself3'
|
||||
);
|
||||
->willReturn('GeneratedByNextcloudItself1');
|
||||
|
||||
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());
|
||||
$this->assertSame('GeneratedByNextcloudItself1', $requestId->getId());
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertSame('someothertestvalue', $result['propertyB']);
|
||||
}
|
||||
|
||||
public function notJsonDataProvider() {
|
||||
public static function dataNotJsonData(): array {
|
||||
return [
|
||||
['this is not valid json'],
|
||||
['"just a string"'],
|
||||
|
|
@ -260,9 +260,9 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider notJsonDataProvider
|
||||
* @dataProvider dataNotJsonData
|
||||
*/
|
||||
public function testNotJsonPost($testData): void {
|
||||
public function testNotJsonPost(string $testData): void {
|
||||
global $data;
|
||||
$data = $testData;
|
||||
$vars = [
|
||||
|
|
@ -544,7 +544,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertEquals('3', $request->getParams()['id']);
|
||||
}
|
||||
|
||||
public function dataGetRemoteAddress(): array {
|
||||
public static function dataGetRemoteAddress(): array {
|
||||
return [
|
||||
'IPv4 without trusted remote' => [
|
||||
[
|
||||
|
|
@ -714,14 +714,10 @@ class RequestTest extends \Test\TestCase {
|
|||
public function testGetRemoteAddress(array $headers, array $trustedProxies, array $forwardedForHeaders, string $expected): void {
|
||||
$this->config
|
||||
->method('getSystemValue')
|
||||
->withConsecutive(
|
||||
['trusted_proxies'],
|
||||
['forwarded_for_headers'],
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$trustedProxies,
|
||||
$forwardedForHeaders,
|
||||
);
|
||||
->willReturnMap([
|
||||
['trusted_proxies', [], $trustedProxies],
|
||||
['forwarded_for_headers', ['HTTP_X_FORWARDED_FOR'], $forwardedForHeaders],
|
||||
]);
|
||||
|
||||
$request = new Request(
|
||||
[
|
||||
|
|
@ -736,10 +732,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertSame($expected, $request->getRemoteAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function httpProtocolProvider() {
|
||||
public static function dataHttpProtocol(): array {
|
||||
return [
|
||||
// Valid HTTP 1.0
|
||||
['HTTP/1.0', 'HTTP/1.0'],
|
||||
|
|
@ -766,7 +759,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider httpProtocolProvider
|
||||
* @dataProvider dataHttpProtocol
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string $expected
|
||||
|
|
@ -956,7 +949,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider userAgentProvider
|
||||
* @dataProvider dataUserAgent
|
||||
* @param string $testAgent
|
||||
* @param array $userAgent
|
||||
* @param bool $matches
|
||||
|
|
@ -978,7 +971,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider userAgentProvider
|
||||
* @dataProvider dataUserAgent
|
||||
* @param string $testAgent
|
||||
* @param array $userAgent
|
||||
* @param bool $matches
|
||||
|
|
@ -995,10 +988,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertFalse($request->isUserAgent($userAgent));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function userAgentProvider() {
|
||||
public static function dataUserAgent(): array {
|
||||
return [
|
||||
[
|
||||
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
|
||||
|
|
@ -1117,7 +1107,7 @@ class RequestTest extends \Test\TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
public function dataMatchClientVersion(): array {
|
||||
public static function dataMatchClientVersion(): array {
|
||||
return [
|
||||
[
|
||||
'Mozilla/5.0 (Android) Nextcloud-android/3.24.1',
|
||||
|
|
@ -1373,10 +1363,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertSame('', $request->getServerHost());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataGetServerHostTrustedDomain() {
|
||||
public static function dataGetServerHostTrustedDomain(): array {
|
||||
return [
|
||||
'is array' => ['my.trusted.host', ['my.trusted.host']],
|
||||
'is array but undefined index 0' => ['my.trusted.host', [2 => 'my.trusted.host']],
|
||||
|
|
@ -1387,10 +1374,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataGetServerHostTrustedDomain
|
||||
* @param $expected
|
||||
* @param $trustedDomain
|
||||
*/
|
||||
public function testGetServerHostTrustedDomain($expected, $trustedDomain): void {
|
||||
public function testGetServerHostTrustedDomain(string $expected, $trustedDomain): void {
|
||||
$this->config
|
||||
->method('getSystemValue')
|
||||
->willReturnCallback(function ($key, $default) use ($trustedDomain) {
|
||||
|
|
@ -1499,7 +1484,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider genericPathInfoProvider
|
||||
* @dataProvider dataGenericPathInfo
|
||||
* @param string $requestUri
|
||||
* @param string $scriptName
|
||||
* @param string $expected
|
||||
|
|
@ -1522,7 +1507,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider genericPathInfoProvider
|
||||
* @dataProvider dataGenericPathInfo
|
||||
* @param string $requestUri
|
||||
* @param string $scriptName
|
||||
* @param string $expected
|
||||
|
|
@ -1545,7 +1530,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider rawPathInfoProvider
|
||||
* @dataProvider dataRawPathInfo
|
||||
* @param string $requestUri
|
||||
* @param string $scriptName
|
||||
* @param string $expected
|
||||
|
|
@ -1568,7 +1553,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider pathInfoProvider
|
||||
* @dataProvider dataPathInfo
|
||||
* @param string $requestUri
|
||||
* @param string $scriptName
|
||||
* @param string $expected
|
||||
|
|
@ -1590,10 +1575,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertSame($expected, $request->getPathInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function genericPathInfoProvider() {
|
||||
public static function dataGenericPathInfo(): array {
|
||||
return [
|
||||
['/core/index.php?XDEBUG_SESSION_START=14600', '/core/index.php', ''],
|
||||
['/index.php/apps/files/', 'index.php', '/apps/files/'],
|
||||
|
|
@ -1605,19 +1587,13 @@ class RequestTest extends \Test\TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rawPathInfoProvider() {
|
||||
public static function dataRawPathInfo(): array {
|
||||
return [
|
||||
['/foo%2Fbar/subfolder', '', 'foo%2Fbar/subfolder'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function pathInfoProvider() {
|
||||
public static function dataPathInfo(): array {
|
||||
return [
|
||||
['/foo%2Fbar/subfolder', '', 'foo/bar/subfolder'],
|
||||
];
|
||||
|
|
@ -1645,7 +1621,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertSame('/test.php', $request->getRequestUri());
|
||||
}
|
||||
|
||||
public function providesGetRequestUriWithOverwriteData() {
|
||||
public static function dataGetRequestUriWithOverwrite(): array {
|
||||
return [
|
||||
['/scriptname.php/some/PathInfo', '/owncloud/', ''],
|
||||
['/scriptname.php/some/PathInfo', '/owncloud/', '123', '123.123.123.123'],
|
||||
|
|
@ -1653,7 +1629,7 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesGetRequestUriWithOverwriteData
|
||||
* @dataProvider dataGetRequestUriWithOverwrite
|
||||
*/
|
||||
public function testGetRequestUriWithOverwrite($expectedUri, $overwriteWebRoot, $overwriteCondAddr, $remoteAddr = ''): void {
|
||||
$this->config
|
||||
|
|
@ -1665,7 +1641,7 @@ class RequestTest extends \Test\TestCase {
|
|||
]);
|
||||
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->setMethods(['getScriptName'])
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1690,8 +1666,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithGet(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'get' => [
|
||||
|
|
@ -1720,8 +1696,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithPost(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'post' => [
|
||||
|
|
@ -1750,8 +1726,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithHeader(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1780,8 +1756,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithGetAndWithoutCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'get' => [
|
||||
|
|
@ -1804,8 +1780,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithPostAndWithoutCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'post' => [
|
||||
|
|
@ -1828,8 +1804,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithHeaderAndWithoutCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1852,8 +1828,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1879,8 +1855,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesStrictCookieCheckWithAllCookiesAndStrict(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName', 'getCookieParams'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName', 'getCookieParams'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1911,8 +1887,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsStrictCookieCheckWithAllCookiesAndMissingStrict(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName', 'getCookieParams'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName', 'getCookieParams'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1944,7 +1920,7 @@ class RequestTest extends \Test\TestCase {
|
|||
public function testGetCookieParams(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->setMethods(['getScriptName'])
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[],
|
||||
$this->requestId,
|
||||
|
|
@ -1959,8 +1935,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesStrictCookieCheckWithAllCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -1984,8 +1960,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesStrictCookieCheckWithRandomCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2007,8 +1983,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsStrictCookieCheckWithSessionCookie(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2030,8 +2006,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsStrictCookieCheckWithRememberMeCookie(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2053,8 +2029,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsCSRFCheckWithPostAndWithCookies(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'post' => [
|
||||
|
|
@ -2080,8 +2056,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailStrictCookieCheckWithOnlyLaxCookie(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2104,8 +2080,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailStrictCookieCheckWithOnlyStrictCookie(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2128,8 +2104,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesLaxCookieCheck(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2152,8 +2128,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testFailsLaxCookieCheckWithOnlyStrictCookie(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2176,8 +2152,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testSkipCookieCheckForOCSRequests(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2199,10 +2175,7 @@ class RequestTest extends \Test\TestCase {
|
|||
$this->assertTrue($request->passesStrictCookieCheck());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function invalidTokenDataProvider() {
|
||||
public static function dataInvalidToken(): array {
|
||||
return [
|
||||
['InvalidSentToken'],
|
||||
['InvalidSentToken:InvalidSecret'],
|
||||
|
|
@ -2211,13 +2184,12 @@ class RequestTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidTokenDataProvider
|
||||
* @param string $invalidToken
|
||||
* @dataProvider dataInvalidToken
|
||||
*/
|
||||
public function testPassesCSRFCheckWithInvalidToken($invalidToken): void {
|
||||
public function testPassesCSRFCheckWithInvalidToken(string $invalidToken): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
@ -2243,8 +2215,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithoutTokenFail(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[],
|
||||
$this->requestId,
|
||||
|
|
@ -2259,8 +2231,8 @@ class RequestTest extends \Test\TestCase {
|
|||
|
||||
public function testPassesCSRFCheckWithOCSAPIRequestHeader(): void {
|
||||
/** @var Request $request */
|
||||
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
|
||||
->setMethods(['getScriptName'])
|
||||
$request = $this->getMockBuilder(Request::class)
|
||||
->onlyMethods(['getScriptName'])
|
||||
->setConstructorArgs([
|
||||
[
|
||||
'server' => [
|
||||
|
|
|
|||
|
|
@ -70,14 +70,10 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
$this->config
|
||||
->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->withConsecutive(
|
||||
['debug'],
|
||||
['installed']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
false
|
||||
);
|
||||
->willReturnMap([
|
||||
['debug', false],
|
||||
['installed', false]
|
||||
]);
|
||||
|
||||
$actual = $this->jsCombiner->process(__DIR__, '/data/combine.json', 'awesomeapp');
|
||||
$this->assertFalse($actual);
|
||||
|
|
@ -87,14 +83,10 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
$this->config
|
||||
->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->withConsecutive(
|
||||
['debug'],
|
||||
['installed']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
true
|
||||
);
|
||||
->willReturnMap([
|
||||
['debug', '', false],
|
||||
['installed', '', true],
|
||||
]);
|
||||
$folder = $this->createMock(ISimpleFolder::class);
|
||||
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willThrowException(new NotFoundException());
|
||||
$this->appData->expects($this->once())->method('newFolder')->with('awesomeapp')->willReturn($folder);
|
||||
|
|
@ -127,14 +119,10 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
$this->config
|
||||
->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->withConsecutive(
|
||||
['debug'],
|
||||
['installed']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
true
|
||||
);
|
||||
->willReturnMap([
|
||||
['debug', '', false],
|
||||
['installed', '', true],
|
||||
]);
|
||||
$folder = $this->createMock(ISimpleFolder::class);
|
||||
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder);
|
||||
$file = $this->createMock(ISimpleFile::class);
|
||||
|
|
@ -165,14 +153,10 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
$this->config
|
||||
->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->withConsecutive(
|
||||
['debug'],
|
||||
['installed']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
true
|
||||
);
|
||||
->willReturnMap([
|
||||
['debug', '', false],
|
||||
['installed', '', true],
|
||||
]);
|
||||
$folder = $this->createMock(ISimpleFolder::class);
|
||||
$this->appData->expects($this->once())->method('getFolder')->with('awesomeapp')->willReturn($folder);
|
||||
$file = $this->createMock(ISimpleFile::class);
|
||||
|
|
@ -206,14 +190,10 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
$this->config
|
||||
->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->withConsecutive(
|
||||
['debug'],
|
||||
['installed']
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
false,
|
||||
true
|
||||
);
|
||||
->willReturnMap([
|
||||
['debug', '', false],
|
||||
['installed', '', true],
|
||||
]);
|
||||
$folder = $this->createMock(ISimpleFolder::class);
|
||||
$this->appData->expects($this->once())
|
||||
->method('getFolder')
|
||||
|
|
@ -395,15 +375,11 @@ class JSCombinerTest extends \Test\TestCase {
|
|||
|
||||
$folder->expects($this->exactly(3))
|
||||
->method('getFile')
|
||||
->withConsecutive(
|
||||
[$fileName],
|
||||
[$fileName . '.deps'],
|
||||
[$fileName . '.gzip']
|
||||
)->willReturnOnConsecutiveCalls(
|
||||
$file,
|
||||
$depsFile,
|
||||
$gzFile
|
||||
);
|
||||
->willReturnMap([
|
||||
[$fileName, $file],
|
||||
[$fileName . '.deps', $depsFile],
|
||||
[$fileName . '.gzip', $gzFile]
|
||||
]);
|
||||
|
||||
$file->expects($this->once())
|
||||
->method('putContent')
|
||||
|
|
@ -484,7 +460,7 @@ var b = \'world\';
|
|||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
public function dataGetCachedSCSS() {
|
||||
public static function dataGetCachedSCSS(): array {
|
||||
return [
|
||||
['awesomeapp', 'core/js/foo.json', '/js/core/foo.js'],
|
||||
['files', 'apps/files/js/foo.json', '/js/files/foo.js']
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ class ManagerTest extends TestCase {
|
|||
$this->assertEquals('foo3', array_shift($result)->getUID());
|
||||
}
|
||||
|
||||
public function dataCreateUserInvalid() {
|
||||
public static function dataCreateUserInvalid(): array {
|
||||
return [
|
||||
['te?st', 'foo', 'Only the following characters are allowed in a username:'
|
||||
. ' "a-z", "A-Z", "0-9", spaces and "_.@-\'"'],
|
||||
|
|
@ -760,16 +760,11 @@ class ManagerTest extends TestCase {
|
|||
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
||||
$backend->expects($this->exactly(3))
|
||||
->method('userExists')
|
||||
->withConsecutive(
|
||||
[$this->equalTo('uid1')],
|
||||
[$this->equalTo('uid99')],
|
||||
[$this->equalTo('uid2')]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
->willReturnMap([
|
||||
['uid1', true],
|
||||
['uid99', false],
|
||||
['uid2', true]
|
||||
]);
|
||||
|
||||
$manager = new \OC\User\Manager($config, $this->cacheFactory, $this->eventDispatcher, $this->logger);
|
||||
$manager->registerBackend($backend);
|
||||
|
|
|
|||
Loading…
Reference in a new issue