Browse Source

Match \OC_Helper::linkToPublic() to new links and fit unittests

tags/v8.0.0alpha1
kondou 9 years ago
parent
commit
ecc9b42e41
2 changed files with 28 additions and 10 deletions
  1. 6
    6
      lib/private/helper.php
  2. 22
    4
      tests/lib/helper.php

+ 6
- 6
lib/private/helper.php View File

@@ -129,12 +129,12 @@ class OC_Helper {
* Returns a absolute url to the given service.
*/
public static function linkToPublic($service, $add_slash = false) {
return OC::$server->getURLGenerator()->getAbsoluteURL(
self::linkTo(
'', 'public.php') . '?service=' . $service
. (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : ''
)
);
if ($service === 'files') {
$url = OC::$server->getURLGenerator()->getAbsoluteURL('/s');
} else {
$url = OC::$server->getURLGenerator()->getAbsoluteURL(self::linkTo('', 'public.php').'?service='.$service);
}
return $url . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '');
}

/**

+ 22
- 4
tests/lib/helper.php View File

@@ -443,15 +443,33 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
public function testLinkToPublic() {
\OC::$WEBROOT = '';
$result = \OC_Helper::linkToPublic('files');
$this->assertEquals('http://localhost/public.php?service=files', $result);
$this->assertEquals('http://localhost/s', $result);
$result = \OC_Helper::linkToPublic('files', false);
$this->assertEquals('http://localhost/public.php?service=files', $result);
$this->assertEquals('http://localhost/s', $result);
$result = \OC_Helper::linkToPublic('files', true);
$this->assertEquals('http://localhost/s/', $result);

$result = \OC_Helper::linkToPublic('other');
$this->assertEquals('http://localhost/public.php?service=other', $result);
$result = \OC_Helper::linkToPublic('other', false);
$this->assertEquals('http://localhost/public.php?service=other', $result);
$result = \OC_Helper::linkToPublic('other', true);
$this->assertEquals('http://localhost/public.php?service=other/', $result);

\OC::$WEBROOT = '/owncloud';
$result = \OC_Helper::linkToPublic('files');
$this->assertEquals('http://localhost/owncloud/public.php?service=files', $result);
$this->assertEquals('http://localhost/owncloud/s', $result);
$result = \OC_Helper::linkToPublic('files', false);
$this->assertEquals('http://localhost/owncloud/public.php?service=files', $result);
$this->assertEquals('http://localhost/owncloud/s', $result);
$result = \OC_Helper::linkToPublic('files', true);
$this->assertEquals('http://localhost/owncloud/s/', $result);

$result = \OC_Helper::linkToPublic('other');
$this->assertEquals('http://localhost/owncloud/public.php?service=other', $result);
$result = \OC_Helper::linkToPublic('other', false);
$this->assertEquals('http://localhost/owncloud/public.php?service=other', $result);
$result = \OC_Helper::linkToPublic('other', true);
$this->assertEquals('http://localhost/owncloud/public.php?service=other/', $result);
}

/**

Loading…
Cancel
Save