summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/App/CodeChecker/InfoCheckerTest.php10
-rw-r--r--tests/lib/Settings/Admin/AdditionalTest.php2
-rw-r--r--tests/lib/Settings/Admin/EncryptionTest.php4
-rw-r--r--tests/lib/Settings/Admin/ServerTest.php2
-rw-r--r--tests/lib/Settings/Admin/SharingTest.php4
-rw-r--r--tests/lib/Settings/Admin/TipsTricksTest.php4
-rw-r--r--tests/lib/Settings/ManagerTest.php127
-rw-r--r--tests/lib/Share20/ManagerTest.php49
-rw-r--r--tests/lib/Template/SCSSCacherTest.php51
-rw-r--r--tests/lib/UrlGeneratorTest.php77
10 files changed, 239 insertions, 91 deletions
diff --git a/tests/lib/App/CodeChecker/InfoCheckerTest.php b/tests/lib/App/CodeChecker/InfoCheckerTest.php
index c16874fbd33..760d9880739 100644
--- a/tests/lib/App/CodeChecker/InfoCheckerTest.php
+++ b/tests/lib/App/CodeChecker/InfoCheckerTest.php
@@ -50,10 +50,12 @@ class InfoCheckerTest extends TestCase {
public function appInfoData() {
return [
['testapp-infoxml', []],
- ['testapp-version', []],
- ['testapp-infoxml-version', []],
- ['testapp-infoxml-version-different', [['type' => 'differentVersions', 'message' => 'appinfo/version: 1.2.4 - appinfo/info.xml: 1.2.3']]],
- ['testapp-version-missing', []],
+ ['testapp-version', [['type' => 'mandatoryFieldMissing', 'field' => 'version']]],
+ ['testapp-dependency-missing', [
+ ['type' => 'missingRequirement', 'field' => 'min'],
+ ['type' => 'missingRequirement', 'field' => 'max'],
+ ['type' => 'mandatoryFieldMissing', 'field' => 'dependencies'],
+ ]],
['testapp-name-missing', [['type' => 'mandatoryFieldMissing', 'field' => 'name']]],
];
}
diff --git a/tests/lib/Settings/Admin/AdditionalTest.php b/tests/lib/Settings/Admin/AdditionalTest.php
index 420a7110c13..84c63f3aeb1 100644
--- a/tests/lib/Settings/Admin/AdditionalTest.php
+++ b/tests/lib/Settings/Admin/AdditionalTest.php
@@ -97,7 +97,7 @@ class AdditionalTest extends TestCase {
$expected = new TemplateResponse(
'settings',
- 'admin/additional-mail',
+ 'settings/admin/additional-mail',
[
'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
'mail_domain' => 'mx.nextcloud.com',
diff --git a/tests/lib/Settings/Admin/EncryptionTest.php b/tests/lib/Settings/Admin/EncryptionTest.php
index a282b059c92..a5f483863e6 100644
--- a/tests/lib/Settings/Admin/EncryptionTest.php
+++ b/tests/lib/Settings/Admin/EncryptionTest.php
@@ -81,7 +81,7 @@ class EncryptionTest extends TestCase {
->willReturn(['entry']);
$expected = new TemplateResponse(
'settings',
- 'admin/encryption',
+ 'settings/admin/encryption',
[
'encryptionEnabled' => $enabled,
'encryptionReady' => $enabled,
@@ -116,7 +116,7 @@ class EncryptionTest extends TestCase {
->willReturn(['entry', 'entry']);
$expected = new TemplateResponse(
'settings',
- 'admin/encryption',
+ 'settings/admin/encryption',
[
'encryptionEnabled' => $enabled,
'encryptionReady' => $enabled,
diff --git a/tests/lib/Settings/Admin/ServerTest.php b/tests/lib/Settings/Admin/ServerTest.php
index f876ae85136..a71aef0178e 100644
--- a/tests/lib/Settings/Admin/ServerTest.php
+++ b/tests/lib/Settings/Admin/ServerTest.php
@@ -123,7 +123,7 @@ class ServerTest extends TestCase {
$envPath = getenv('PATH');
$expected = new TemplateResponse(
'settings',
- 'admin/server',
+ 'settings/admin/server',
[
// Diagnosis
'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
diff --git a/tests/lib/Settings/Admin/SharingTest.php b/tests/lib/Settings/Admin/SharingTest.php
index 0bf03559683..d9aa14fecea 100644
--- a/tests/lib/Settings/Admin/SharingTest.php
+++ b/tests/lib/Settings/Admin/SharingTest.php
@@ -112,7 +112,7 @@ class SharingTest extends TestCase {
$expected = new TemplateResponse(
'settings',
- 'admin/sharing',
+ 'settings/admin/sharing',
[
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
@@ -205,7 +205,7 @@ class SharingTest extends TestCase {
$expected = new TemplateResponse(
'settings',
- 'admin/sharing',
+ 'settings/admin/sharing',
[
'allowGroupSharing' => 'yes',
'allowLinks' => 'yes',
diff --git a/tests/lib/Settings/Admin/TipsTricksTest.php b/tests/lib/Settings/Admin/TipsTricksTest.php
index 0e8857b56d0..cbecd51ed55 100644
--- a/tests/lib/Settings/Admin/TipsTricksTest.php
+++ b/tests/lib/Settings/Admin/TipsTricksTest.php
@@ -52,7 +52,7 @@ class TipsTrickTest extends TestCase {
$expected = new TemplateResponse(
'settings',
- 'admin/tipstricks',
+ 'settings/admin/tipstricks',
[
'databaseOverload' => true,
],
@@ -71,7 +71,7 @@ class TipsTrickTest extends TestCase {
$expected = new TemplateResponse(
'settings',
- 'admin/tipstricks',
+ 'settings/admin/tipstricks',
[
'databaseOverload' => false,
],
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 07f7e71feca..6a13b737c8e 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -23,18 +23,23 @@
namespace Tests\Settings;
+use OC\Accounts\AccountManager;
use OC\Settings\Admin\Sharing;
use OC\Settings\Manager;
use OC\Settings\Mapper;
+use OC\Settings\Personal\Security;
use OC\Settings\Section;
+use OCP\App\IAppManager;
use OCP\Encryption\IManager;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use Test\TestCase;
@@ -61,6 +66,16 @@ class ManagerTest extends TestCase {
private $mapper;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $url;
+ /** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $accountManager;
+ /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $groupManager;
+ /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $l10nFactory;
+ /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */
+ private $defaults;
+ /** @var IAppManager */
+ private $appManager;
public function setUp() {
parent::setUp();
@@ -75,6 +90,11 @@ class ManagerTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->mapper = $this->createMock(Mapper::class);
$this->url = $this->createMock(IURLGenerator::class);
+ $this->accountManager = $this->createMock(AccountManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->l10nFactory = $this->createMock(IFactory::class);
+ $this->defaults = $this->createMock(\OC_Defaults::class);
+ $this->appManager = $this->createMock(IAppManager::class);
$this->manager = new Manager(
$this->logger,
@@ -86,21 +106,40 @@ class ManagerTest extends TestCase {
$this->lockingProvider,
$this->request,
$this->mapper,
- $this->url
+ $this->url,
+ $this->accountManager,
+ $this->groupManager,
+ $this->l10nFactory,
+ $this->defaults,
+ $this->appManager
);
}
- public function testSetupSettingsUpdate() {
+ public function settingsTypeProvider() {
+ return [
+ ['admin', 'admin_settings'],
+ ['personal', 'personal_settings'],
+ ];
+ }
+
+ /**
+ * @dataProvider settingsTypeProvider
+ * @param string $type
+ * @param string $table
+ */
+ public function testSetupSettingsUpdate($type, $table) {
+ $className = 'OCA\Files\Settings\Admin';
+
$this->mapper->expects($this->any())
->method('has')
- ->with('admin_settings', 'OCA\Files\Settings\Admin')
+ ->with($table, $className)
->will($this->returnValue(true));
$this->mapper->expects($this->once())
->method('update')
- ->with('admin_settings',
+ ->with($table,
'class',
- 'OCA\Files\Settings\Admin', [
+ $className, [
'section' => 'additional',
'priority' => 5
]);
@@ -108,19 +147,24 @@ class ManagerTest extends TestCase {
->method('add');
$this->manager->setupSettings([
- 'admin' => 'OCA\Files\Settings\Admin',
+ $type => $className,
]);
}
- public function testSetupSettingsAdd() {
+ /**
+ * @dataProvider settingsTypeProvider
+ * @param string $type
+ * @param string $table
+ */
+ public function testSetupSettingsAdd($type, $table) {
$this->mapper->expects($this->any())
->method('has')
- ->with('admin_settings', 'OCA\Files\Settings\Admin')
+ ->with($table, 'OCA\Files\Settings\Admin')
->will($this->returnValue(false));
$this->mapper->expects($this->once())
->method('add')
- ->with('admin_settings', [
+ ->with($table, [
'class' => 'OCA\Files\Settings\Admin',
'section' => 'additional',
'priority' => 5
@@ -130,7 +174,7 @@ class ManagerTest extends TestCase {
->method('update');
$this->manager->setupSettings([
- 'admin' => 'OCA\Files\Settings\Admin',
+ $type => 'OCA\Files\Settings\Admin',
]);
}
@@ -167,6 +211,34 @@ class ManagerTest extends TestCase {
], $this->manager->getAdminSections());
}
+ public function testGetPersonalSections() {
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnArgument(0));
+
+ $this->mapper->expects($this->once())
+ ->method('getPersonalSectionsFromDB')
+ ->will($this->returnValue([
+ ['class' => \OCA\WorkflowEngine\Settings\Section::class, 'priority' => 90]
+ ]));
+
+ $this->url->expects($this->exactly(3))
+ ->method('imagePath')
+ ->willReturnMap([
+ ['core', 'actions/info.svg', '1'],
+ ['settings', 'password.svg', '2'],
+ ['settings', 'change.svg', '3'],
+ ]);
+
+ $this->assertArraySubset([
+ 0 => [new Section('personal-info', 'Personal info', 0, '1')],
+ 5 => [new Section('security', 'Security', 0, '2')],
+ 15 => [new Section('sync-clients', 'Sync clients', 0, '3')],
+ 90 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)],
+ ], $this->manager->getPersonalSections());
+ }
+
public function testGetAdminSectionsEmptySection() {
$this->l10n
->expects($this->any())
@@ -198,6 +270,31 @@ class ManagerTest extends TestCase {
], $this->manager->getAdminSections());
}
+ public function testGetPersonalSectionsEmptySection() {
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnArgument(0));
+
+ $this->mapper->expects($this->once())
+ ->method('getPersonalSectionsFromDB')
+ ->will($this->returnValue([]));
+
+ $this->url->expects($this->exactly(3))
+ ->method('imagePath')
+ ->willReturnMap([
+ ['core', 'actions/info.svg', '1'],
+ ['settings', 'password.svg', '2'],
+ ['settings', 'change.svg', '3'],
+ ]);
+
+ $this->assertArraySubset([
+ 0 => [new Section('personal-info', 'Personal info', 0, '1')],
+ 5 => [new Section('security', 'Security', 0, '2')],
+ 15 => [new Section('sync-clients', 'Sync clients', 0, '3')],
+ ], $this->manager->getPersonalSections());
+ }
+
public function testGetAdminSettings() {
$this->mapper->expects($this->any())
->method('getAdminSettingsFromDB')
@@ -207,4 +304,14 @@ class ManagerTest extends TestCase {
0 => [new Sharing($this->config)],
], $this->manager->getAdminSettings('sharing'));
}
+
+ public function testGetPersonalSettings() {
+ $this->mapper->expects($this->any())
+ ->method('getPersonalSettingsFromDB')
+ ->will($this->returnValue([]));
+
+ $this->assertEquals([
+ 10 => [new Security()],
+ ], $this->manager->getPersonalSettings('security'));
+ }
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 13556285b61..1cc165106d7 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -508,7 +508,7 @@ class ManagerTest extends \Test\TestCase {
[$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true],
[$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],
- [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Can\'t share with yourself', true],
+ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Can’t share with yourself', true],
[$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
[$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true],
@@ -539,26 +539,26 @@ class ManagerTest extends \Test\TestCase {
$mount = $this->createMock(MoveableMount::class);
$limitedPermssions->method('getMountPoint')->willReturn($mount);
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Can’t increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Can’t increase permissions of path', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Can’t increase permissions of path', true];
$nonMoveableMountPermssions = $this->createMock(Folder::class);
$nonMoveableMountPermssions->method('isShareable')->willReturn(true);
$nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Can’t increase permissions of path', false];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Can’t increase permissions of path', false];
$rootFolder = $this->createMock(Folder::class);
$rootFolder->method('isShareable')->willReturn(true);
$rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
$rootFolder->method('getPath')->willReturn('myrootfolder');
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You can\'t share your root folder', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can\'t share your root folder', true];
- $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can\'t share your root folder', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You can’t share your root folder', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can’t share your root folder', true];
+ $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can’t share your root folder', true];
$allPermssions = $this->createMock(Folder::class);
$allPermssions->method('isShareable')->willReturn(true);
@@ -614,7 +614,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException \InvalidArgumentException
- * @expectedExceptionMessage You can't share your root folder
+ * @expectedExceptionMessage You can’t share your root folder
*/
public function testGeneralCheckShareRoot() {
$thrown = null;
@@ -882,7 +882,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Only sharing with group members is allowed
+ * @expectedExceptionMessage Sharing is only allowed with group members
*/
public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() {
$share = $this->manager->newShare();
@@ -954,7 +954,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Path already shared with this user
+ * @expectedExceptionMessage Path is already shared with this user
*/
public function testUserCreateChecksIdenticalShareExists() {
$share = $this->manager->newShare();
@@ -979,7 +979,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Path already shared with this user
+ * @expectedExceptionMessage Path is already shared with this user
*/
public function testUserCreateChecksIdenticalPathSharedViaGroup() {
$share = $this->manager->newShare();
@@ -1105,7 +1105,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Only sharing within your own groups is allowed
+ * @expectedExceptionMessage Sharing is only allowed within your own groups
*/
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
$share = $this->manager->newShare();
@@ -1131,7 +1131,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Only sharing within your own groups is allowed
+ * @expectedExceptionMessage Sharing is only allowed within your own groups
*/
public function testGroupCreateChecksShareWithGroupMembersOnlyNullGroup() {
$share = $this->manager->newShare();
@@ -1183,7 +1183,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Path already shared with this group
+ * @expectedExceptionMessage Path is already shared with this group
*/
public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
$share = $this->manager->newShare();
@@ -1238,7 +1238,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Link sharing not allowed
+ * @expectedExceptionMessage Link sharing is not allowed
*/
public function testLinkCreateChecksNoLinkSharesAllowed() {
$share = $this->manager->newShare();
@@ -1254,7 +1254,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Link shares can't have reshare permissions
+ * @expectedExceptionMessage Link shares can’t have reshare permissions
*/
public function testLinkCreateChecksSharePermissions() {
$share = $this->manager->newShare();
@@ -1272,7 +1272,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Public upload not allowed
+ * @expectedExceptionMessage Public upload is not allowed
*/
public function testLinkCreateChecksNoPublicUpload() {
$share = $this->manager->newShare();
@@ -2142,6 +2142,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException \OCP\Share\Exceptions\ShareNotFound
+ * @expectedExceptionMessage The requested share does not exist anymore
*/
public function testGetShareByTokenExpired() {
$this->config
@@ -2150,6 +2151,10 @@ class ManagerTest extends \Test\TestCase {
->with('core', 'shareapi_allow_links', 'yes')
->willReturn('yes');
+ $this->l->expects($this->once())
+ ->method('t')
+ ->willReturnArgument(0);
+
$manager = $this->createManagerMock()
->setMethods(['deleteShare'])
->getMock();
@@ -2292,7 +2297,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Can't change share type
+ * @expectedExceptionMessage Can’t change share type
*/
public function testUpdateShareCantChangeShareType() {
$manager = $this->createManagerMock()
@@ -2346,7 +2351,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException Exception
- * @expectedExceptionMessage Can't share with the share owner
+ * @expectedExceptionMessage Can’t share with the share owner
*/
public function testUpdateShareCantShareWithOwner() {
$manager = $this->createManagerMock()
@@ -2637,7 +2642,7 @@ class ManagerTest extends \Test\TestCase {
/**
* @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can't change target of link share
+ * @expectedExceptionMessage Can’t change target of link share
*/
public function testMoveShareLink() {
$share = $this->manager->newShare();
diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php
index fb7c6c5e034..345972bb1af 100644
--- a/tests/lib/Template/SCSSCacherTest.php
+++ b/tests/lib/Template/SCSSCacherTest.php
@@ -72,6 +72,10 @@ class SCSSCacherTest extends \Test\TestCase {
$this->depsCache
);
$this->themingDefaults->expects($this->any())->method('getScssVariables')->willReturn([]);
+
+ $this->urlGenerator->expects($this->any())
+ ->method('getBaseUrl')
+ ->willReturn('http://localhost/nextcloud');
}
public function testProcessUncachedFileNoAppDataFolder() {
@@ -84,14 +88,15 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps = $this->createMock(ISimpleFile::class);
$gzfile = $this->createMock(ISimpleFile::class);
+ $filePrefix = md5('http://localhost/nextcloud') . '-';
$folder->method('getFile')
- ->will($this->returnCallback(function($path) use ($file, $gzfile) {
- if ($path === 'styles.css') {
+ ->will($this->returnCallback(function($path) use ($file, $gzfile, $filePrefix) {
+ if ($path === $filePrefix.'styles.css') {
return $file;
- } else if ($path === 'styles.css.deps') {
+ } else if ($path === $filePrefix.'styles.css.deps') {
throw new NotFoundException();
- } else if ($path === 'styles.css.gzip') {
+ } else if ($path === $filePrefix.'styles.css.gzip') {
return $gzfile;
} else {
$this->fail();
@@ -99,9 +104,13 @@ class SCSSCacherTest extends \Test\TestCase {
}));
$folder->expects($this->once())
->method('newFile')
- ->with('styles.css.deps')
+ ->with($filePrefix.'styles.css.deps')
->willReturn($fileDeps);
+ $this->urlGenerator->expects($this->once())
+ ->method('getBaseUrl')
+ ->willReturn('http://localhost/nextcloud');
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
@@ -113,14 +122,15 @@ class SCSSCacherTest extends \Test\TestCase {
$file->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
$gzfile = $this->createMock(ISimpleFile::class);
+ $filePrefix = md5('http://localhost/nextcloud') . '-';
$folder->method('getFile')
- ->will($this->returnCallback(function($path) use ($file, $gzfile) {
- if ($path === 'styles.css') {
+ ->will($this->returnCallback(function($path) use ($file, $gzfile, $filePrefix) {
+ if ($path === $filePrefix.'styles.css') {
return $file;
- } else if ($path === 'styles.css.deps') {
+ } else if ($path === $filePrefix.'styles.css.deps') {
throw new NotFoundException();
- } else if ($path === 'styles.css.gzip') {
+ } else if ($path === $filePrefix.'styles.css.gzip') {
return $gzfile;
}else {
$this->fail();
@@ -128,7 +138,7 @@ class SCSSCacherTest extends \Test\TestCase {
}));
$folder->expects($this->once())
->method('newFile')
- ->with('styles.css.deps')
+ ->with($filePrefix.'styles.css.deps')
->willReturn($fileDeps);
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
@@ -142,14 +152,15 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps = $this->createMock(ISimpleFile::class);
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$gzFile = $this->createMock(ISimpleFile::class);
+ $filePrefix = md5('http://localhost/nextcloud') . '-';
$folder->method('getFile')
- ->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile) {
- if ($name === 'styles.css') {
+ ->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
+ if ($name === $filePrefix.'styles.css') {
return $file;
- } else if ($name === 'styles.css.deps') {
+ } else if ($name === $filePrefix.'styles.css.deps') {
return $fileDeps;
- } else if ($name === 'styles.css.gzip') {
+ } else if ($name === $filePrefix.'styles.css.gzip') {
return $gzFile;
}
$this->fail();
@@ -174,14 +185,14 @@ class SCSSCacherTest extends \Test\TestCase {
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$gzFile = $this->createMock(ISimpleFile::class);
-
+ $filePrefix = md5('http://localhost/nextcloud') . '-';
$folder->method('getFile')
- ->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile) {
- if ($name === 'styles.css') {
+ ->will($this->returnCallback(function($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
+ if ($name === $filePrefix.'styles.css') {
return $file;
- } else if ($name === 'styles.css.deps') {
+ } else if ($name === $filePrefix.'styles.css.deps') {
return $fileDeps;
- } else if ($name === 'styles.css.gzip') {
+ } else if ($name === $filePrefix.'styles.css.gzip') {
return $gzFile;
}
$this->fail();
@@ -374,7 +385,7 @@ class SCSSCacherTest extends \Test\TestCase {
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.Css.getCss', [
- 'fileName' => 'styles.css',
+ 'fileName' => md5('http://localhost/nextcloud') . '-styles.css',
'appName' => $appName
])
->willReturn(\OC::$WEBROOT . $result);
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 28fd2d336d2..69067f51e08 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -9,6 +9,8 @@
namespace Test;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\IRequest;
+use OCP\IURLGenerator;
/**
* Class UrlGeneratorTest
@@ -17,6 +19,37 @@ use OCP\IConfig;
*/
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
@@ -24,11 +57,7 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
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);
}
@@ -39,11 +68,7 @@ class UrlGeneratorTest extends \Test\TestCase {
*/
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);
}
@@ -51,13 +76,10 @@ class UrlGeneratorTest extends \Test\TestCase {
* @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() {
@@ -89,13 +111,9 @@ class UrlGeneratorTest extends \Test\TestCase {
* @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);
}
@@ -105,13 +123,9 @@ class UrlGeneratorTest extends \Test\TestCase {
* @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);
}
@@ -132,5 +146,14 @@ class UrlGeneratorTest extends \Test\TestCase {
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);
+ }
+
}