diff options
Diffstat (limited to 'tests')
29 files changed, 545 insertions, 255 deletions
diff --git a/tests/Core/Command/Maintenance/UpdateTheme.php b/tests/Core/Command/Maintenance/UpdateTheme.php new file mode 100644 index 00000000000..fbdea0b72b4 --- /dev/null +++ b/tests/Core/Command/Maintenance/UpdateTheme.php @@ -0,0 +1,82 @@ +<?php +/** + * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Tests\Core\Command\Maintenance; + +use OC\Core\Command\Maintenance\Mimetype\UpdateDB; +use OC\Core\Command\Maintenance\UpdateTheme; +use OC\Files\Type\Detection; +use OC\Files\Type\Loader; +use OCP\ICache; +use OCP\ICacheFactory; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; +use OCP\Files\IMimeTypeDetector; +use OCP\Files\IMimeTypeLoader; + +class UpdateThemeTest extends TestCase { + /** @var IMimeTypeDetector */ + protected $detector; + /** @var ICacheFactory */ + protected $cacheFactory; + + + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleInput; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $consoleOutput; + + /** @var \Symfony\Component\Console\Command\Command */ + protected $command; + + protected function setUp() { + parent::setUp(); + + $this->detector = $this->createMock(Detection::class); + $this->cacheFactory = $this->createMock(ICacheFactory::class); + + $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock(); + $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + + $this->command = new UpdateTheme($this->detector, $this->cacheFactory); + } + + public function testThemeUpdate() { + $this->consoleInput->method('getOption') + ->with('maintenance:theme:update') + ->willReturn(true); + $this->detector->expects($this->once()) + ->method('getAllAliases') + ->willReturn([]); + $cache = $this->createMock(ICache::class); + $cache->expects($this->once()) + ->method('clear') + ->with(''); + $this->cacheFactory->expects($this->once()) + ->method('create') + ->with('imagePath') + ->willReturn($cache); + self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); + } +} diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index ca32a04efe1..bd2d0143caf 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -95,6 +95,7 @@ class LoginControllerTest extends TestCase { ->willReturn('/login'); $expected = new RedirectResponse('/login'); + $expected->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); $this->assertEquals($expected, $this->loginController->logout()); } @@ -124,6 +125,7 @@ class LoginControllerTest extends TestCase { ->willReturn('/login'); $expected = new RedirectResponse('/login'); + $expected->addHeader('Clear-Site-Data', '"cache", "cookies", "storage", "executionContexts"'); $this->assertEquals($expected, $this->loginController->logout()); } diff --git a/tests/Settings/Controller/AdminSettingsControllerTest.php b/tests/Settings/Controller/AdminSettingsControllerTest.php index 6c93bca0d68..51357f67a2d 100644 --- a/tests/Settings/Controller/AdminSettingsControllerTest.php +++ b/tests/Settings/Controller/AdminSettingsControllerTest.php @@ -22,7 +22,6 @@ */ namespace Tests\Settings\Controller; - use OC\Settings\Admin\TipsTricks; use OC\Settings\Controller\AdminSettingsController; use OCP\AppFramework\Http\TemplateResponse; @@ -31,6 +30,13 @@ use OCP\IRequest; use OCP\Settings\IManager; use Test\TestCase; +/** + * Class AdminSettingsControllerTest + * + * @group DB + * + * @package Tests\Settings\Controller + */ class AdminSettingsControllerTest extends TestCase { /** @var AdminSettingsController */ private $adminSettingsController; @@ -38,8 +44,10 @@ class AdminSettingsControllerTest extends TestCase { private $request; /** @var INavigationManager */ private $navigationManager; - /** @var IManager */ + /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ private $settingsManager; + /** @var string */ + private $adminUid = 'lololo'; public function setUp() { parent::setUp(); @@ -54,6 +62,16 @@ class AdminSettingsControllerTest extends TestCase { $this->navigationManager, $this->settingsManager ); + + $user = \OC::$server->getUserManager()->createUser($this->adminUid, 'olo'); + \OC_User::setUserId($user->getUID()); + \OC::$server->getGroupManager()->createGroup('admin')->addUser($user); + } + + public function tearDown() { + \OC::$server->getUserManager()->get($this->adminUid)->delete(); + + parent::tearDown(); } public function testIndex() { @@ -63,10 +81,15 @@ class AdminSettingsControllerTest extends TestCase { ->willReturn([]); $this->settingsManager ->expects($this->once()) + ->method('getPersonalSections') + ->willReturn([]); + $this->settingsManager + ->expects($this->once()) ->method('getAdminSettings') ->with('test') ->willReturn([5 => new TipsTricks($this->getMockBuilder('\OCP\IConfig')->getMock())]); - $expected = new TemplateResponse('settings', 'admin/frame', ['forms' => [], 'content' => '']); + + $expected = new TemplateResponse('settings', 'settings/frame', ['forms' => ['personal' => [], 'admin' => []], 'content' => '']); $this->assertEquals($expected, $this->adminSettingsController->index('test')); } } diff --git a/tests/Settings/Controller/PersonalControllerTest.php b/tests/Settings/Controller/PersonalControllerTest.php deleted file mode 100644 index a1b727629bf..00000000000 --- a/tests/Settings/Controller/PersonalControllerTest.php +++ /dev/null @@ -1,122 +0,0 @@ -<?php -/** - * - * - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -namespace Test\Settings\Controller; - -use OC\Settings\Controller\PersonalController; -use OCP\AppFramework\Http; -use OCP\AppFramework\Http\JSONResponse; -use OCP\IConfig; -use OCP\IL10N; -use OCP\IRequest; -use OCP\L10N\IFactory; - -class PersonalControllerTest extends \Test\TestCase { - - /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ - private $l10nFactory; - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ - private $config; - /** @var PersonalController */ - private $controller; - /** @var IL10N */ - private $l; - - public function setUp() { - parent::setUp(); - - $this->l10nFactory = $this->createMock(IFactory::class); - $this->config = $this->createMock(IConfig::class); - $this->l = $this->createMock(IL10N::class); - - $this->l->method('t') - ->will($this->returnCallback(function ($text, $parameters = []) { - return vsprintf($text, $parameters); - })); - - $this->controller = new PersonalController( - 'settings', - $this->createMock(IRequest::class), - $this->l10nFactory, - 'user', - $this->config, - $this->l - ); - } - - public function testSetLanguage() { - $this->l10nFactory->method('findAvailableLanguages') - ->willReturn(['aa', 'bb', 'cc']); - $this->config->expects($this->once()) - ->method('setUserValue') - ->with( - $this->equalTo('user'), - $this->equalTo('core'), - $this->equalTo('lang'), - $this->equalTo('bb') - ); - - $resp = $this->controller->setLanguage('bb'); - $expected = new JSONResponse([]); - $this->assertEquals($expected, $resp); - } - - public function testSetLanguageEn() { - $this->l10nFactory->method('findAvailableLanguages') - ->willReturn(['aa', 'bb', 'cc']); - $this->config->expects($this->once()) - ->method('setUserValue') - ->with( - $this->equalTo('user'), - $this->equalTo('core'), - $this->equalTo('lang'), - $this->equalTo('en') - ); - - $resp = $this->controller->setLanguage('en'); - $expected = new JSONResponse([]); - $this->assertEquals($expected, $resp); - } - - public function testSetLanguageFails() { - $this->l10nFactory->method('findAvailableLanguages') - ->willReturn(['aa', 'bb', 'cc']); - $this->config->expects($this->never()) - ->method('setUserValue'); - - $resp = $this->controller->setLanguage('dd'); - $expected = new JSONResponse(['message' => 'Invalid request'], Http::STATUS_BAD_REQUEST); - $this->assertEquals($expected, $resp); - } - - - public function testSetLanguageEmpty() { - $this->l10nFactory->method('findAvailableLanguages') - ->willReturn(['aa', 'bb', 'cc']); - $this->config->expects($this->never()) - ->method('setUserValue'); - - $resp = $this->controller->setLanguage(''); - $expected = new JSONResponse(['message' => 'Invalid request'], Http::STATUS_BAD_REQUEST); - $this->assertEquals($expected, $resp); - } -} diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index fee47625cfd..a8b67278e77 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -21,6 +21,7 @@ namespace Tests\Settings\Mailer; +use OC\Mail\EMailTemplate; use OCP\Mail\IEMailTemplate; use OC\Mail\Message; use OC\Settings\Mailer\NewUserMailHelper; @@ -62,6 +63,13 @@ class NewUserMailHelperTest extends TestCase { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10n = $this->createMock(IL10N::class); $this->mailer = $this->createMock(IMailer::class); + $template = new EMailTemplate( + $this->defaults, + $this->urlGenerator, + $this->l10n + ); + $this->mailer->method('createEMailTemplate') + ->will($this->returnValue($template)); $this->secureRandom = $this->createMock(ISecureRandom::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(IConfig::class); diff --git a/tests/acceptance/features/access-levels.feature b/tests/acceptance/features/access-levels.feature index 57998899a57..80170296675 100644 --- a/tests/acceptance/features/access-levels.feature +++ b/tests/acceptance/features/access-levels.feature @@ -1,11 +1,10 @@ Feature: access-levels - Scenario: regular users can not see admin-level items in the Settings menu + Scenario: regular users cannot see admin-level items in the Settings menu Given I am logged in When I open the Settings menu Then I see that the Settings menu is shown - And I see that the "Personal" item in the Settings menu is shown - And I see that the "Admin" item in the Settings menu is not shown + And I see that the "Settings" item in the Settings menu is shown And I see that the "Users" item in the Settings menu is not shown And I see that the "Help" item in the Settings menu is shown And I see that the "Log out" item in the Settings menu is shown @@ -14,8 +13,19 @@ Feature: access-levels Given I am logged in as the admin When I open the Settings menu Then I see that the Settings menu is shown - And I see that the "Personal" item in the Settings menu is shown - And I see that the "Admin" item in the Settings menu is shown + And I see that the "Settings" item in the Settings menu is shown And I see that the "Users" item in the Settings menu is shown And I see that the "Help" item in the Settings menu is shown And I see that the "Log out" item in the Settings menu is shown + + Scenario: regular users cannot see admin-level items on the Settings page + Given I am logged in + When I visit the settings page + Then I see that the "Personal" settings panel is shown + And I see that the "Administration" settings panel is not shown + + Scenario: admin users can see admin-level items on the Settings page + Given I am logged in as the admin + When I visit the settings page + Then I see that the "Personal" settings panel is shown + And I see that the "Administration" settings panel is shown diff --git a/tests/acceptance/features/app-files.feature b/tests/acceptance/features/app-files.feature index 6779b37e145..8d32508513a 100644 --- a/tests/acceptance/features/app-files.feature +++ b/tests/acceptance/features/app-files.feature @@ -52,3 +52,19 @@ Feature: app-files And I authenticate with password "fedcba" Then I see that the current page is the Authenticate page for the shared link I wrote down And I see that a wrong password for the shared file message is shown + + Scenario: show the input field for tags in the details view + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view for "All files" section is open + When I open the input field for tags in the details view + Then I see that the input field for tags in the details view is shown + + Scenario: show the input field for tags in the details view after the sharing tab has loaded + Given I am logged in + And I open the details view for "welcome.txt" + And I see that the details view for "All files" section is open + And I open the "Sharing" tab in the details view + And I see that the "Sharing" tab in the details view is eventually loaded + When I open the input field for tags in the details view + Then I see that the input field for tags in the details view is shown diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php index 5916fd4bec6..52f69c66796 100644 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -105,6 +105,69 @@ class FilesAppContext implements Context, ActorAwareInterface { /** * @return Locator */ + public static function fileDetailsInCurrentSectionDetailsViewWithText($fileDetailsText) { + return Locator::forThe()->xpath("//span[normalize-space() = '$fileDetailsText']")-> + descendantOf(self::fileDetailsInCurrentSectionDetailsView())-> + describedAs("File details with text \"$fileDetailsText\" in current section details view in Files app"); + } + + /** + * @return Locator + */ + private static function fileDetailsInCurrentSectionDetailsView() { + return Locator::forThe()->css(".file-details")-> + descendantOf(self::currentSectionDetailsView())-> + describedAs("File details in current section details view in Files app"); + } + + /** + * @return Locator + */ + public static function inputFieldForTagsInCurrentSectionDetails() { + return Locator::forThe()->css(".systemTagsInfoView")-> + descendantOf(self::currentSectionDetailsView())-> + describedAs("Input field for tags in current section details view in Files app"); + } + + /** + * @return Locator + */ + public static function tabHeaderInCurrentSectionDetailsViewNamed($tabHeaderName) { + return Locator::forThe()->xpath("//li[normalize-space() = '$tabHeaderName']")-> + descendantOf(self::tabHeadersInCurrentSectionDetailsView())-> + describedAs("Tab header named $tabHeaderName in current section details view in Files app"); + } + + /** + * @return Locator + */ + private static function tabHeadersInCurrentSectionDetailsView() { + return Locator::forThe()->css(".tabHeaders")-> + descendantOf(self::currentSectionDetailsView())-> + describedAs("Tab headers in current section details view in Files app"); + } + + /** + * @return Locator + */ + public static function tabInCurrentSectionDetailsViewNamed($tabName) { + return Locator::forThe()->xpath("//div[@id=//*[contains(concat(' ', normalize-space(@class), ' '), ' tabHeader ') and normalize-space() = '$tabName']/@data-tabid]")-> + descendantOf(self::currentSectionDetailsView())-> + describedAs("Tab named $tabName in current section details view in Files app"); + } + + /** + * @return Locator + */ + public static function loadingIconForTabInCurrentSectionDetailsViewNamed($tabName) { + return Locator::forThe()->css(".loading")-> + descendantOf(self::tabInCurrentSectionDetailsViewNamed($tabName))-> + describedAs("Loading icon for tab named $tabName in current section details view in Files app"); + } + + /** + * @return Locator + */ public static function shareLinkCheckbox() { // forThe()->checkbox("Share link") can not be used here; that would // return the checkbox itself, but the element that the user interacts @@ -247,6 +310,20 @@ class FilesAppContext implements Context, ActorAwareInterface { } /** + * @Given I open the input field for tags in the details view + */ + public function iOpenTheInputFieldForTagsInTheDetailsView() { + $this->actor->find(self::fileDetailsInCurrentSectionDetailsViewWithText("Tags"), 10)->click(); + } + + /** + * @Given I open the :tabName tab in the details view + */ + public function iOpenTheTabInTheDetailsView($tabName) { + $this->actor->find(self::tabHeaderInCurrentSectionDetailsViewNamed($tabName), 10)->click(); + } + + /** * @Given I mark :fileName as favorite */ public function iMarkAsFavorite($fileName) { @@ -344,6 +421,23 @@ class FilesAppContext implements Context, ActorAwareInterface { } /** + * @Then I see that the input field for tags in the details view is shown + */ + public function iSeeThatTheInputFieldForTagsInTheDetailsViewIsShown() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::inputFieldForTagsInCurrentSectionDetails(), 10)->isVisible()); + } + + /** + * @When I see that the :tabName tab in the details view is eventually loaded + */ + public function iSeeThatTheTabInTheDetailsViewIsEventuallyLoaded($tabName) { + if (!$this->waitForElementToBeEventuallyNotShown(self::loadingIconForTabInCurrentSectionDetailsViewNamed($tabName), $timeout = 10)) { + PHPUnit_Framework_Assert::fail("The $tabName tab in the details view has not been loaded after $timeout seconds"); + } + } + + /** * @Then I see that the working icon for password protect is shown */ public function iSeeThatTheWorkingIconForPasswordProtectIsShown() { @@ -354,20 +448,7 @@ class FilesAppContext implements Context, ActorAwareInterface { * @Then I see that the working icon for password protect is eventually not shown */ public function iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown() { - $timeout = 10; - $timeoutStep = 1; - - $actor = $this->actor; - $passwordProtectWorkingIcon = self::passwordProtectWorkingIcon(); - - $workingIconNotFoundCallback = function() use ($actor, $passwordProtectWorkingIcon) { - try { - return !$actor->find($passwordProtectWorkingIcon)->isVisible(); - } catch (NoSuchElementException $exception) { - return true; - } - }; - if (!Utils::waitFor($workingIconNotFoundCallback, $timeout, $timeoutStep)) { + if (!$this->waitForElementToBeEventuallyNotShown(self::passwordProtectWorkingIcon(), $timeout = 10)) { PHPUnit_Framework_Assert::fail("The working icon for password protect is still shown after $timeout seconds"); } } @@ -382,4 +463,17 @@ class FilesAppContext implements Context, ActorAwareInterface { $this->iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown(); } + private function waitForElementToBeEventuallyNotShown($elementLocator, $timeout = 10, $timeoutStep = 1) { + $actor = $this->actor; + + $elementNotFoundCallback = function() use ($actor, $elementLocator) { + try { + return !$actor->find($elementLocator)->isVisible(); + } catch (NoSuchElementException $exception) { + return true; + } + }; + + return Utils::waitFor($elementNotFoundCallback, $timeout, $timeoutStep); + } } diff --git a/tests/acceptance/features/bootstrap/SettingsMenuContext.php b/tests/acceptance/features/bootstrap/SettingsMenuContext.php index 1ff5d94e98f..401575c78f0 100644 --- a/tests/acceptance/features/bootstrap/SettingsMenuContext.php +++ b/tests/acceptance/features/bootstrap/SettingsMenuContext.php @@ -67,6 +67,15 @@ class SettingsMenuContext implements Context, ActorAwareInterface { } /** + * @param string $itemText + * @return Locator + */ + private static function settingsPanelFor($itemText) { + return Locator::forThe()->xpath("//div[@id = 'app-navigation']//ul//li[@class = 'settings-caption' and normalize-space() = '$itemText']")-> + describedAs($itemText . " item in Settings panel"); + } + + /** * @When I open the Settings menu */ public function iOpenTheSettingsMenu() { @@ -83,6 +92,14 @@ class SettingsMenuContext implements Context, ActorAwareInterface { } /** + * @When I visit the settings page + */ + public function iVisitTheSettingsPage() { + $this->iOpenTheSettingsMenu(); + $this->actor->find(self::menuItemFor('Settings'), 2)->click(); + } + + /** * @When I log out */ public function iLogOut() { @@ -120,4 +137,25 @@ class SettingsMenuContext implements Context, ActorAwareInterface { } } + /** + * @Then I see that the :itemText settings panel is shown + */ + public function iSeeThatTheItemSettingsPanelIsShown($itemText) { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() + ); + } + + /** + * @Then I see that the :itemText settings panel is not shown + */ + public function iSeeThatTheItemSettingsPanelIsNotShown($itemText) { + try { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::settingsPanelFor($itemText), 10)->isVisible() + ); + } catch (NoSuchElementException $exception) { + } + } + } diff --git a/tests/acceptance/features/core/ElementWrapper.php b/tests/acceptance/features/core/ElementWrapper.php index 6b730903f6c..f6ce176817b 100644 --- a/tests/acceptance/features/core/ElementWrapper.php +++ b/tests/acceptance/features/core/ElementWrapper.php @@ -119,7 +119,7 @@ class ElementWrapper { /** * Returns whether the wrapped element is visible or not. * - * @return boolbean true if the wrapped element is visible, false otherwise. + * @return bool true if the wrapped element is visible, false otherwise. */ public function isVisible() { $commandCallback = function() { diff --git a/tests/apps/testapp-infoxml-version-different/appinfo/info.xml b/tests/apps/testapp-dependency-missing/appinfo/info.xml index c765400a76f..c765400a76f 100644 --- a/tests/apps/testapp-infoxml-version-different/appinfo/info.xml +++ b/tests/apps/testapp-dependency-missing/appinfo/info.xml diff --git a/tests/apps/testapp-infoxml-version-different/appinfo/version b/tests/apps/testapp-infoxml-version-different/appinfo/version deleted file mode 100644 index e8ea05db814..00000000000 --- a/tests/apps/testapp-infoxml-version-different/appinfo/version +++ /dev/null @@ -1 +0,0 @@ -1.2.4 diff --git a/tests/apps/testapp-infoxml-version/appinfo/info.xml b/tests/apps/testapp-infoxml-version/appinfo/info.xml deleted file mode 100644 index c765400a76f..00000000000 --- a/tests/apps/testapp-infoxml-version/appinfo/info.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0"?> -<info> - <id>testapp-infoxml-version</id> - <version>1.2.3</version> - <author>Jane</author> - <description>A b c</description> - <licence>Abc</licence> - <name>Test app</name> -</info> diff --git a/tests/apps/testapp-infoxml-version/appinfo/version b/tests/apps/testapp-infoxml-version/appinfo/version deleted file mode 100644 index 0495c4a88ca..00000000000 --- a/tests/apps/testapp-infoxml-version/appinfo/version +++ /dev/null @@ -1 +0,0 @@ -1.2.3 diff --git a/tests/apps/testapp-infoxml/appinfo/info.xml b/tests/apps/testapp-infoxml/appinfo/info.xml index cb63a0fc76e..d4df1c3cd3f 100644 --- a/tests/apps/testapp-infoxml/appinfo/info.xml +++ b/tests/apps/testapp-infoxml/appinfo/info.xml @@ -6,4 +6,7 @@ <description>A b c</description> <licence>Abc</licence> <name>Test app</name> + <dependencies> + <nextcloud min-version="12.0" max-version="12.0"/> + </dependencies> </info> diff --git a/tests/apps/testapp-name-missing/appinfo/info.xml b/tests/apps/testapp-name-missing/appinfo/info.xml index f0a62b8d380..591c4361899 100644 --- a/tests/apps/testapp-name-missing/appinfo/info.xml +++ b/tests/apps/testapp-name-missing/appinfo/info.xml @@ -5,4 +5,7 @@ <author>Jane</author> <description>A b c</description> <licence>Abc</licence> + <dependencies> + <nextcloud min-version="12.0" max-version="12.0"/> + </dependencies> </info> diff --git a/tests/apps/testapp-version-missing/appinfo/info.xml b/tests/apps/testapp-version-missing/appinfo/info.xml deleted file mode 100644 index d7da3e07e36..00000000000 --- a/tests/apps/testapp-version-missing/appinfo/info.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0"?> -<info> - <id>testapp-version</id> - <author>Jane</author> - <description>A b c</description> - <licence>Abc</licence> - <name>Test app</name> -</info> diff --git a/tests/apps/testapp-version/appinfo/info.xml b/tests/apps/testapp-version/appinfo/info.xml index d7da3e07e36..28e2475800f 100644 --- a/tests/apps/testapp-version/appinfo/info.xml +++ b/tests/apps/testapp-version/appinfo/info.xml @@ -5,4 +5,7 @@ <description>A b c</description> <licence>Abc</licence> <name>Test app</name> + <dependencies> + <nextcloud min-version="12.0" max-version="12.0"/> + </dependencies> </info> diff --git a/tests/karma.config.js b/tests/karma.config.js index 62b5171dcd1..07dc2965346 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -102,6 +102,7 @@ module.exports = function(config) { // need to enforce loading order... 'apps/systemtags/js/app.js', 'apps/systemtags/js/systemtagsinfoview.js', + 'apps/systemtags/js/systemtagsinfoviewtoggleview.js', 'apps/systemtags/js/systemtagsfilelist.js', 'apps/systemtags/js/filesplugin.js' ], 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); + } + } |