[ 'user', true, 'PERMISSIONS', true, 2 ], 'permissions only' => [ null, false, 'PERMISSIONS', true, 1 ], ]; } public function testAfterPutNotFoundException(): void { $afterPut = null; $this->server->expects($this->once()) ->method('on') ->willReturnCallback( function ($method, $callback) use (&$afterPut): void { $this->assertSame('afterMethod:PUT', $method); $afterPut = $callback; }); $this->plugin->initialize($this->server); $node = $this->createMock(Node::class); $this->tree->expects($this->once())->method('getNodeForPath') ->willThrowException(new NotFound()); $this->logger->expects($this->once())->method('error'); $afterPut($this->request, $this->response); } #[DataProvider('afterPutData')] public function testAfterPut(?string $ownerId, bool $expectOwnerIdHeader, ?string $permissions, bool $expectPermissionsHeader, int $expectedInvocations): void { $afterPut = null; $this->server->expects($this->once()) ->method('on') ->willReturnCallback( function ($method, $callback) use (&$afterPut): void { $this->assertSame('afterMethod:PUT', $method); $afterPut = $callback; }); $this->plugin->initialize($this->server); $node = $this->createMock(Node::class); $this->tree->expects($this->once())->method('getNodeForPath') ->willReturn($node); $user = $this->createMock(IUser::class); $node->expects($this->once())->method('getOwner')->willReturn($user); $user->expects($this->once())->method('getUID')->willReturn($ownerId); $node->expects($this->once())->method('getDavPermissions')->willReturn($permissions); $matcher = $this->exactly($expectedInvocations); $this->response->expects($matcher)->method('setHeader') ->willReturnCallback(function ($name, $value) use ( $expectedInvocations, $expectPermissionsHeader, $expectOwnerIdHeader, $matcher, $ownerId, $permissions): void { $invocationNumber = $matcher->numberOfInvocations(); if ($invocationNumber === 0) { throw new LogicException('No invocations were expected'); } if (($expectOwnerIdHeader && $expectedInvocations === 1) || ($expectedInvocations === 2 && $invocationNumber === 1)) { $this->assertEquals('X-NC-OwnerId', $name); $this->assertEquals($ownerId, $value); } if (($expectPermissionsHeader && $expectedInvocations === 1) || ($expectedInvocations === 2 && $invocationNumber === 2)) { $this->assertEquals('X-NC-Permissions', $name); $this->assertEquals($permissions, $value); } }); $afterPut($this->request, $this->response); } protected function setUp(): void { parent::setUp(); $this->server = $this->createMock(Server::class); $this->tree = $this->createMock(Tree::class); $this->server->tree = $this->tree; $this->logger = $this->createMock(LoggerInterface::class); $this->plugin = new AddExtraHeadersPlugin($this->logger, false); $this->request = $this->createMock(RequestInterface::class); $this->response = $this->createMock(ResponseInterface::class); } }