diff options
Diffstat (limited to 'tests')
4 files changed, 91 insertions, 40 deletions
diff --git a/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php new file mode 100644 index 00000000000..cd2332b0588 --- /dev/null +++ b/tests/lib/AppFramework/Bootstrap/FunctionInjectorTest.php @@ -0,0 +1,84 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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 lib\AppFramework\Bootstrap; + +use OC\AppFramework\Bootstrap\FunctionInjector; +use OC\AppFramework\Utility\SimpleContainer; +use Test\TestCase; + +interface Foo { +} + +class FunctionInjectorTest extends TestCase { + + /** @var SimpleContainer */ + private $container; + + protected function setUp(): void { + parent::setUp(); + + $this->container = new SimpleContainer(); + } + + public function testInjectFnNotRegistered(): void { + $this->expectException(\OCP\AppFramework\QueryException::class); + + (new FunctionInjector($this->container))->injectFn(static function (Foo $p1): void { + }); + } + + public function testInjectFnNotRegisteredButNullable(): void { + (new FunctionInjector($this->container))->injectFn(static function (?Foo $p1): void { + }); + + // Nothing to assert. No errors means everything is fine. + $this->addToAssertionCount(1); + } + + public function testInjectFnByType(): void { + $this->container->registerService(Foo::class, function () { + $this->addToAssertionCount(1); + return new class implements Foo { + }; + }); + + (new FunctionInjector($this->container))->injectFn(static function (Foo $p1): void { + }); + + // Nothing to assert. No errors means everything is fine. + $this->addToAssertionCount(1); + } + + public function testInjectFnByName(): void { + $this->container->registerParameter('test', 'abc'); + + (new FunctionInjector($this->container))->injectFn(static function ($test): void { + }); + + // Nothing to assert. No errors means everything is fine. + $this->addToAssertionCount(1); + } +} diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 306ee9f841c..69f1aa5d547 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -535,7 +535,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { new StrictCookieMissingException() ); - $expected = new RedirectResponse(\OC::$WEBROOT); + $expected = new RedirectResponse(\OC::$WEBROOT . '/'); $this->assertEquals($expected , $response); } diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php index f8a43058305..36fa1febfcf 100644 --- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php +++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /** * ownCloud - App Framework * @@ -67,13 +69,14 @@ class SimpleContainerTest extends \Test\TestCase { } + public function testRegister() { $this->container->registerParameter('test', 'abc'); $this->assertEquals('abc', $this->container->query('test')); } - + public function testNothingRegistered() { $this->expectException(\OCP\AppFramework\QueryException::class); @@ -81,7 +84,7 @@ class SimpleContainerTest extends \Test\TestCase { } - + public function testNotAClass() { $this->expectException(\OCP\AppFramework\QueryException::class); @@ -190,7 +193,7 @@ class SimpleContainerTest extends \Test\TestCase { $this->assertEquals('abc', $this->container->query($query)); } - + public function testConstructorComplexNoTestParameterFound() { $this->expectException(\OCP\AppFramework\QueryException::class); diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php index 38d3d611bb8..69c2833433d 100644 --- a/tests/lib/TagsTest.php +++ b/tests/lib/TagsTest.php @@ -24,7 +24,6 @@ namespace Test; use OCP\IUser; use OCP\IUserSession; -use OCP\Share\IShare; /** * Class TagsTest @@ -287,39 +286,4 @@ class TagsTest extends \Test\TestCase { $this->assertTrue($tagger->removeFromFavorites(1)); $this->assertEquals([], $tagger->getFavorites()); } - - public function testShareTags() { - $testTag = 'TestTag'; - \OC\Share\Share::registerBackend('test', 'Test\Share\Backend'); - - $tagger = $this->tagMgr->load('test'); - $tagger->tagAs(1, $testTag); - - - $otherUserId = $this->getUniqueID('user2_'); - $otherUser = $this->createMock(IUser::class); - $otherUser->method('getUID') - ->willReturn($otherUserId); - - \OC::$server->getUserManager()->createUser($otherUserId, 'pass'); - \OC_User::setUserId($otherUserId); - $otherUserSession = $this->createMock(IUserSession::class); - $otherUserSession - ->expects($this->any()) - ->method('getUser') - ->willReturn($otherUser); - - $otherTagMgr = new \OC\TagManager($this->tagMapper, $otherUserSession); - $otherTagger = $otherTagMgr->load('test'); - $this->assertFalse($otherTagger->hasTag($testTag)); - - \OC_User::setUserId($this->user->getUID()); - // TODO new sharing - \OC\Share\Share::shareItem('test', 1, IShare::TYPE_USER, $otherUserId, \OCP\Constants::PERMISSION_READ); - - \OC_User::setUserId($otherUserId); - $otherTagger = $otherTagMgr->load('test', [], true); // Update tags, load shared ones. - $this->assertTrue($otherTagger->hasTag($testTag)); - $this->assertContains(1, $otherTagger->getIdsForTag($testTag)); - } } |