Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -254,12 +255,18 @@ public function doTestAddShare($shareData1, $isGroup = false) {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}');
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');

$newClientCalls = [];
$this->clientService
->method('newClient')
->willReturnCallback(function () use (&$newClientCalls): IClient {
if (!empty($newClientCalls)) {
return array_shift($newClientCalls);
}
return $this->createMock(IClient::class);
});
if (!$isGroup) {
$client = $this->getMockBuilder('OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$this->clientService->expects($this->at(0))
->method('newClient')
->willReturn($client);
$client = $this->createMock(IClient::class);
$newClientCalls[] = $client;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
Expand Down Expand Up @@ -311,11 +318,8 @@ public function doTestAddShare($shareData1, $isGroup = false) {
$this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1');

if (!$isGroup) {
$client = $this->getMockBuilder('OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$this->clientService->expects($this->at(0))
->method('newClient')
->willReturn($client);
$client = $this->createMock(IClient::class);
$newClientCalls[] = $client;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
Expand Down Expand Up @@ -367,16 +371,10 @@ public function doTestAddShare($shareData1, $isGroup = false) {
// no http requests here
$this->manager->removeGroupShares('group1');
} else {
$client1 = $this->getMockBuilder('OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$client2 = $this->getMockBuilder('OCP\Http\Client\IClient')
->disableOriginalConstructor()->getMock();
$this->clientService->expects($this->exactly(2))
->method('newClient')
->willReturnOnConsecutiveCalls(
$client1,
$client2,
);
$client1 = $this->createMock(IClient::class);
$client2 = $this->createMock(IClient::class);
$newClientCalls[] = $client1;
$newClientCalls[] = $client2;
$response = $this->createMock(IResponse::class);
$response->method('getBody')
->willReturn(json_encode([
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Command/Config/App/SetConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp(): void {
}


public function setData() {
public static function dataSet() {
return [
[
'name',
Expand All @@ -63,7 +63,7 @@ public function setData() {
}

/**
* @dataProvider setData
* @dataProvider dataSet
*
* @param string $configName
* @param mixed $newValue
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Command/Config/System/SetConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp(): void {
}


public function setData() {
public static function dataTest() {
return [
[['name'], 'newvalue', null, 'newvalue'],
[['a', 'b', 'c'], 'foobar', null, ['b' => ['c' => 'foobar']]],
Expand All @@ -48,7 +48,7 @@ public function setData() {
}

/**
* @dataProvider setData
* @dataProvider dataTest
*
* @param array $configNames
* @param string $newValue
Expand Down
42 changes: 19 additions & 23 deletions tests/Core/Command/Encryption/EnableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function setUp(): void {
}


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'],
Expand All @@ -57,15 +57,8 @@ public function dataEnable() {

/**
* @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')
Expand All @@ -79,27 +72,30 @@ public function testEnable($oldStatus, $defaultModule, $availableModules, $isUpd
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]);
}
Expand Down
40 changes: 20 additions & 20 deletions tests/Core/Command/Log/ManageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testValidateTimezone(): void {
self::invokePrivate($this->command, 'validateTimezone', ['Mars/OlympusMons']);
}

public function convertLevelStringProvider() {
public static function dataConvertLevelString(): array {
return [
['dEbug', 0],
['inFO', 1],
Expand All @@ -100,9 +100,9 @@ public function convertLevelStringProvider() {
}

/**
* @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])
);
Expand All @@ -115,7 +115,7 @@ public function testConvertLevelStringInvalid(): void {
self::invokePrivate($this->command, 'convertLevelString', ['abc']);
}

public function convertLevelNumberProvider() {
public static function dataConvertLevelNumber(): array {
return [
[0, 'Debug'],
[1, 'Info'],
Expand All @@ -126,9 +126,9 @@ public function convertLevelNumberProvider() {
}

/**
* @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])
);
Expand All @@ -144,23 +144,23 @@ public function testConvertLevelNumberInvalid(): void {
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]);
}
Expand Down
36 changes: 24 additions & 12 deletions tests/Core/Command/User/AuthTokens/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ protected function setUp(): void {
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')
Expand All @@ -59,8 +61,10 @@ public function testDeleteTokenById(): void {
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')
Expand All @@ -78,8 +82,10 @@ public function testDeleteTokenByIdRequiresTokenId(): void {
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')
Expand All @@ -97,8 +103,10 @@ public function testDeleteTokensLastUsedBefore(): void {
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')
Expand All @@ -116,8 +124,10 @@ public function testLastUsedBeforeAcceptsIso8601Expanded(): void {
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')
Expand All @@ -135,8 +145,10 @@ public function testLastUsedBeforeAcceptsYmd(): void {
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')
Expand Down
30 changes: 13 additions & 17 deletions tests/Core/Controller/NavigationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ protected function setUp(): void {
);
}

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')
Expand All @@ -59,11 +60,10 @@ public function testGetAppNavigation($absolute): void {
->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']);
Expand All @@ -77,7 +77,7 @@ public function testGetAppNavigation($absolute): void {
}

/** @dataProvider dataGetNavigation */
public function testGetSettingsNavigation($absolute): void {
public function testGetSettingsNavigation(bool $absolute): void {
$this->navigationManager->expects($this->once())
->method('getAll')
->with('settings')
Expand All @@ -88,14 +88,10 @@ public function testGetSettingsNavigation($absolute): void {
->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']);
Expand Down
Loading
Loading