diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-07-15 17:11:54 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-07-31 19:37:59 +0200 |
commit | 7b723813cef60e744ab14ab418c82e5ec67a9f2e (patch) | |
tree | eda4a044c9defc883c35d98e1ba5a9e261a3ecdf /apps/dav/tests | |
parent | ab1a20522b1b2730398869a764f672175a1abcb8 (diff) | |
download | nextcloud-server-7b723813cef60e744ab14ab418c82e5ec67a9f2e.tar.gz nextcloud-server-7b723813cef60e744ab14ab418c82e5ec67a9f2e.zip |
Multiple fixes
- Fix tests
- Use non deprecated event stuff
- Add a bit of type hinting to the new stuff
- More safe handling of instanceOfStorage (share might not be the first
wrapper)
- Fix resharing
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/Controller/DirectControllerTest.php | 26 | ||||
-rw-r--r-- | apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php | 11 |
2 files changed, 22 insertions, 15 deletions
diff --git a/apps/dav/tests/unit/Controller/DirectControllerTest.php b/apps/dav/tests/unit/Controller/DirectControllerTest.php index 00771e7f7a6..fe6d4ea8f24 100644 --- a/apps/dav/tests/unit/Controller/DirectControllerTest.php +++ b/apps/dav/tests/unit/Controller/DirectControllerTest.php @@ -34,11 +34,12 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\IRequest; -use OCP\IURLGenerator; +use OCP\IUrlGenerator; use OCP\Security\ISecureRandom; use Test\TestCase; @@ -56,11 +57,13 @@ class DirectControllerTest extends TestCase { /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ private $timeFactory; - /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUrlGenerator|\PHPUnit\Framework\MockObject\MockObject */ private $urlGenerator; - /** @var DirectController */ - private $controller; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + private $eventDispatcher; + + private DirectController $controller; protected function setUp(): void { parent::setUp(); @@ -69,7 +72,8 @@ class DirectControllerTest extends TestCase { $this->directMapper = $this->createMock(DirectMapper::class); $this->random = $this->createMock(ISecureRandom::class); $this->timeFactory = $this->createMock(ITimeFactory::class); - $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->urlGenerator = $this->createMock(IUrlGenerator::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->controller = new DirectController( 'dav', @@ -79,11 +83,12 @@ class DirectControllerTest extends TestCase { $this->directMapper, $this->random, $this->timeFactory, - $this->urlGenerator + $this->urlGenerator, + $this->eventDispatcher ); } - public function testGetUrlNonExistingFileId() { + public function testGetUrlNonExistingFileId(): void { $userFolder = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') @@ -97,7 +102,7 @@ class DirectControllerTest extends TestCase { $this->controller->getUrl(101); } - public function testGetUrlForFolder() { + public function testGetUrlForFolder(): void { $userFolder = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') @@ -113,7 +118,7 @@ class DirectControllerTest extends TestCase { $this->controller->getUrl(101); } - public function testGetUrlValid() { + public function testGetUrlValid(): void { $userFolder = $this->createMock(Folder::class); $this->rootFolder->method('getUserFolder') ->with('awesomeUser') @@ -128,6 +133,9 @@ class DirectControllerTest extends TestCase { ->with(101) ->willReturn([$file]); + $userFolder->method('getRelativePath') + ->willReturn('/path'); + $this->random->method('generate') ->with( 60, diff --git a/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php b/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php index 3bd7a2d6dde..f86a60fb4bf 100644 --- a/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php +++ b/apps/dav/tests/unit/DAV/ViewOnlyPluginTest.php @@ -36,8 +36,7 @@ use OCA\DAV\Connector\Sabre\Exception\Forbidden; class ViewOnlyPluginTest extends TestCase { - /** @var ViewOnlyPlugin */ - private $plugin; + private ViewOnlyPlugin $plugin; /** @var Tree | \PHPUnit\Framework\MockObject\MockObject */ private $tree; /** @var RequestInterface | \PHPUnit\Framework\MockObject\MockObject */ @@ -56,14 +55,14 @@ class ViewOnlyPluginTest extends TestCase { $this->plugin->initialize($server); } - public function testCanGetNonDav() { + public function testCanGetNonDav(): void { $this->request->expects($this->once())->method('getPath')->willReturn('files/test/target'); $this->tree->method('getNodeForPath')->willReturn(null); $this->assertTrue($this->plugin->checkViewOnly($this->request)); } - public function testCanGetNonShared() { + public function testCanGetNonShared(): void { $this->request->expects($this->once())->method('getPath')->willReturn('files/test/target'); $davNode = $this->createMock(DavFile::class); $this->tree->method('getNodeForPath')->willReturn($davNode); @@ -78,7 +77,7 @@ class ViewOnlyPluginTest extends TestCase { $this->assertTrue($this->plugin->checkViewOnly($this->request)); } - public function providesDataForCanGet() { + public function providesDataForCanGet(): array { return [ // has attribute permissions-download enabled - can get file [ $this->createMock(File::class), true, true], @@ -92,7 +91,7 @@ class ViewOnlyPluginTest extends TestCase { /** * @dataProvider providesDataForCanGet */ - public function testCanGet($nodeInfo, $attrEnabled, $expectCanDownloadFile) { + public function testCanGet(File $nodeInfo, ?bool $attrEnabled, bool $expectCanDownloadFile): void { $this->request->expects($this->once())->method('getPath')->willReturn('files/test/target'); $davNode = $this->createMock(DavFile::class); |