diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index 2c6e93084..a18ae2e6b 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -1755,7 +1755,16 @@ public function testProjectFolderHasAppPassword(): void { ->method('getTokenByUser') ->with(Application::OPEN_PROJECT_ENTITIES_NAME) ->willReturn([$tokenMock]); - $service = $this->getServiceMock([], null, null, null, null, null, null, null, null, $tokenProviderMock); + $service = $this->getServiceMock([], + null, + null, + null, + null, + null, + null, + null, + null, + $tokenProviderMock); $this->assertTrue($service->hasAppPassword()); } @@ -1765,24 +1774,33 @@ public function testProjectFolderHasMultipleAppPassword(): void { $tokenMock1 = $this->getMockBuilder(IToken::class)->getMock(); $tokenMock1 ->method('getName') - ->willReturnOnConsecutiveCalls('session'); + ->willReturn('session'); $tokenMock2 = $this->getMockBuilder(IToken::class)->getMock(); $tokenMock2 ->method('getName') - ->willReturnOnConsecutiveCalls('test'); + ->willReturn('test'); $tokenMock3 = $this->getMockBuilder(IToken::class)->getMock(); $tokenMock3 ->method('getName') - ->willReturnOnConsecutiveCalls('new-token'); + ->willReturn('new-token'); $tokenMock4 = $this->getMockBuilder(IToken::class)->getMock(); $tokenMock4 ->method('getName') - ->willReturnOnConsecutiveCalls('OpenProject'); + ->willReturn('OpenProject'); $tokenProviderMock ->method('getTokenByUser') ->with(Application::OPEN_PROJECT_ENTITIES_NAME) ->willReturn([$tokenMock1,$tokenMock2,$tokenMock3,$tokenMock4]); - $service = $this->getServiceMock([], null, null, null, null, null, null, null, null, $tokenProviderMock); + $service = $this->getServiceMock([], + null, + null, + null, + null, + null, + null, + null, + null, + $tokenProviderMock); $this->assertTrue($service->hasAppPassword()); } @@ -1797,10 +1815,79 @@ public function testProjectFolderHasAppPasswordNegativeCondition(): void { ->method('getTokenByUser') ->with(Application::OPEN_PROJECT_ENTITIES_NAME) ->willReturn([$tokenMock]); - $service = $this->getServiceMock([], null, null, null, null, null, null, null, null, $tokenProviderMock); + $service = $this->getServiceMock([], + null, + null, + null, + null, + null, + null, + null, + null, + $tokenProviderMock); $this->assertFalse($service->hasAppPassword()); } + public function testProjectFolderDeleteAppPassword(): void { + $tokenProviderMock = $this->getMockBuilder(IProvider::class)->disableOriginalConstructor() + ->getMock(); + $tokenMock1 = $this->getMockBuilder(IToken::class)->getMock(); + $tokenMock1 + ->method('getName') + ->willReturn('session'); + $tokenMock1 + ->method('getId') + ->willReturn(1); + $tokenMock2 = $this->getMockBuilder(IToken::class)->getMock(); + $tokenMock2 + ->method('getName') + ->willReturn('test'); + $tokenMock2 + ->method('getId') + ->willReturn(2); + $tokenMock3 = $this->getMockBuilder(IToken::class)->getMock(); + $tokenMock3 + ->method('getName') + ->willReturn('new-token'); + $tokenMock3 + ->method('getId') + ->willReturn(3); + $tokenMock4 = $this->getMockBuilder(IToken::class)->getMock(); + $tokenMock4 + ->method('getName') + ->willReturn('OpenProject'); + $tokenMock4 + ->method('getId') + ->willReturn(4); + $tokenMock5 = $this->getMockBuilder(IToken::class)->getMock(); + $tokenMock5 + ->method('getName') + ->willReturn('OpenProject'); + $tokenMock5 + ->method('getId') + ->willReturn(5); + $tokenProviderMock + ->method('getTokenByUser') + ->with(Application::OPEN_PROJECT_ENTITIES_NAME) + ->willReturn([$tokenMock1,$tokenMock2,$tokenMock3,$tokenMock4,$tokenMock5]); + $service = $this->getServiceMock(['hasAppPassword'], + null, + null, + null, + null, + null, + null, + null, + null, + $tokenProviderMock) + ; + $service->method('hasAppPassword')->willReturn(true); + $tokenProviderMock->expects($this->exactly(2)) + ->method('invalidateTokenById') + ->withConsecutive([Application::OPEN_PROJECT_ENTITIES_NAME, 4], [Application::OPEN_PROJECT_ENTITIES_NAME, 5]); + $service->deleteAppPassword(); + } + public function testLinkWorkPackageToFilePact(): void { $consumerRequest = new ConsumerRequest(); $consumerRequest