@@ -803,10 +803,6 @@ private function getOpenProjectAPIService(
803803 $ appManagerMock ->method ('isInstalled ' )->willReturn (true );
804804 }
805805
806- $ urlGeneratorMock = $ this ->getMockBuilder (IURLGenerator::class)->getMock ();
807- $ urlGeneratorMock
808- ->method ('getBaseUrl ' )
809- ->willReturn ($ baseUrl );
810806 $ this ->defaultConfigMock
811807 ->method ('getSystemValueString ' )
812808 ->with ($ this ->equalTo ('overwrite.cli.url ' ))
@@ -817,7 +813,6 @@ private function getOpenProjectAPIService(
817813 'config ' => $ this ->defaultConfigMock ,
818814 'clientService ' => $ clientService ,
819815 'rootFolder ' => $ storageMock ,
820- 'urlGenerator ' => $ urlGeneratorMock ,
821816 'appManager ' => $ appManagerMock ,
822817 'tokenEventFactory ' => $ exchangeTokenMock ,
823818 ]);
@@ -831,21 +826,27 @@ private function getOpenProjectAPIService(
831826 *
832827 * @param array<string> $mockMethods
833828 * @param array<string, object> $constructParams
829+ * @param bool $mockBaseUrl
834830 *
835831 * @return OpenProjectAPIService|MockObject
836832 */
837833 private function getOpenProjectAPIServiceMock (
838834 array $ mockMethods = ['request ' ],
839835 array $ constructParams = [],
836+ bool $ mockBaseUrl = true
840837 ): OpenProjectAPIService |MockObject {
841- $ mockMethods [] = 'getBaseUrl ' ;
838+ if ($ mockBaseUrl ) {
839+ $ mockMethods [] = 'getNCBaseUrl ' ;
840+ }
842841 $ constructArgs = $ this ->getOpenProjectAPIServiceConstructArgs ($ constructParams );
843842
844843 $ mock = $ this ->getMockBuilder (OpenProjectAPIService::class)
845844 ->setConstructorArgs ($ constructArgs )
846845 ->onlyMethods ($ mockMethods )
847846 ->getMock ();
848- $ mock ->method ('getBaseUrl ' )->willReturn ('https://nc.my-server.org ' );
847+ if ($ mockBaseUrl ) {
848+ $ mock ->method ('getNCBaseUrl ' )->willReturn ('https://nc.my-server.org ' );
849+ }
849850 return $ mock ;
850851 }
851852
@@ -3906,14 +3907,7 @@ public function testGetAvailableOpenProjectProjectsErrorResponse(): void {
39063907 * @return void
39073908 */
39083909 public function testGetAvailableOpenProjectProjectsQueryOnly () {
3909- $ iUrlGeneratorMock = $ this ->getMockBuilder (IURLGenerator::class)->disableOriginalConstructor ()->getMock ();
3910- $ iUrlGeneratorMock ->method ('getBaseUrl ' )->willReturn ('https%3A%2F%2Fnc.my-server.org ' );
3911- $ service = $ this ->getOpenProjectAPIServiceMock (
3912- ['request ' ],
3913- [
3914- 'urlGenerator ' => $ iUrlGeneratorMock ,
3915- ],
3916- );
3910+ $ service = $ this ->getOpenProjectAPIServiceMock (['request ' ]);
39173911 $ service ->method ('request ' )
39183912 ->with (
39193913 'user ' , 'work_packages/available_projects ' ,
@@ -5197,4 +5191,52 @@ public function testGetAppsName(string $appId, ?array $appInfo, string $expected
51975191 $ this ->assertSame ($ expected , $ result );
51985192 }
51995193
5194+ /**
5195+ * @return array<mixed>
5196+ */
5197+ public function getNCBaseUrlDataProvider () {
5198+ return [
5199+ 'HTTP url ' => [
5200+ 'url ' => 'http://test.nc.local ' ,
5201+ 'expected ' => 'https://test.nc.local ' ,
5202+ ],
5203+ 'HTTPS url ' => [
5204+ 'url ' => 'https://test.nc.local ' ,
5205+ 'expected ' => 'https://test.nc.local ' ,
5206+ ],
5207+ 'invalid url ' => [
5208+ 'url ' => 'invalid_url ' ,
5209+ 'expected ' => '' ,
5210+ ],
5211+ 'empty url ' => [
5212+ 'url ' => '' ,
5213+ 'expected ' => '' ,
5214+ ],
5215+ ];
5216+ }
5217+
5218+ /**
5219+ * @dataProvider getNCBaseUrlDataProvider
5220+ * @param string $url
5221+ * @param string $expected
5222+ * @return void
5223+ */
5224+ public function testGetNCBaseUrl (string $ url , string $ expected ): void {
5225+ $ configMock = $ this ->createMock (IConfig::class);
5226+ $ configMock
5227+ ->method ('getSystemValueString ' )
5228+ ->with ($ this ->equalTo ('overwrite.cli.url ' ))
5229+ ->willReturn ($ url );
5230+
5231+ $ service = $ this ->getOpenProjectAPIServiceMock (
5232+ [],
5233+ [
5234+ 'config ' => $ configMock ,
5235+ ],
5236+ false ,
5237+ );
5238+
5239+ $ baseUrl = $ service ->getNCBaseUrl ();
5240+ $ this ->assertEquals ($ expected , $ baseUrl );
5241+ }
52005242}
0 commit comments