$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
$config = $c->getConfig();
$cacheFactory = $c->getMemCacheFactory();
+ $request = $c->getRequest();
return new \OC\URLGenerator(
$config,
- $cacheFactory
+ $cacheFactory,
+ $request
);
});
$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
$this->registerAlias('UserCache', \OCP\ICache::class);
$this->registerService(Factory::class, function (Server $c) {
+
$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
'\\OC\\Memcache\\ArrayCache',
'\\OC\\Memcache\\ArrayCache',
'\\OC\\Memcache\\ArrayCache'
);
$config = $c->getConfig();
- $urlGenerator = new URLGenerator($config, $arrayCacheFactory);
+ $request = $c->getRequest();
+ $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
$v = \OC_App::getAppVersions();
namespace Test;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IURLGenerator;
/**
* Class UrlGeneratorTest
*/
class UrlGeneratorTest extends \Test\TestCase {
+ /** @var \PHPUnit_Framework_MockObject_MockObject|IConfig */
+ private $config;
+ /** @var \PHPUnit_Framework_MockObject_MockObject|ICacheFactory */
+ private $cacheFactory;
+ /** @var \PHPUnit_Framework_MockObject_MockObject|IRequest */
+ private $request;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ public function setUp() {
+ parent::setUp();
+ $this->config = $this->createMock(IConfig::class);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->urlGenerator = new \OC\URLGenerator(
+ $this->config,
+ $this->cacheFactory,
+ $this->request
+ );
+ }
+
+ private function mockBaseUrl() {
+ $this->request->expects($this->once())
+ ->method('getServerProtocol')
+ ->willReturn('http');
+ $this->request->expects($this->once())
+ ->method('getServerHost')
+ ->willReturn('localhost');
+
+ }
+
/**
* @small
* test linkTo URL construction
*/
public function testLinkToDocRoot($app, $file, $args, $expectedResult) {
\OC::$WEBROOT = '';
- $config = $this->createMock(IConfig::class);
- $cacheFactory = $this->createMock(ICacheFactory::class);
- $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
- $result = $urlGenerator->linkTo($app, $file, $args);
-
+ $result = $this->urlGenerator->linkTo($app, $file, $args);
$this->assertEquals($expectedResult, $result);
}
*/
public function testLinkToSubDir($app, $file, $args, $expectedResult) {
\OC::$WEBROOT = '/owncloud';
- $config = $this->createMock(IConfig::class);
- $cacheFactory = $this->createMock(ICacheFactory::class);
- $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
- $result = $urlGenerator->linkTo($app, $file, $args);
-
+ $result = $this->urlGenerator->linkTo($app, $file, $args);
$this->assertEquals($expectedResult, $result);
}
* @dataProvider provideRoutes
*/
public function testLinkToRouteAbsolute($route, $expected) {
+ $this->mockBaseUrl();
\OC::$WEBROOT = '/owncloud';
- $config = $this->createMock(IConfig::class);
- $cacheFactory = $this->createMock(ICacheFactory::class);
- $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
- $result = $urlGenerator->linkToRouteAbsolute($route);
+ $result = $this->urlGenerator->linkToRouteAbsolute($route);
$this->assertEquals($expected, $result);
-
}
public function provideRoutes() {
* @dataProvider provideDocRootURLs
*/
function testGetAbsoluteURLDocRoot($url, $expectedResult) {
-
+ $this->mockBaseUrl();
\OC::$WEBROOT = '';
- $config = $this->createMock(IConfig::class);
- $cacheFactory = $this->createMock(ICacheFactory::class);
- $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
- $result = $urlGenerator->getAbsoluteURL($url);
-
+ $result = $this->urlGenerator->getAbsoluteURL($url);
$this->assertEquals($expectedResult, $result);
}
* @dataProvider provideSubDirURLs
*/
function testGetAbsoluteURLSubDir($url, $expectedResult) {
-
+ $this->mockBaseUrl();
\OC::$WEBROOT = '/owncloud';
- $config = $this->createMock(IConfig::class);
- $cacheFactory = $this->createMock(ICacheFactory::class);
- $urlGenerator = new \OC\URLGenerator($config, $cacheFactory);
- $result = $urlGenerator->getAbsoluteURL($url);
-
+ $result = $this->urlGenerator->getAbsoluteURL($url);
$this->assertEquals($expectedResult, $result);
}
array("apps/index.php", "http://localhost/owncloud/apps/index.php"),
);
}
+
+ public function testGetBaseUrl() {
+ $this->mockBaseUrl();
+ \OC::$WEBROOT = '/nextcloud';
+ $actual = $this->urlGenerator->getBaseUrl();
+ $expected = "http://localhost/nextcloud";
+ $this->assertEquals($expected, $actual);
+ }
+
}