12
12
use OCP \IConfig ;
13
13
use OCP \IRequest ;
14
14
use OCP \IURLGenerator ;
15
+ use OCP \Route \IRouter ;
15
16
16
17
/**
17
18
* Class UrlGeneratorTest
19
+ *
20
+ * @package Test
18
21
*/
19
22
class UrlGeneratorTest extends \Test \TestCase {
20
23
@@ -24,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase {
24
27
private $ cacheFactory ;
25
28
/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
26
29
private $ request ;
30
+ /** @var \PHPUnit\Framework\MockObject\MockObject|IRouter */
31
+ private $ router ;
27
32
/** @var IURLGenerator */
28
33
private $ urlGenerator ;
29
34
/** @var string */
@@ -34,10 +39,12 @@ protected function setUp(): void {
34
39
$ this ->config = $ this ->createMock (IConfig::class);
35
40
$ this ->cacheFactory = $ this ->createMock (ICacheFactory::class);
36
41
$ this ->request = $ this ->createMock (IRequest::class);
42
+ $ this ->router = $ this ->createMock (IRouter::class);
37
43
$ this ->urlGenerator = new \OC \URLGenerator (
38
44
$ this ->config ,
39
45
$ this ->cacheFactory ,
40
- $ this ->request
46
+ $ this ->request ,
47
+ $ this ->router
41
48
);
42
49
$ this ->originalWebRoot = \OC ::$ WEBROOT ;
43
50
}
@@ -84,14 +91,23 @@ public function testLinkToSubDir($app, $file, $args, $expectedResult) {
84
91
public function testLinkToRouteAbsolute ($ route , $ expected ) {
85
92
$ this ->mockBaseUrl ();
86
93
\OC ::$ WEBROOT = '/nextcloud ' ;
94
+ $ this ->router ->expects ($ this ->once ())
95
+ ->method ('generate ' )
96
+ ->willReturnCallback (function ($ routeName , $ parameters ) {
97
+ if ($ routeName === 'core.Preview.getPreview ' ) {
98
+ return '/index.php/core/preview.png ' ;
99
+ } elseif ($ routeName === 'cloud_federation_api.requesthandlercontroller.addShare ' ) {
100
+ return '/index.php/ocm/shares ' ;
101
+ }
102
+ });
87
103
$ result = $ this ->urlGenerator ->linkToRouteAbsolute ($ route );
88
104
$ this ->assertEquals ($ expected , $ result );
89
105
}
90
106
91
107
public function provideRoutes () {
92
108
return [
93
- ['files_ajax_list ' , 'http://localhost/nextcloud/index.php/apps/files/ajax/list.php ' ],
94
109
['core.Preview.getPreview ' , 'http://localhost/nextcloud/index.php/core/preview.png ' ],
110
+ ['cloud_federation_api.requesthandlercontroller.addShare ' , 'http://localhost/nextcloud/index.php/ocm/shares ' ],
95
111
];
96
112
}
97
113
@@ -169,6 +185,15 @@ public function testGetBaseUrl() {
169
185
public function testLinkToOCSRouteAbsolute (string $ route , string $ expected ) {
170
186
$ this ->mockBaseUrl ();
171
187
\OC ::$ WEBROOT = '/nextcloud ' ;
188
+ $ this ->router ->expects ($ this ->once ())
189
+ ->method ('generate ' )
190
+ ->willReturnCallback (function ($ routeName , $ parameters ) {
191
+ if ($ routeName === 'ocs.core.OCS.getCapabilities ' ) {
192
+ return '/index.php/ocsapp/cloud/capabilities ' ;
193
+ } elseif ($ routeName === 'ocs.core.WhatsNew.dismiss ' ) {
194
+ return '/index.php/ocsapp/core/whatsnew ' ;
195
+ }
196
+ });
172
197
$ result = $ this ->urlGenerator ->linkToOCSRouteAbsolute ($ route );
173
198
$ this ->assertEquals ($ expected , $ result );
174
199
}
0 commit comments