[null]; yield 'empty X-NC-WebDAV-Auto-Mkcol header' => ['']; yield 'invalid X-NC-WebDAV-Auto-Mkcol header' => ['enable']; } public function testBeforeMethodWithRootNodeNotAnICollectionShouldReturnTrue(): void { $this->request->method('getHeader')->willReturn('1'); $this->request->expects(self::once()) ->method('getPath') ->willReturn('/non-relevant/path.txt'); $this->tree->expects(self::once()) ->method('nodeExists') ->with('/non-relevant') ->willReturn(false); $mockNode = $this->getMockBuilder(INode::class); $this->tree->expects(self::once()) ->method('getNodeForPath') ->willReturn($mockNode); $return = $this->plugin->beforeMethod($this->request, $this->response); $this->assertTrue($return); } #[\PHPUnit\Framework\Attributes\DataProvider('dataMissingHeaderShouldReturnTrue')] public function testBeforeMethodWithMissingHeaderShouldReturnTrue(?string $header): void { $this->request->expects(self::once()) ->method('getHeader') ->with('X-NC-WebDAV-Auto-Mkcol') ->willReturn($header); $this->request->expects(self::never()) ->method('getPath'); $return = $this->plugin->beforeMethod($this->request, $this->response); self::assertTrue($return); } public function testBeforeMethodWithExistingPathShouldReturnTrue(): void { $this->request->method('getHeader')->willReturn('1'); $this->request->expects(self::once()) ->method('getPath') ->willReturn('/files/user/deep/image.jpg'); $this->tree->expects(self::once()) ->method('nodeExists') ->with('/files/user/deep') ->willReturn(true); $this->tree->expects(self::never()) ->method('getNodeForPath'); $return = $this->plugin->beforeMethod($this->request, $this->response); self::assertTrue($return); } public function testBeforeMethodShouldSucceed(): void { $this->request->method('getHeader')->willReturn('1'); $this->request->expects(self::once()) ->method('getPath') ->willReturn('/files/user/my/deep/path/image.jpg'); $this->tree->expects(self::once()) ->method('nodeExists') ->with('/files/user/my/deep/path') ->willReturn(false); $mockNode = $this->createMock(ICollection::class); $this->tree->expects(self::once()) ->method('getNodeForPath') ->with('/files') ->willReturn($mockNode); $mockNode->expects(self::exactly(4)) ->method('childExists') ->willReturnMap([ ['user', true], ['my', true], ['deep', false], ['path', false], ]); $mockNode->expects(self::exactly(2)) ->method('createDirectory'); $mockNode->expects(self::exactly(4)) ->method('getChild') ->willReturn($mockNode); $return = $this->plugin->beforeMethod($this->request, $this->response); self::assertTrue($return); } protected function setUp(): void { parent::setUp(); $server = $this->createMock(Server::class); $this->tree = $this->createMock(Tree::class); $server->tree = $this->tree; $this->plugin = new UploadAutoMkcolPlugin(); $this->request = $this->createMock(RequestInterface::class); $this->response = $this->createMock(ResponseInterface::class); $server->httpRequest = $this->request; $server->httpResponse = $this->response; $this->plugin->initialize($server); } }