diff options
Diffstat (limited to 'tests')
56 files changed, 972 insertions, 294 deletions
diff --git a/tests/Core/Command/SystemTag/AddTest.php b/tests/Core/Command/SystemTag/AddTest.php new file mode 100644 index 00000000000..c875c8f3ec3 --- /dev/null +++ b/tests/Core/Command/SystemTag/AddTest.php @@ -0,0 +1,138 @@ +<?php +/** + * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de> + * + * @author Johannes Leuker <developers@hosting.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Core\Command\SystemTag; + +use OC\Core\Command\SystemTag\Add; +use OCP\SystemTag\ISystemTag; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\TagAlreadyExistsException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; + +class AddTest extends TestCase { + + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ + private $systemTagManager; + + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ + private $command; + + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $input; + + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $output; + + protected function setUp(): void { + parent::setUp(); + + $this->systemTagManager = $this->createMock(ISystemTagManager::class); + $this->command = $this->getMockBuilder(Add::class) + ->setConstructorArgs([$this->systemTagManager]) + ->setMethods(['writeArrayInOutputFormat']) + ->getMock(); + + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testExecute() { + $tagId = '42'; + $tagName = 'wichtig'; + $tagAccess = 'public'; + + $tag = $this->createMock(ISystemTag::class); + $tag->method('getId')->willReturn($tagId); + $tag->method('getName')->willReturn($tagName); + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); + + $this->systemTagManager->method('createTag') + ->with( + $tagName, + true, + true + )->willReturn($tag); + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { + if ($arg === 'name') { + return $tagName; + } elseif ($arg === 'access') { + return $tagAccess; + } + throw new \Exception(); + }); + + $this->command->expects($this->once()) + ->method('writeArrayInOutputFormat') + ->with( + $this->equalTo($this->input), + $this->equalTo($this->output), + [ + 'id' => $tagId, + 'name' => $tagName, + 'access' => $tagAccess, + ] + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } + + public function testAlreadyExists() { + $tagId = '42'; + $tagName = 'wichtig'; + $tagAccess = 'public'; + + $tag = $this->createMock(ISystemTag::class); + $tag->method('getId')->willReturn($tagId); + $tag->method('getName')->willReturn($tagName); + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); + + $this->systemTagManager->method('createTag') + ->willReturnCallback(function ($tagName, $userVisible, $userAssignable) { + throw new TagAlreadyExistsException( + 'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists' + ); + }); + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) { + if ($arg === 'name') { + return $tagName; + } elseif ($arg === 'access') { + return $tagAccess; + } + throw new \Exception(); + }); + + $this->output->expects($this->once()) + ->method('writeln') + ->with( + '<error>Tag ("wichtig", 1, 1) already exists</error>' + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } +} diff --git a/tests/Core/Command/SystemTag/DeleteTest.php b/tests/Core/Command/SystemTag/DeleteTest.php new file mode 100644 index 00000000000..138606049ee --- /dev/null +++ b/tests/Core/Command/SystemTag/DeleteTest.php @@ -0,0 +1,100 @@ +<?php +/** + * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de> + * + * @author Johannes Leuker <developers@hosting.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Core\Command\SystemTag; + +use OC\Core\Command\SystemTag\Delete; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\TagNotFoundException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; + +class DeleteTest extends TestCase { + + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ + private $systemTagManager; + + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ + private $command; + + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $input; + + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $output; + + protected function setUp(): void { + parent::setUp(); + + $this->systemTagManager = $this->createMock(ISystemTagManager::class); + $this->command = $this->getMockBuilder(Delete::class) + ->setConstructorArgs([$this->systemTagManager]) + ->setMethods(['writeArrayInOutputFormat']) + ->getMock(); + + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testExecute() { + $tagId = 69; + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagId) { + if ($arg === 'id') { + return $tagId; + } + throw new \Exception(); + }); + + $this->output->expects($this->once()) + ->method('writeln') + ->with('<info>The specified tag was deleted</info>'); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } + + public function testNotFound() { + $tagId = 69; + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagId) { + if ($arg === 'id') { + return $tagId; + } + throw new \Exception(); + }); + + $this->systemTagManager->method('deleteTags') + ->willReturnCallback(function ($tagId) { + throw new TagNotFoundException(); + }); + + $this->output->expects($this->once()) + ->method('writeln') + ->with('<error>Tag not found</error>'); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } +} diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php new file mode 100644 index 00000000000..7794ac5aefd --- /dev/null +++ b/tests/Core/Command/SystemTag/EditTest.php @@ -0,0 +1,201 @@ +<?php +/** + * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de> + * + * @author Johannes Leuker <developers@hosting.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Core\Command\SystemTag; + +use OC\Core\Command\SystemTag\Edit; +use OCP\SystemTag\ISystemTag; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\TagAlreadyExistsException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; + +class EditTest extends TestCase { + + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ + private $systemTagManager; + + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ + private $command; + + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $input; + + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $output; + + protected function setUp(): void { + parent::setUp(); + + $this->systemTagManager = $this->createMock(ISystemTagManager::class); + $this->command = $this->getMockBuilder(Edit::class) + ->setConstructorArgs([$this->systemTagManager]) + ->setMethods(['writeArrayInOutputFormat']) + ->getMock(); + + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testExecute() { + $tagId = '5'; + $tagName = 'unwichtige Dateien'; + $newTagName = 'moderat wichtige Dateien'; + $newTagAccess = 'restricted'; + $newTagUserVisible = true; + $newTagUserAssignable = false; + + $tag = $this->createMock(ISystemTag::class); + $tag->method('getId')->willReturn($tagId); + $tag->method('getName')->willReturn($tagName); + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); + + $this->systemTagManager->method('getTagsByIds') + ->with($tagId) + ->willReturn([$tag]); + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagId) { + if ($arg === 'id') { + return $tagId; + } + throw new \Exception(); + }); + + $this->input->method('getOption') + ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { + if ($arg === 'name') { + return $newTagName; + } elseif ($arg === 'access') { + return $newTagAccess; + } + throw new \Exception(); + }); + + $this->systemTagManager->expects($this->once()) + ->method('updateTag') + ->with( + $tagId, + $newTagName, + $newTagUserVisible, + $newTagUserAssignable + ); + + $this->output->expects($this->once()) + ->method('writeln') + ->with( + '<info>Tag updated ("'.$newTagName.'", '.$newTagUserVisible.', '.$newTagUserAssignable.')</info>' + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } + + public function testAlreadyExists() { + $tagId = '5'; + $tagName = 'unwichtige Dateien'; + $tagUserVisible = false; + $tagUserAssignable = false; + $newTagName = 'moderat wichtige Dateien'; + $newTagAccess = 'restricted'; + $newTagUserVisible = true; + $newTagUserAssignable = false; + + $tag = $this->createMock(ISystemTag::class); + $tag->method('getId')->willReturn($tagId); + $tag->method('getName')->willReturn($tagName); + $tag->method('isUserVisible')->willReturn($tagUserVisible); + $tag->method('isUserAssignable')->willReturn($tagUserAssignable); + $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); + + $this->systemTagManager->method('getTagsByIds') + ->with($tagId) + ->willReturn([$tag]); + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagId) { + if ($arg === 'id') { + return $tagId; + } + throw new \Exception(); + }); + + $this->input->method('getOption') + ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) { + if ($arg === 'name') { + return $newTagName; + } elseif ($arg === 'access') { + return $newTagAccess; + } + throw new \Exception(); + }); + + $this->systemTagManager->method('updateTag') + ->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable) { + throw new TagAlreadyExistsException( + 'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists' + ); + }); + + $this->systemTagManager->expects($this->once()) + ->method('updateTag') + ->with( + $tagId, + $newTagName, + $newTagUserVisible, + $newTagUserAssignable + ); + + $this->output->expects($this->once()) + ->method('writeln') + ->with( + '<error>Tag ("' . $newTagName . '", '. $newTagUserVisible . ', ' . $newTagUserAssignable . ') already exists</error>' + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } + + public function testNotFound() { + $tagId = '404'; + + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($tagId) { + if ($arg === 'id') { + return $tagId; + } + throw new \Exception(); + }); + + $this->systemTagManager->method('getTagsByIds') + ->with($tagId) + ->willReturn([]); + + $this->output->expects($this->once()) + ->method('writeln') + ->with( + '<error>Tag not found</error>' + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } +} diff --git a/tests/Core/Command/SystemTag/ListCommandTest.php b/tests/Core/Command/SystemTag/ListCommandTest.php new file mode 100644 index 00000000000..2e2fba1017f --- /dev/null +++ b/tests/Core/Command/SystemTag/ListCommandTest.php @@ -0,0 +1,113 @@ +<?php +/** + * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de> + * + * @author Johannes Leuker <developers@hosting.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Core\Command\SystemTag; + +use OC\Core\Command\SystemTag\ListCommand; +use OCP\SystemTag\ISystemTag; +use OCP\SystemTag\ISystemTagManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; + +class ListCommandTest extends TestCase { + + /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */ + private $systemTagManager; + + /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */ + private $command; + + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $input; + + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $output; + + protected function setUp(): void { + parent::setUp(); + + $this->systemTagManager = $this->createMock(ISystemTagManager::class); + $this->command = $this->getMockBuilder(ListCommand::class) + ->setConstructorArgs([$this->systemTagManager]) + ->setMethods(['writeArrayInOutputFormat']) + ->getMock(); + + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testExecute() { + $tag1 = $this->createMock(ISystemTag::class); + $tag1->method('getId')->willReturn('1'); + $tag1->method('getName')->willReturn('public_tag'); + $tag1->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC); + $tag2 = $this->createMock(ISystemTag::class); + $tag2->method('getId')->willReturn('2'); + $tag2->method('getName')->willReturn('restricted_tag'); + $tag2->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_RESTRICTED); + $tag3 = $this->createMock(ISystemTag::class); + $tag3->method('getId')->willReturn('3'); + $tag3->method('getName')->willReturn('invisible_tag'); + $tag3->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE); + + $this->systemTagManager->method('getAllTags') + ->with( + null, + null + )->willReturn([$tag1, $tag2, $tag3]); + + $this->input->method('getOption') + ->willReturnCallback(function ($arg) { + if ($arg === 'visibilityFilter') { + return null; + } elseif ($arg === 'nameSearchPattern') { + return null; + } + throw new \Exception(); + }); + + $this->command->expects($this->once()) + ->method('writeArrayInOutputFormat') + ->with( + $this->equalTo($this->input), + $this->equalTo($this->output), + [ + '1' => [ + 'name' => 'public_tag', + 'access' => 'public', + ], + '2' => [ + 'name' => 'restricted_tag', + 'access' => 'restricted', + ], + '3' => [ + 'name' => 'invisible_tag', + 'access' => 'invisible', + ] + ] + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } +} diff --git a/tests/docker/mysqlmb4.config.php b/tests/docker/mysqlmb4.config.php index 528673950a4..3511e3c3723 100644 --- a/tests/docker/mysqlmb4.config.php +++ b/tests/docker/mysqlmb4.config.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + $CONFIG = [ 'mysql.utf8mb4' => true, ]; diff --git a/tests/jestBabelTransformer.js b/tests/jestBabelTransformer.js new file mode 100644 index 00000000000..6790920a76c --- /dev/null +++ b/tests/jestBabelTransformer.js @@ -0,0 +1,26 @@ +/** + * @copyright 2021 François Freitag <mail@franek.fr> + * + * @author François Freitag <mail@franek.fr> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +const babelJest = require('babel-jest') +const babelConfig = require('@nextcloud/babel-config') + +module.exports = babelJest.createTransformer(babelConfig) diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index 687ae29ff7b..9bce92716ac 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -106,6 +106,7 @@ class AccountManagerTest extends TestCase { /** @var IUser $user */ $user = $this->createMock(IUser::class); + // FIXME: should be an integration test instead of this abomination $accountManager->expects($this->once())->method('getUser')->with($user)->willReturn($oldData); if ($updateExisting) { @@ -147,9 +148,9 @@ class AccountManagerTest extends TestCase { public function dataTrueFalse() { return [ - [['newData'], ['oldData'], false, true], - [['newData'], [], true, false], - [['oldData'], ['oldData'], false, false] + [['myProperty' => ['value' => 'newData']], ['myProperty' => ['value' => 'oldData']], false, true], + [['myProperty' => ['value' => 'newData']], [], true, false], + [['myProperty' => ['value' => 'oldData']], ['myProperty' => ['value' => 'oldData']], false, false] ]; } @@ -213,8 +214,8 @@ class AccountManagerTest extends TestCase { // SCOPE_PRIVATE is not allowed for display name and email IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_PRIVATE], IAccountManager::PROPERTY_EMAIL => ['value' => 'test@example.org', 'scope' => IAccountManager::SCOPE_PRIVATE], - IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => 'invalid'], - IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => ''], + IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => IAccountManager::SCOPE_LOCAL], + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_LOCAL], ], [ IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_LOCAL], @@ -222,9 +223,23 @@ class AccountManagerTest extends TestCase { IAccountManager::PROPERTY_TWITTER => ['value' => '@sometwitter', 'scope' => IAccountManager::SCOPE_LOCAL], IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_LOCAL], ], - // don't throw but fall back false, false, ], + // illegal scope values + [ + [ + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => IAccountManager::SCOPE_FEDERATED], + IAccountManager::PROPERTY_ADDRESS => ['value' => 'some street', 'scope' => IAccountManager::SCOPE_LOCAL], + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.org', 'scope' => IAccountManager::SCOPE_PRIVATE], + ], + [ + IAccountManager::PROPERTY_PHONE => ['value' => '+491601231212', 'scope' => ''], + IAccountManager::PROPERTY_ADDRESS => ['value' => 'some street', 'scope' => 'v2-invalid'], + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://example.org', 'scope' => 'invalid'], + ], + [], + true, true + ], // invalid or unsupported scope values throw an exception when passing $throwOnData=true [ [IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'Display Name', 'scope' => IAccountManager::SCOPE_PUBLISHED]], diff --git a/tests/lib/Accounts/AccountPropertyTest.php b/tests/lib/Accounts/AccountPropertyTest.php index f99abc21f83..50c3b8f84a4 100644 --- a/tests/lib/Accounts/AccountPropertyTest.php +++ b/tests/lib/Accounts/AccountPropertyTest.php @@ -38,7 +38,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $this->assertEquals(IAccountManager::PROPERTY_WEBSITE, $accountProperty->getName()); $this->assertEquals('https://example.com', $accountProperty->getValue()); @@ -51,7 +52,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setValue('https://example.org'); $this->assertEquals('https://example.org', $accountProperty->getValue()); @@ -63,7 +65,8 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setScope(IAccountManager::SCOPE_LOCAL); $this->assertEquals(IAccountManager::SCOPE_LOCAL, $accountProperty->getScope()); @@ -80,21 +83,26 @@ class AccountPropertyTest extends TestCase { [IAccountManager::VISIBILITY_PRIVATE, IAccountManager::SCOPE_LOCAL], [IAccountManager::VISIBILITY_CONTACTS_ONLY, IAccountManager::SCOPE_FEDERATED], [IAccountManager::VISIBILITY_PUBLIC, IAccountManager::SCOPE_PUBLISHED], - // fallback - ['', IAccountManager::SCOPE_LOCAL], - ['unknown', IAccountManager::SCOPE_LOCAL], + // invalid values + ['', null], + ['unknown', null], + ['v2-unknown', null], ]; } /** * @dataProvider scopesProvider */ - public function testSetScopeMapping($storedScope, $returnedScope) { + public function testSetScopeMapping(string $storedScope, ?string $returnedScope) { + if ($returnedScope === null) { + $this->expectException(\InvalidArgumentException::class); + } $accountProperty = new AccountProperty( IAccountManager::PROPERTY_WEBSITE, 'https://example.com', $storedScope, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $this->assertEquals($returnedScope, $accountProperty->getScope()); } @@ -104,25 +112,42 @@ class AccountPropertyTest extends TestCase { IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '' ); $actualReturn = $accountProperty->setVerified(IAccountManager::NOT_VERIFIED); $this->assertEquals(IAccountManager::NOT_VERIFIED, $accountProperty->getVerified()); $this->assertEquals(IAccountManager::NOT_VERIFIED, $actualReturn->getVerified()); } + public function testSetVerificationData() { + $accountProperty = new AccountProperty( + IAccountManager::PROPERTY_WEBSITE, + 'https://example.com', + IAccountManager::SCOPE_PUBLISHED, + IAccountManager::VERIFIED, + '' + ); + $token = uniqid(); + $actualReturn = $accountProperty->setVerificationData($token); + $this->assertEquals($token, $accountProperty->getVerificationData()); + $this->assertEquals($token, $actualReturn->getVerificationData()); + } + public function testJsonSerialize() { $accountProperty = new AccountProperty( IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, - IAccountManager::VERIFIED + IAccountManager::VERIFIED, + '60a7a633b74af', ); $this->assertEquals([ 'name' => IAccountManager::PROPERTY_WEBSITE, 'value' => 'https://example.com', 'scope' => IAccountManager::SCOPE_PUBLISHED, - 'verified' => IAccountManager::VERIFIED + 'verified' => IAccountManager::VERIFIED, + 'verificationData' => '60a7a633b74af' ], $accountProperty->jsonSerialize()); } } diff --git a/tests/lib/Accounts/AccountTest.php b/tests/lib/Accounts/AccountTest.php index 8afcc44afd1..9c2a5333d20 100644 --- a/tests/lib/Accounts/AccountTest.php +++ b/tests/lib/Accounts/AccountTest.php @@ -43,7 +43,7 @@ class AccountTest extends TestCase { public function testSetProperty() { $user = $this->createMock(IUser::class); - $property = new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); + $property = new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''); $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); $this->assertEquals($property, $account->getProperty(IAccountManager::PROPERTY_WEBSITE)); @@ -52,8 +52,8 @@ class AccountTest extends TestCase { public function testGetProperties() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED) + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, '') ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); @@ -65,9 +65,9 @@ class AccountTest extends TestCase { public function testGetFilteredProperties() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED), - IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED), + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, ''), + IAccountManager::PROPERTY_PHONE => new AccountProperty(IAccountManager::PROPERTY_PHONE, '123456', IAccountManager::SCOPE_PUBLISHED, IAccountManager::VERIFIED, ''), ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); @@ -98,8 +98,8 @@ class AccountTest extends TestCase { public function testJsonSerialize() { $user = $this->createMock(IUser::class); $properties = [ - IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED), - IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED) + IAccountManager::PROPERTY_WEBSITE => new AccountProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED, ''), + IAccountManager::PROPERTY_EMAIL => new AccountProperty(IAccountManager::PROPERTY_EMAIL, 'user@example.com', IAccountManager::SCOPE_LOCAL, IAccountManager::VERIFIED, '') ]; $account = new Account($user); $account->setProperty(IAccountManager::PROPERTY_WEBSITE, 'https://example.com', IAccountManager::SCOPE_PUBLISHED, IAccountManager::NOT_VERIFIED); diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 5b6fedb1cc2..db2f117cb9b 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -20,10 +20,10 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; @@ -93,7 +93,7 @@ class AppManagerTest extends TestCase { /** @var EventDispatcherInterface|MockObject */ protected $eventDispatcher; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; /** @var IAppManager */ @@ -109,7 +109,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->cacheFactory->expects($this->any()) ->method('createDistributed') ->with('settings') diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php index f9696cc1b00..840d47ed802 100644 --- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -34,7 +34,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; class AppFetcherTest extends TestCase { @@ -48,7 +48,7 @@ class AppFetcherTest extends TestCase { protected $config; /** @var CompareVersion|\PHPUnit\Framework\MockObject\MockObject */ protected $compareVersion; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; /** @var AppFetcher */ protected $fetcher; @@ -1848,7 +1848,7 @@ EJL3BaQAQaASSsvFrcozYxrQG4VzEg== $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); $this->compareVersion = new CompareVersion(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->fetcher = new AppFetcher( $factory, diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php index 531fdf41e78..735df939965 100644 --- a/tests/lib/App/AppStore/Fetcher/FetcherBase.php +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -33,7 +33,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; abstract class FetcherBase extends TestCase { @@ -47,7 +47,7 @@ abstract class FetcherBase extends TestCase { protected $timeFactory; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; /** @var Fetcher */ protected $fetcher; @@ -67,7 +67,7 @@ abstract class FetcherBase extends TestCase { $this->clientService = $this->createMock(IClientService::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); } public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion() { diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php index 1fca34423d5..05442455cb7 100644 --- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php +++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php @@ -35,9 +35,9 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use OCP\IServerContainer; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class CoordinatorTest extends TestCase { @@ -57,7 +57,7 @@ class CoordinatorTest extends TestCase { /** @var IEventDispatcher|MockObject */ private $eventDispatcher; - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var Coordinator */ @@ -71,7 +71,7 @@ class CoordinatorTest extends TestCase { $this->crashReporterRegistry = $this->createMock(Registry::class); $this->dashboardManager = $this->createMock(IManager::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->coordinator = new Coordinator( $this->serverContainer, diff --git a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php index e304a63cfc4..f97ac92e887 100644 --- a/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php +++ b/tests/lib/AppFramework/Bootstrap/RegistrationContextTest.php @@ -29,13 +29,13 @@ use OC\AppFramework\Bootstrap\RegistrationContext; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\EventDispatcher\IEventDispatcher; -use OCP\ILogger; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class RegistrationContextTest extends TestCase { - /** @var ILogger|MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var RegistrationContext */ @@ -44,7 +44,7 @@ class RegistrationContextTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->context = new RegistrationContext( $this->logger diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php index 1ee6da9ca30..83b764f6c65 100644 --- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php @@ -98,29 +98,24 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V1Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + $this->assertInstanceOf(V1Response::class, $result); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception instanceof OCSForbiddenException) { - $this->assertSame(Http::STATUS_UNAUTHORIZED, $result->getStatus()); - } else { - $this->assertSame(Http::STATUS_OK, $result->getStatus()); - } - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + + $this->assertSame(Http::STATUS_OK, $result->getStatus()); } /** @@ -139,23 +134,22 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V2Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } - $this->assertSame($code, $result->getStatus()); - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + $this->assertInstanceOf(V2Response::class, $result); + + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + $this->assertSame($code, $result->getStatus()); } /** @@ -174,23 +168,22 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V2Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } - $this->assertSame($code, $result->getStatus()); - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + $this->assertInstanceOf(V2Response::class, $result); + + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + $this->assertSame($code, $result->getStatus()); } public function dataAfterController() { @@ -205,7 +198,7 @@ class OCSMiddlewareTest extends \Test\TestCase { [$OCSController, new Http\Response(), false], [$OCSController, new Http\JSONResponse(), false], [$OCSController, new Http\JSONResponse(['message' => 'foo']), false], - [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true], + [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED], [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true], [$controller, new Http\Response(), false], @@ -223,8 +216,9 @@ class OCSMiddlewareTest extends \Test\TestCase { * @param Controller $controller * @param Http\Response $response * @param bool $converted + * @param int $convertedOCSStatus */ - public function testAfterController($controller, $response, $converted) { + public function testAfterController($controller, $response, $converted, $convertedOCSStatus = 0) { $OCSMiddleware = new OCSMiddleware($this->request); $newResponse = $OCSMiddleware->afterController($controller, 'foo', $response); @@ -233,8 +227,13 @@ class OCSMiddlewareTest extends \Test\TestCase { } else { $this->assertInstanceOf(BaseResponse::class, $newResponse); $this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'statusMessage')); - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED, $newResponse->getOCSStatus()); - $this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus()); + + if ($convertedOCSStatus) { + $this->assertSame($convertedOCSStatus, $newResponse->getOCSStatus()); + } else { + $this->assertSame($response->getStatus(), $newResponse->getOCSStatus()); + } + $this->assertSame($response->getStatus(), $newResponse->getStatus()); } } } diff --git a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php index 0d27a9a070f..aa713b99156 100644 --- a/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/RateLimitingMiddlewareTest.php @@ -26,13 +26,16 @@ use OC\AppFramework\Utility\ControllerMethodReflector; use OC\Security\RateLimiting\Exception\RateLimitExceededException; use OC\Security\RateLimiting\Limiter; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; use Test\TestCase; +/** + * @group DB + */ class RateLimitingMiddlewareTest extends TestCase { /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ private $request; @@ -250,11 +253,7 @@ class RateLimitingMiddlewareTest extends TestCase { ->willReturn('JSON'); $result = $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new RateLimitExceededException()); - $expected = new JSONResponse( - [ - 'message' => 'Rate limit exceeded', - ], - 429 + $expected = new DataResponse([], 429 ); $this->assertEquals($expected, $result); } @@ -271,13 +270,12 @@ class RateLimitingMiddlewareTest extends TestCase { $result = $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new RateLimitExceededException()); $expected = new TemplateResponse( 'core', - '403', - [ - 'file' => 'Rate limit exceeded', - ], - 'guest' + '429', + [], + TemplateResponse::RENDER_AS_GUEST ); $expected->setStatus(429); $this->assertEquals($expected, $result); + $this->assertIsString($result->render()); } } diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index a3c9efa557c..076f6588d94 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -39,11 +39,11 @@ use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\INavigationManager; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Security\ISecureRandom; +use Psr\Log\LoggerInterface; class SecurityMiddlewareTest extends \Test\TestCase { @@ -59,7 +59,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { private $request; /** @var ControllerMethodReflector */ private $reader; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */ private $navigationManager; @@ -75,7 +75,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { $this->controller = $this->createMock(Controller::class); $this->reader = new ControllerMethodReflector(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->navigationManager = $this->createMock(INavigationManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->request = $this->createMock(IRequest::class); diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 7ada4ec746a..22fad4ab61f 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -13,6 +13,7 @@ use OC\App\AppManager; use OC\App\InfoParser; use OC\AppConfig; use OCP\IAppConfig; +use Psr\Log\LoggerInterface; /** * Class AppTest @@ -477,7 +478,7 @@ class AppTest extends \Test\TestCase { 'appforgroup2' => '["group2"]', 'appforgroup12' => '["group2","group1"]', ] - + ); $apps = \OC_App::getEnabledApps(false, $forceAll); @@ -512,7 +513,7 @@ class AppTest extends \Test\TestCase { 'app3' => 'yes', 'app2' => 'no', ] - + ); $apps = \OC_App::getEnabledApps(); @@ -554,7 +555,7 @@ class AppTest extends \Test\TestCase { \OC::$server->getGroupManager(), \OC::$server->getMemCacheFactory(), \OC::$server->getEventDispatcher(), - \OC::$server->getLogger() + \OC::$server->get(LoggerInterface::class) )); } diff --git a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php index 1b813b5f36b..d9c565a3f6d 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php @@ -32,15 +32,16 @@ use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Authentication\TwoFactorAuth\ProviderLoader; use OCP\App\IAppManager; use OCP\Authentication\TwoFactorAuth\IProvider; +use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class ProviderLoaderTest extends TestCase { - /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IAppManager|MockObject */ private $appManager; - /** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUser|MockObject */ private $user; /** @var RegistrationContext|MockObject */ @@ -53,7 +54,7 @@ class ProviderLoaderTest extends TestCase { parent::setUp(); $this->appManager = $this->createMock(IAppManager::class); - $this->user = $this->createMock(\OCP\IUser::class); + $this->user = $this->createMock(IUser::class); $this->registrationContext = $this->createMock(RegistrationContext::class); $coordinator = $this->createMock(Coordinator::class); @@ -123,7 +124,7 @@ class ProviderLoaderTest extends TestCase { ->with($this->user) ->willReturn([]); - $this->registrationContext->method('getTwoFactorProvider') + $this->registrationContext->method('getTwoFactorProviders') ->willReturn([ new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider') ]); diff --git a/tests/lib/Avatar/AvatarManagerTest.php b/tests/lib/Avatar/AvatarManagerTest.php index d3bc60efb59..ce6981a2a21 100644 --- a/tests/lib/Avatar/AvatarManagerTest.php +++ b/tests/lib/Avatar/AvatarManagerTest.php @@ -36,9 +36,9 @@ use OCP\Files\IAppData; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; +use Psr\Log\LoggerInterface; /** * Class AvatarManagerTest @@ -52,7 +52,7 @@ class AvatarManagerTest extends \Test\TestCase { private $appData; /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private $l10n; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ private $config; @@ -70,7 +70,7 @@ class AvatarManagerTest extends \Test\TestCase { $this->userManager = $this->createMock(Manager::class); $this->appData = $this->createMock(IAppData::class); $this->l10n = $this->createMock(IL10N::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->config = $this->createMock(IConfig::class); $this->accountManager = $this->createMock(IAccountManager::class); $this->knownUserService = $this->createMock(KnownUserService::class); @@ -247,7 +247,7 @@ class AvatarManagerTest extends \Test\TestCase { } if ($expectedPlaceholder) { - $expected = new PlaceholderAvatar($folder, $user, $this->createMock(ILogger::class)); + $expected = new PlaceholderAvatar($folder, $user, $this->createMock(LoggerInterface::class)); } else { $expected = new UserAvatar($folder, $this->l10n, $user, $this->logger, $this->config); } diff --git a/tests/lib/Avatar/GuestAvatarTest.php b/tests/lib/Avatar/GuestAvatarTest.php index 1c424234f10..b8e6d8ae2e8 100644 --- a/tests/lib/Avatar/GuestAvatarTest.php +++ b/tests/lib/Avatar/GuestAvatarTest.php @@ -26,8 +26,8 @@ namespace Test\Avatar; use OC\Avatar\GuestAvatar; use OCP\Files\SimpleFS\InMemoryFile; -use OCP\ILogger; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; /** @@ -48,8 +48,8 @@ class GuestAvatarTest extends TestCase { * @return void */ public function setupGuestAvatar() { - /* @var MockObject|ILogger $logger */ - $logger = $this->getMockBuilder(ILogger::class)->getMock(); + /* @var MockObject|LoggerInterface $logger */ + $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->guestAvatar = new GuestAvatar('einstein', $logger); } diff --git a/tests/lib/Avatar/UserAvatarTest.php b/tests/lib/Avatar/UserAvatarTest.php index 31f2a6ebf5b..3570f2017d5 100644 --- a/tests/lib/Avatar/UserAvatarTest.php +++ b/tests/lib/Avatar/UserAvatarTest.php @@ -16,7 +16,7 @@ use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\IL10N; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class UserAvatarTest extends \Test\TestCase { /** @var Folder | \PHPUnit\Framework\MockObject\MockObject */ @@ -309,7 +309,7 @@ class UserAvatarTest extends \Test\TestCase { $this->folder, $l, $user, - $this->createMock(ILogger::class), + $this->createMock(LoggerInterface::class), $this->config ); } diff --git a/tests/lib/CapabilitiesManagerTest.php b/tests/lib/CapabilitiesManagerTest.php index 536355f9697..4909272c4a8 100644 --- a/tests/lib/CapabilitiesManagerTest.php +++ b/tests/lib/CapabilitiesManagerTest.php @@ -25,19 +25,19 @@ use OC\CapabilitiesManager; use OCP\AppFramework\QueryException; use OCP\Capabilities\ICapability; use OCP\Capabilities\IPublicCapability; -use OCP\ILogger; +use Psr\Log\LoggerInterface; class CapabilitiesManagerTest extends TestCase { /** @var CapabilitiesManager */ private $manager; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; protected function setUp(): void { parent::setUp(); - $this->logger = $this->getMockBuilder(ILogger::class)->getMock(); + $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->manager = new CapabilitiesManager($this->logger); } @@ -139,7 +139,7 @@ class CapabilitiesManagerTest extends TestCase { ] ] ]; - + $this->assertEquals($expected, $res); } diff --git a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php index 2f7cd1061e9..1cbaa178445 100644 --- a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php @@ -125,13 +125,15 @@ class GroupPluginTest extends TestCase { return $group; } - public function dataGetGroups() { + public function dataGetGroups(): array { return [ - ['test', false, true, [], [], [], [], true, false], - ['test', false, false, [], [], [], [], true, false], + ['test', false, true, false, [], [], [], [], true, false], + ['test', false, false, false, [], [], [], [], true, false], + // group sharing disabled + ['test', false, true, true, [], [], [], [], false, false], // group without display name [ - 'test', false, true, + 'test', false, true, false, [$this->getGroupMock('test1')], [], [], @@ -141,7 +143,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by id [ - 'test', false, true, + 'test', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [], @@ -151,7 +153,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by display name [ - 'one', false, true, + 'one', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [], @@ -161,7 +163,7 @@ class GroupPluginTest extends TestCase { ], // group with display name, search by display name, exact expected [ - 'Test One', false, true, + 'Test One', false, true, false, [$this->getGroupMock('test1', 'Test One')], [], [['label' => 'Test One', 'value' => ['shareType' => IShare::TYPE_GROUP, 'shareWith' => 'test1']]], @@ -170,7 +172,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, false, + 'test', false, false, false, [$this->getGroupMock('test1')], [], [], @@ -179,7 +181,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -191,7 +193,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -203,7 +205,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -218,7 +220,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -230,7 +232,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', false, true, + 'test', false, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -247,7 +249,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -260,10 +262,10 @@ class GroupPluginTest extends TestCase { true, $this->getGroupMock('test'), ], - ['test', true, true, [], [], [], [], true, false], - ['test', true, false, [], [], [], [], true, false], + ['test', true, true, false, [], [], [], [], true, false], + ['test', true, false, false, [], [], [], [], true, false], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test1'), $this->getGroupMock('test2'), @@ -275,7 +277,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test1'), $this->getGroupMock('test2'), @@ -287,7 +289,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -299,7 +301,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -311,7 +313,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -323,7 +325,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -335,7 +337,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -347,7 +349,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test'), $this->getGroupMock('test1'), @@ -359,7 +361,7 @@ class GroupPluginTest extends TestCase { false, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -374,7 +376,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -386,7 +388,7 @@ class GroupPluginTest extends TestCase { null, ], [ - 'test', true, true, + 'test', true, true, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -403,7 +405,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', true, false, + 'test', true, false, false, [ $this->getGroupMock('test0'), $this->getGroupMock('test1'), @@ -417,7 +419,7 @@ class GroupPluginTest extends TestCase { $this->getGroupMock('test'), ], [ - 'test', false, false, + 'test', false, false, false, [ $this->getGroupMock('test', null, true), $this->getGroupMock('test1'), @@ -437,6 +439,7 @@ class GroupPluginTest extends TestCase { * @param string $searchTerm * @param bool $shareWithGroupOnly * @param bool $shareeEnumeration + * @param bool $groupSharingDisabled * @param array $groupResponse * @param array $userGroupsResponse * @param array $exactExpected @@ -445,35 +448,45 @@ class GroupPluginTest extends TestCase { * @param bool|IGroup $singleGroup */ public function testSearch( - $searchTerm, - $shareWithGroupOnly, - $shareeEnumeration, + string $searchTerm, + bool $shareWithGroupOnly, + bool $shareeEnumeration, + bool $groupSharingDisabled, array $groupResponse, array $userGroupsResponse, array $exactExpected, array $expected, - $reachedEnd, + bool $reachedEnd, $singleGroup ) { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( - function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration) { - if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') { - return $shareWithGroupOnly ? 'yes' : 'no'; - } elseif ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { - return $shareeEnumeration ? 'yes' : 'no'; + function ($appName, $key, $default) use ($shareWithGroupOnly, $shareeEnumeration, $groupSharingDisabled) { + if ($appName !== 'core') { + return $default; + } + switch ($key) { + case 'shareapi_only_share_with_group_members': + return $shareWithGroupOnly ? 'yes' : 'no'; + case 'shareapi_allow_share_dialog_user_enumeration': + return $shareeEnumeration ? 'yes' : 'no'; + case 'shareapi_allow_group_sharing': + return $groupSharingDisabled ? 'no' : 'yes'; + default: + return $default; } - return $default; } ); $this->instantiatePlugin(); - $this->groupManager->expects($this->once()) - ->method('search') - ->with($searchTerm, $this->limit, $this->offset) - ->willReturn($groupResponse); + if (!$groupSharingDisabled) { + $this->groupManager->expects($this->once()) + ->method('search') + ->with($searchTerm, $this->limit, $this->offset) + ->willReturn($groupResponse); + } if ($singleGroup !== false) { $this->groupManager->expects($this->once()) @@ -497,8 +510,10 @@ class GroupPluginTest extends TestCase { $moreResults = $this->plugin->search($searchTerm, $this->limit, $this->offset, $this->searchResult); $result = $this->searchResult->asArray(); - $this->assertEquals($exactExpected, $result['exact']['groups']); - $this->assertEquals($expected, $result['groups']); + if (!$groupSharingDisabled) { + $this->assertEquals($exactExpected, $result['exact']['groups']); + $this->assertEquals($expected, $result['groups']); + } $this->assertSame($reachedEnd, $moreResults); } } diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 81279c4c569..3ec9e6f5efc 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -33,25 +33,26 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\IConfig; -use OCP\ILogger; use OCP\IUser; use OCP\IUserSession; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Test\TestCase; class LookupPluginTest extends TestCase { - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IClientService|MockObject */ protected $clientService; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserSession|MockObject */ protected $userSession; - /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ICloudIdManager|MockObject */ protected $cloudIdManager; /** @var LookupPlugin */ protected $plugin; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; protected function setUp(): void { @@ -60,7 +61,7 @@ class LookupPluginTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->clientService = $this->createMock(IClientService::class); $cloudId = $this->createMock(ICloudId::class); $cloudId->expects($this->any())->method('getRemote')->willReturn('myNextcloud.net'); @@ -108,7 +109,7 @@ class LookupPluginTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->plugin->search('foobar', 10, 0, $searchResult); @@ -132,7 +133,7 @@ class LookupPluginTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->plugin->search('foobar', 10, 0, $searchResult); @@ -145,7 +146,7 @@ class LookupPluginTest extends TestCase { public function testSearch(array $searchParams) { $type = new SearchResultType('lookup'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $searchResult->expects($this->once()) ->method('addResultSet') @@ -207,7 +208,7 @@ class LookupPluginTest extends TestCase { public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled) { $type = new SearchResultType('lookup'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $this->config->expects($this->once()) @@ -269,7 +270,7 @@ class LookupPluginTest extends TestCase { ->with('files_sharing', 'lookupServerEnabled', 'yes') ->willReturn('no'); - /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */ + /** @var ISearchResult|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); $searchResult->expects($this->never()) ->method('addResultSet'); diff --git a/tests/lib/Collaboration/Resources/ManagerTest.php b/tests/lib/Collaboration/Resources/ManagerTest.php index 092d4ffd39c..01a39660a7c 100644 --- a/tests/lib/Collaboration/Resources/ManagerTest.php +++ b/tests/lib/Collaboration/Resources/ManagerTest.php @@ -27,12 +27,12 @@ use OC\Collaboration\Resources\Manager; use OCP\Collaboration\Resources\IManager; use OCP\Collaboration\Resources\IProviderManager; use OCP\IDBConnection; -use OCP\ILogger; +use Psr\Log\LoggerInterface; use Test\TestCase; class ManagerTest extends TestCase { - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var IProviderManager */ protected $providerManager; @@ -42,14 +42,14 @@ class ManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->providerManager = $this->createMock(IProviderManager::class); /** @var IDBConnection $connection */ $connection = $this->createMock(IDBConnection::class); $this->manager = new Manager($connection, $this->providerManager, $this->logger); } - + public function testRegisterResourceProvider(): void { $this->logger->expects($this->once()) ->method('debug') diff --git a/tests/lib/Collaboration/Resources/ProviderManagerTest.php b/tests/lib/Collaboration/Resources/ProviderManagerTest.php index 751e2cc1f8d..19a34962a56 100644 --- a/tests/lib/Collaboration/Resources/ProviderManagerTest.php +++ b/tests/lib/Collaboration/Resources/ProviderManagerTest.php @@ -27,15 +27,15 @@ use OC\Collaboration\Resources\ProviderManager; use OCA\Files\Collaboration\Resources\ResourceProvider; use OCP\AppFramework\QueryException; use OCP\Collaboration\Resources\IProviderManager; -use OCP\ILogger; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use Test\TestCase; class ProviderManagerTest extends TestCase { /** @var IServerContainer */ protected $serverContainer; - /** @var ILogger */ + /** @var LoggerInterface */ protected $logger; /** @var IProviderManager */ protected $providerManager; @@ -44,7 +44,7 @@ class ProviderManagerTest extends TestCase { parent::setUp(); $this->serverContainer = $this->createMock(IServerContainer::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->providerManager = new class($this->serverContainer, $this->logger) extends ProviderManager { public function countProviders(): int { diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 1d541556c0b..36398171b1b 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -773,6 +773,10 @@ class FolderTest extends NodeTest { $folderInfo->expects($this->any()) ->method('getMountPoint') ->willReturn($mount); + $root->method('getMount') + ->willReturn($mount); + $root->method('getMountsIn') + ->willReturn([]); $cache = $storage->getCache(); @@ -838,6 +842,11 @@ class FolderTest extends NodeTest { ->method('getMountPoint') ->willReturn($mount); + $root->method('getMount') + ->willReturn($mount); + $root->method('getMountsIn') + ->willReturn([]); + $cache = $storage->getCache(); $id1 = $cache->put('bar/foo/folder', [ @@ -903,6 +912,10 @@ class FolderTest extends NodeTest { $folderInfo->expects($this->any()) ->method('getMountPoint') ->willReturn($mount); + $root->method('getMount') + ->willReturn($mount); + $root->method('getMountsIn') + ->willReturn([]); $cache = $storage->getCache(); diff --git a/tests/lib/InitialStateServiceTest.php b/tests/lib/InitialStateServiceTest.php index 30eca056206..2a23774baf1 100644 --- a/tests/lib/InitialStateServiceTest.php +++ b/tests/lib/InitialStateServiceTest.php @@ -27,10 +27,10 @@ namespace Test; use OC\AppFramework\Bootstrap\Coordinator; use OCP\IServerContainer; +use Psr\Log\LoggerInterface; use function json_encode; use JsonSerializable; use OC\InitialStateService; -use OCP\ILogger; use stdClass; class InitialStateServiceTest extends TestCase { @@ -42,7 +42,7 @@ class InitialStateServiceTest extends TestCase { parent::setUp(); $this->service = new InitialStateService( - $this->createMock(ILogger::class), + $this->createMock(LoggerInterface::class), $this->createMock(Coordinator::class), $this->createMock(IServerContainer::class) ); diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 2626e047c74..c49f8bf76a5 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -14,8 +14,8 @@ use OC\Installer; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; -use OCP\ILogger; use OCP\ITempManager; +use Psr\Log\LoggerInterface; /** * Class InstallerTest @@ -32,7 +32,7 @@ class InstallerTest extends TestCase { private $clientService; /** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */ private $tempManager; - /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ private $config; @@ -43,7 +43,7 @@ class InstallerTest extends TestCase { $this->appFetcher = $this->createMock(AppFetcher::class); $this->clientService = $this->createMock(IClientService::class); $this->tempManager = $this->createMock(ITempManager::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->config = $this->createMock(IConfig::class); $config = \OC::$server->getConfig(); @@ -53,7 +53,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), $config, false ); @@ -76,7 +76,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), false ); @@ -100,7 +100,7 @@ class InstallerTest extends TestCase { \OC::$server->getAppFetcher(), \OC::$server->getHTTPClientService(), \OC::$server->getTempManager(), - \OC::$server->getLogger(), + \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), false ); diff --git a/tests/lib/Security/Bruteforce/CapabilitiesTest.php b/tests/lib/Security/Bruteforce/CapabilitiesTest.php index cd43d94f8cb..1c2bbb6bc53 100644 --- a/tests/lib/Security/Bruteforce/CapabilitiesTest.php +++ b/tests/lib/Security/Bruteforce/CapabilitiesTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl> * diff --git a/tests/lib/Security/Bruteforce/ThrottlerTest.php b/tests/lib/Security/Bruteforce/ThrottlerTest.php index b4a7016bc20..fb28a7c9c7a 100644 --- a/tests/lib/Security/Bruteforce/ThrottlerTest.php +++ b/tests/lib/Security/Bruteforce/ThrottlerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/CSP/AddContentSecurityPolicyEventTest.php b/tests/lib/Security/CSP/AddContentSecurityPolicyEventTest.php index ef894bb56f3..7de4665ec58 100644 --- a/tests/lib/Security/CSP/AddContentSecurityPolicyEventTest.php +++ b/tests/lib/Security/CSP/AddContentSecurityPolicyEventTest.php @@ -1,6 +1,7 @@ <?php declare(strict_types=1); + /** * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> * diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php index 2fc7a53e78d..b91482ab2c6 100644 --- a/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php +++ b/tests/lib/Security/CSP/ContentSecurityPolicyManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php index 783eb35eef9..0e21f13e6f7 100644 --- a/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php +++ b/tests/lib/Security/CSP/ContentSecurityPolicyNonceManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php b/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php index 10ab0f00c94..256199eff15 100644 --- a/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php +++ b/tests/lib/Security/CSRF/CsrfTokenGeneratorTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php index 29fbbfe3b26..44a9a7a929d 100644 --- a/tests/lib/Security/CSRF/CsrfTokenManagerTest.php +++ b/tests/lib/Security/CSRF/CsrfTokenManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CSRF/CsrfTokenTest.php b/tests/lib/Security/CSRF/CsrfTokenTest.php index fbb92cd315a..b694e797232 100644 --- a/tests/lib/Security/CSRF/CsrfTokenTest.php +++ b/tests/lib/Security/CSRF/CsrfTokenTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php index 8d4a966efea..f55cf49f142 100644 --- a/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php +++ b/tests/lib/Security/CSRF/TokenStorage/SessionStorageTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CertificateManagerTest.php b/tests/lib/Security/CertificateManagerTest.php index 3af4b564612..c50296c2a33 100644 --- a/tests/lib/Security/CertificateManagerTest.php +++ b/tests/lib/Security/CertificateManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or diff --git a/tests/lib/Security/CertificateTest.php b/tests/lib/Security/CertificateTest.php index 223fb226904..5d3fd602fb2 100644 --- a/tests/lib/Security/CertificateTest.php +++ b/tests/lib/Security/CertificateTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Lukas Reschke <lukas@owncloud.com> * diff --git a/tests/lib/Security/CredentialsManagerTest.php b/tests/lib/Security/CredentialsManagerTest.php index e8ede3bfd66..3335e18a8b1 100644 --- a/tests/lib/Security/CredentialsManagerTest.php +++ b/tests/lib/Security/CredentialsManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @author Robin McCorkell <rmccorkell@owncloud.com> * diff --git a/tests/lib/Security/CryptoTest.php b/tests/lib/Security/CryptoTest.php index 0c7c1aa1ac7..bdbad8b2610 100644 --- a/tests/lib/Security/CryptoTest.php +++ b/tests/lib/Security/CryptoTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or diff --git a/tests/lib/Security/HasherTest.php b/tests/lib/Security/HasherTest.php index 3bd98625529..5836703504e 100644 --- a/tests/lib/Security/HasherTest.php +++ b/tests/lib/Security/HasherTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or diff --git a/tests/lib/Security/IdentityProof/KeyTest.php b/tests/lib/Security/IdentityProof/KeyTest.php index ae5f77f1609..4c852ff7020 100644 --- a/tests/lib/Security/IdentityProof/KeyTest.php +++ b/tests/lib/Security/IdentityProof/KeyTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl> * diff --git a/tests/lib/Security/IdentityProof/ManagerTest.php b/tests/lib/Security/IdentityProof/ManagerTest.php index 16ceec248ae..0a6f97f3fcd 100644 --- a/tests/lib/Security/IdentityProof/ManagerTest.php +++ b/tests/lib/Security/IdentityProof/ManagerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/IdentityProof/SignerTest.php b/tests/lib/Security/IdentityProof/SignerTest.php index 3ce211d51e7..f9abf84071d 100644 --- a/tests/lib/Security/IdentityProof/SignerTest.php +++ b/tests/lib/Security/IdentityProof/SignerTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl> * diff --git a/tests/lib/Security/Normalizer/IpAddressTest.php b/tests/lib/Security/Normalizer/IpAddressTest.php index 044fc52b4b9..b202ecd7234 100644 --- a/tests/lib/Security/Normalizer/IpAddressTest.php +++ b/tests/lib/Security/Normalizer/IpAddressTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php index 902c586dc13..ff58bd5c09e 100644 --- a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php +++ b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/RateLimiting/LimiterTest.php b/tests/lib/Security/RateLimiting/LimiterTest.php index 76121a49bc1..8b3509a4790 100644 --- a/tests/lib/Security/RateLimiting/LimiterTest.php +++ b/tests/lib/Security/RateLimiting/LimiterTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch> * diff --git a/tests/lib/Security/SecureRandomTest.php b/tests/lib/Security/SecureRandomTest.php index 0ffd7ae7c14..7257d52e8f5 100644 --- a/tests/lib/Security/SecureRandomTest.php +++ b/tests/lib/Security/SecureRandomTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or diff --git a/tests/lib/Security/TrustedDomainHelperTest.php b/tests/lib/Security/TrustedDomainHelperTest.php index 2796dead0e2..aedc4cb6a17 100644 --- a/tests/lib/Security/TrustedDomainHelperTest.php +++ b/tests/lib/Security/TrustedDomainHelperTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com> * This file is licensed under the Affero General Public License version 3 or diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index 696e1d69fbe..004fc9c866b 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -14,26 +14,27 @@ use OC\Setup; use OC\SystemConfig; use OCP\Defaults; use OCP\IL10N; -use OCP\ILogger; use OCP\Security\ISecureRandom; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; class SetupTest extends \Test\TestCase { - /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var SystemConfig|MockObject */ protected $config; - /** @var \bantu\IniGetWrapper\IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \bantu\IniGetWrapper\IniGetWrapper|MockObject */ private $iniWrapper; - /** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OCP\IL10N|MockObject */ private $l10n; - /** @var Defaults|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Defaults|MockObject */ private $defaults; - /** @var \OC\Setup|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OC\Setup|MockObject */ protected $setupClass; - /** @var \OCP\ILogger|\PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ protected $logger; - /** @var \OCP\Security\ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */ + /** @var \OCP\Security\ISecureRandom|MockObject */ protected $random; - /** @var Installer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Installer|MockObject */ protected $installer; protected function setUp(): void { @@ -43,7 +44,7 @@ class SetupTest extends \Test\TestCase { $this->iniWrapper = $this->createMock(IniGetWrapper::class); $this->l10n = $this->createMock(IL10N::class); $this->defaults = $this->createMock(Defaults::class); - $this->logger = $this->createMock(ILogger::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->random = $this->createMock(ISecureRandom::class); $this->installer = $this->createMock(Installer::class); $this->setupClass = $this->getMockBuilder(Setup::class) diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index a4dd621522d..117adc95186 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -45,6 +45,7 @@ use OCP\IServerContainer; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; +use OCP\IUserSession; use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Security\Events\ValidatePasswordPolicyEvent; @@ -104,6 +105,7 @@ class ManagerTest extends \Test\TestCase { protected $urlGenerator; /** @var \OC_Defaults|MockObject */ protected $defaults; + protected $userSession; protected function setUp(): void { $this->logger = $this->createMock(ILogger::class); @@ -119,6 +121,7 @@ class ManagerTest extends \Test\TestCase { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->defaults = $this->createMock(\OC_Defaults::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); + $this->userSession = $this->createMock(IUserSession::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->l = $this->createMock(IL10N::class); @@ -149,7 +152,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $this->defaultProvider = $this->createMock(DefaultShareProvider::class); @@ -178,7 +182,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ]); } @@ -596,7 +601,7 @@ class ManagerTest extends \Test\TestCase { [$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true], [$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true], - [$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Can’t share with yourself', true], + [$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Cannot share with yourself', true], [$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true], [$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true], @@ -639,9 +644,9 @@ class ManagerTest extends \Test\TestCase { $limitedPermssions->method('getMountPoint')->willReturn($mount); - $data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Can’t increase permissions of path', true]; - $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Can’t increase permissions of path', true]; - $data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Can’t increase permissions of path', true]; + $data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true]; + $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; + $data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true]; $nonMoveableMountPermssions = $this->createMock(Folder::class); $nonMoveableMountPermssions->method('isShareable')->willReturn(true); @@ -654,17 +659,17 @@ class ManagerTest extends \Test\TestCase { $nonMoveableMountPermssions->method('getStorage') ->willReturn($storage); - $data[] = [$this->createShare(null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Can’t increase permissions of path', false]; - $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Can’t increase permissions of path', false]; + $data[] = [$this->createShare(null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; + $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; $rootFolder = $this->createMock(Folder::class); $rootFolder->method('isShareable')->willReturn(true); $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); $rootFolder->method('getId')->willReturn(42); - $data[] = [$this->createShare(null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You can’t share your root folder', true]; - $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can’t share your root folder', true]; - $data[] = [$this->createShare(null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can’t share your root folder', true]; + $data[] = [$this->createShare(null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You cannot share your root folder', true]; + $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cannot share your root folder', true]; + $data[] = [$this->createShare(null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You cannot share your root folder', true]; $allPermssions = $this->createMock(Folder::class); $allPermssions->method('isShareable')->willReturn(true); @@ -697,7 +702,7 @@ class ManagerTest extends \Test\TestCase { ->willReturn($storage); $data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 1, null, null), null, false]; $data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 3, null, null), null, false]; - $data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 31, null, null), 'Can’t increase permissions of ', true]; + $data[] = [$this->createShare(null, IShare::TYPE_REMOTE, $remoteFile, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of ', true]; return $data; } @@ -753,7 +758,7 @@ class ManagerTest extends \Test\TestCase { public function testGeneralCheckShareRoot() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('You can’t share your root folder'); + $this->expectExceptionMessage('You cannot share your root folder'); $thrown = null; @@ -925,7 +930,7 @@ class ManagerTest extends \Test\TestCase { */ public function testValidateExpirationDateInternalEnforceTooFarIntoFuture($shareType) { $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); - $this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future'); + $this->expectExceptionMessage('Cannot set expiration date more than 3 days in the future'); $future = new \DateTime(); $future->add(new \DateInterval('P7D')); @@ -1286,7 +1291,7 @@ class ManagerTest extends \Test\TestCase { public function testValidateExpirationDateEnforceTooFarIntoFuture() { $this->expectException(\OCP\Share\Exceptions\GenericShareException::class); - $this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future'); + $this->expectExceptionMessage('Cannot set expiration date more than 3 days in the future'); $future = new \DateTime(); $future->add(new \DateInterval('P7D')); @@ -2690,7 +2695,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $share = $this->createMock(IShare::class); @@ -2734,7 +2740,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $share = $this->createMock(IShare::class); @@ -2785,7 +2792,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $share = $this->createMock(IShare::class); @@ -2970,7 +2978,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareCantChangeShareType() { $this->expectException(\Exception::class); - $this->expectExceptionMessage('Can’t change share type'); + $this->expectExceptionMessage('Cannot change share type'); $manager = $this->createManagerMock() ->setMethods([ @@ -3024,7 +3032,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareCantShareWithOwner() { $this->expectException(\Exception::class); - $this->expectExceptionMessage('Can’t share with the share owner'); + $this->expectExceptionMessage('Cannot share with the share owner'); $manager = $this->createManagerMock() ->setMethods([ @@ -3238,7 +3246,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareLinkEnableSendPasswordByTalkWithNoPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk with an empty password'); + $this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3558,7 +3566,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailEnableSendPasswordByTalkWithNoPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk with an empty password'); + $this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3631,7 +3639,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailEnableSendPasswordByTalkRemovingPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk with an empty password'); + $this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3704,7 +3712,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailEnableSendPasswordByTalkRemovingPasswordWithEmptyString() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk with an empty password'); + $this->expectExceptionMessage('Cannot enable sending the password by Talk with an empty password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3777,7 +3785,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailEnableSendPasswordByTalkWithPreviousPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t enable sending the password by Talk without setting a new password'); + $this->expectExceptionMessage('Cannot enable sending the password by Talk without setting a new password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3851,7 +3859,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailDisableSendPasswordByTalkWithPreviousPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t disable sending the password by Talk without setting a new password'); + $this->expectExceptionMessage('Cannot disable sending the password by Talk without setting a new password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3925,7 +3933,7 @@ class ManagerTest extends \Test\TestCase { public function testUpdateShareMailDisableSendPasswordByTalkWithoutChangingPassword() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t disable sending the password by Talk without setting a new password'); + $this->expectExceptionMessage('Cannot disable sending the password by Talk without setting a new password'); $manager = $this->createManagerMock() ->setMethods([ @@ -3999,7 +4007,7 @@ class ManagerTest extends \Test\TestCase { public function testMoveShareLink() { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Can’t change target of link share'); + $this->expectExceptionMessage('Cannot change target of link share'); $share = $this->manager->newShare(); $share->setShareType(IShare::TYPE_LINK); @@ -4123,7 +4131,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $this->assertSame($expected, $manager->shareProviderExists($shareType) @@ -4156,7 +4165,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $factory->setProvider($this->defaultProvider); @@ -4220,7 +4230,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $factory->setProvider($this->defaultProvider); @@ -4336,7 +4347,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $factory->setProvider($this->defaultProvider); @@ -4461,7 +4473,8 @@ class ManagerTest extends \Test\TestCase { $this->mailer, $this->urlGenerator, $this->defaults, - $this->dispatcher + $this->dispatcher, + $this->userSession ); $factory->setProvider($this->defaultProvider); diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index 1affd6d020a..5a7422cbad5 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -22,22 +22,23 @@ namespace Test; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use OC\Installer; use OC\IntegrityCheck\Checker; use OC\Updater; use OCP\IConfig; -use OCP\ILogger; class UpdaterTest extends TestCase { - /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|MockObject */ private $config; - /** @var ILogger | \PHPUnit\Framework\MockObject\MockObject */ + /** @var LoggerInterface|MockObject */ private $logger; /** @var Updater */ private $updater; - /** @var Checker | \PHPUnit\Framework\MockObject\MockObject */ + /** @var Checker|MockObject */ private $checker; - /** @var Installer|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Installer|MockObject */ private $installer; protected function setUp(): void { @@ -45,7 +46,7 @@ class UpdaterTest extends TestCase { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->logger = $this->getMockBuilder(ILogger::class) + $this->logger = $this->getMockBuilder(LoggerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->checker = $this->getMockBuilder(Checker::class) diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 6e25ce16e75..e21a5323b1b 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -10,8 +10,6 @@ namespace Test; use OC_Util; use OCP\App\IAppManager; -use OCP\IConfig; -use OCP\IUser; /** * Class UtilTest @@ -172,53 +170,6 @@ class UtilTest extends \Test\TestCase { } /** - * @dataProvider dataProviderForTestIsSharingDisabledForUser - * @param array $groups existing groups - * @param array $membership groups the user belong to - * @param array $excludedGroups groups which should be excluded from sharing - * @param bool $expected expected result - */ - public function testIsSharingDisabledForUser($groups, $membership, $excludedGroups, $expected) { - $config = $this->getMockBuilder(IConfig::class)->disableOriginalConstructor()->getMock(); - $groupManager = $this->getMockBuilder('OCP\IGroupManager')->disableOriginalConstructor()->getMock(); - $user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock(); - - $config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('core', 'shareapi_exclude_groups', 'no') - ->willReturn('yes'); - $config - ->expects($this->at(1)) - ->method('getAppValue') - ->with('core', 'shareapi_exclude_groups_list') - ->willReturn(json_encode($excludedGroups)); - - $groupManager - ->expects($this->at(0)) - ->method('getUserGroupIds') - ->with($user) - ->willReturn($membership); - - $result = \OC_Util::isSharingDisabledForUser($config, $groupManager, $user); - - $this->assertSame($expected, $result); - } - - public function dataProviderForTestIsSharingDisabledForUser() { - return [ - // existing groups, groups the user belong to, groups excluded from sharing, expected result - [['g1', 'g2', 'g3'], [], ['g1'], false], - [['g1', 'g2', 'g3'], [], [], false], - [['g1', 'g2', 'g3'], ['g2'], ['g1'], false], - [['g1', 'g2', 'g3'], ['g2'], [], false], - [['g1', 'g2', 'g3'], ['g1', 'g2'], ['g1'], false], - [['g1', 'g2', 'g3'], ['g1', 'g2'], ['g1', 'g2'], true], - [['g1', 'g2', 'g3'], ['g1', 'g2'], ['g1', 'g2', 'g3'], true], - ]; - } - - /** * Test default apps * * @dataProvider defaultAppsProvider |