diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Command/Maintenance/UpdateTheme.php | 2 | ||||
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 33 | ||||
-rw-r--r-- | tests/Settings/Activity/SecurityProviderTest.php | 4 | ||||
-rw-r--r-- | tests/acceptance/features/app-files.feature | 11 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/FilesAppContext.php | 37 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/FilesSharingAppContext.php | 84 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/AvatarTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/MailPluginTest.php | 139 | ||||
-rw-r--r-- | tests/lib/IntegrityCheck/CheckerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/LegacyHelperTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Template/SCSSCacherTest.php | 64 | ||||
-rw-r--r-- | tests/lib/Updater/VersionCheckTest.php | 53 | ||||
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 10 |
15 files changed, 429 insertions, 27 deletions
diff --git a/tests/Core/Command/Maintenance/UpdateTheme.php b/tests/Core/Command/Maintenance/UpdateTheme.php index fbdea0b72b4..cbc417dbdba 100644 --- a/tests/Core/Command/Maintenance/UpdateTheme.php +++ b/tests/Core/Command/Maintenance/UpdateTheme.php @@ -74,7 +74,7 @@ class UpdateThemeTest extends TestCase { ->method('clear') ->with(''); $this->cacheFactory->expects($this->once()) - ->method('create') + ->method('createDistributed') ->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 e02b8403a2a..ddf7a865d66 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -182,12 +182,43 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginState' => 0, 'resetPasswordLink' => null, + 'hideRemeberLoginState' => false, ], 'guest' ); $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', '', '')); } + public function testShowLoginFormForFlowAuth() { + $this->userSession + ->expects($this->once()) + ->method('isLoggedIn') + ->willReturn(false); + $this->session + ->expects($this->once()) + ->method('exists') + ->with('client.flow.state.token') + ->willReturn(true); + + $expectedResponse = new TemplateResponse( + 'core', + 'login', + [ + 'messages' => [], + 'redirect_url' => 'login/flow', + 'loginName' => '', + 'user_autofocus' => true, + 'canResetPassword' => true, + 'alt_login' => [], + 'rememberLoginState' => 0, + 'resetPasswordLink' => null, + 'hideRemeberLoginState' => true, + ], + 'guest' + ); + $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('', 'login/flow', '')); + } + /** * @return array */ @@ -240,6 +271,7 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginState' => 0, 'resetPasswordLink' => false, + 'hideRemeberLoginState' => false, ], 'guest' ); @@ -278,6 +310,7 @@ class LoginControllerTest extends TestCase { 'alt_login' => [], 'rememberLoginState' => 0, 'resetPasswordLink' => false, + 'hideRemeberLoginState' => false, ], 'guest' ); diff --git a/tests/Settings/Activity/SecurityProviderTest.php b/tests/Settings/Activity/SecurityProviderTest.php index 21fc28f3c3b..552548984d7 100644 --- a/tests/Settings/Activity/SecurityProviderTest.php +++ b/tests/Settings/Activity/SecurityProviderTest.php @@ -87,7 +87,7 @@ class SecurityProviderTest extends TestCase { ->willReturn('security'); $this->l10n->expects($this->once()) ->method('get') - ->with('core', $lang) + ->with('settings', $lang) ->willReturn($l); $this->urlGenerator->expects($this->once()) ->method('imagePath') @@ -119,7 +119,7 @@ class SecurityProviderTest extends TestCase { ->willReturn('security'); $this->l10n->expects($this->once()) ->method('get') - ->with('core', $lang) + ->with('settings', $lang) ->willReturn($l); $event->expects($this->once()) ->method('getSubject') diff --git a/tests/acceptance/features/app-files.feature b/tests/acceptance/features/app-files.feature index ac2d05fac2c..2cb43611b9a 100644 --- a/tests/acceptance/features/app-files.feature +++ b/tests/acceptance/features/app-files.feature @@ -23,6 +23,17 @@ Feature: app-files When I open the details view for "welcome.txt" Then I see that the details view for "All files" section is open + Scenario: open the menu in a public shared link + Given I act as John + And I am logged in + And I share the link for "welcome.txt" + And I write down the shared link + When I act as Jane + And I visit the shared link I wrote down + And I see that the current page is the shared link I wrote down + And I open the Share menu + Then I see that the Share menu is shown + Scenario: set a password to a shared link Given I am logged in And I share the link for "welcome.txt" diff --git a/tests/acceptance/features/bootstrap/FilesAppContext.php b/tests/acceptance/features/bootstrap/FilesAppContext.php index 338823a9478..4951dc43f1d 100644 --- a/tests/acceptance/features/bootstrap/FilesAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesAppContext.php @@ -452,7 +452,16 @@ class FilesAppContext implements Context, ActorAwareInterface { * @Given I write down the shared link */ public function iWriteDownTheSharedLink() { - $this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::shareLinkField(), 10)->getValue(); + // The shared link field always exists in the DOM (once the "Sharing" + // tab is loaded), but its value is the actual shared link only when it + // is visible. + if (!$this->waitForElementToBeEventuallyShown( + self::shareLinkField(), + $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { + PHPUnit_Framework_Assert::fail("The shared link was not shown yet after $timeout seconds"); + } + + $this->actor->getSharedNotebook()["shared link"] = $this->actor->find(self::shareLinkField())->getValue(); } /** @@ -606,7 +615,9 @@ class FilesAppContext implements Context, ActorAwareInterface { * @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)) { + if (!$this->waitForElementToBeEventuallyNotShown( + self::loadingIconForTabInCurrentSectionDetailsViewNamed($tabName), + $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { PHPUnit_Framework_Assert::fail("The $tabName tab in the details view has not been loaded after $timeout seconds"); } } @@ -622,7 +633,9 @@ class FilesAppContext implements Context, ActorAwareInterface { * @Then I see that the working icon for password protect is eventually not shown */ public function iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown() { - if (!$this->waitForElementToBeEventuallyNotShown(self::passwordProtectWorkingIcon(), $timeout = 10)) { + if (!$this->waitForElementToBeEventuallyNotShown( + self::passwordProtectWorkingIcon(), + $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { PHPUnit_Framework_Assert::fail("The working icon for password protect is still shown after $timeout seconds"); } } @@ -637,10 +650,24 @@ class FilesAppContext implements Context, ActorAwareInterface { $this->iSeeThatTheWorkingIconForPasswordProtectIsEventuallyNotShown(); } + private function waitForElementToBeEventuallyShown($elementLocator, $timeout = 10, $timeoutStep = 1) { + $actor = $this->actor; + + $elementShownCallback = function() use ($actor, $elementLocator) { + try { + return $actor->find($elementLocator)->isVisible(); + } catch (NoSuchElementException $exception) { + return false; + } + }; + + return Utils::waitFor($elementShownCallback, $timeout, $timeoutStep); + } + private function waitForElementToBeEventuallyNotShown($elementLocator, $timeout = 10, $timeoutStep = 1) { $actor = $this->actor; - $elementNotFoundCallback = function() use ($actor, $elementLocator) { + $elementNotShownCallback = function() use ($actor, $elementLocator) { try { return !$actor->find($elementLocator)->isVisible(); } catch (NoSuchElementException $exception) { @@ -648,6 +675,6 @@ class FilesAppContext implements Context, ActorAwareInterface { } }; - return Utils::waitFor($elementNotFoundCallback, $timeout, $timeoutStep); + return Utils::waitFor($elementNotShownCallback, $timeout, $timeoutStep); } } diff --git a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php index 88c1180c753..f3386b46db9 100644 --- a/tests/acceptance/features/bootstrap/FilesSharingAppContext.php +++ b/tests/acceptance/features/bootstrap/FilesSharingAppContext.php @@ -54,6 +54,49 @@ class FilesSharingAppContext implements Context, ActorAwareInterface { /** * @return Locator */ + public static function shareMenuButton() { + return Locator::forThe()->id("share-menutoggle")-> + describedAs("Share menu button in Shared file page"); + } + + /** + * @return Locator + */ + public static function shareMenu() { + return Locator::forThe()->id("share-menu")-> + describedAs("Share menu in Shared file page"); + } + + /** + * @return Locator + */ + public static function downloadItemInShareMenu() { + return Locator::forThe()->id("download")-> + descendantOf(self::shareMenu())-> + describedAs("Download item in Share menu in Shared file page"); + } + + /** + * @return Locator + */ + public static function directLinkItemInShareMenu() { + return Locator::forThe()->id("directLink-container")-> + descendantOf(self::shareMenu())-> + describedAs("Direct link item in Share menu in Shared file page"); + } + + /** + * @return Locator + */ + public static function saveItemInShareMenu() { + return Locator::forThe()->id("save")-> + descendantOf(self::shareMenu())-> + describedAs("Save item in Share menu in Shared file page"); + } + + /** + * @return Locator + */ public static function textPreview() { return Locator::forThe()->css(".text-preview")-> describedAs("Text preview in Shared file page"); @@ -75,6 +118,13 @@ class FilesSharingAppContext implements Context, ActorAwareInterface { } /** + * @When I open the Share menu + */ + public function iOpenTheShareMenu() { + $this->actor->find(self::shareMenuButton(), 10)->click(); + } + + /** * @Then I see that the current page is the Authenticate page for the shared link I wrote down */ public function iSeeThatTheCurrentPageIsTheAuthenticatePageForTheSharedLinkIWroteDown() { @@ -101,10 +151,44 @@ class FilesSharingAppContext implements Context, ActorAwareInterface { } /** + * @Then I see that the Share menu is shown + */ + public function iSeeThatTheShareMenuIsShown() { + // Unlike other menus, the Share menu is always present in the DOM, so + // the element could be found when it was no made visible yet due to the + // command not having been processed by the browser. + if (!$this->waitForElementToBeEventuallyShown( + self::shareMenu(), $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) { + PHPUnit_Framework_Assert::fail("The Share menu is not visible yet after $timeout seconds"); + } + + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::downloadItemInShareMenu())->isVisible()); + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::directLinkItemInShareMenu())->isVisible()); + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::saveItemInShareMenu())->isVisible()); + } + + /** * @Then I see that the shared file preview shows the text :text */ public function iSeeThatTheSharedFilePreviewShowsTheText($text) { PHPUnit_Framework_Assert::assertContains($text, $this->actor->find(self::textPreview(), 10)->getText()); } + private function waitForElementToBeEventuallyShown($elementLocator, $timeout = 10, $timeoutStep = 1) { + $actor = $this->actor; + + $elementShownCallback = function() use ($actor, $elementLocator) { + try { + return $actor->find($elementLocator)->isVisible(); + } catch (NoSuchElementException $exception) { + return false; + } + }; + + return Utils::waitFor($elementShownCallback, $timeout, $timeoutStep); + } + } diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index c2c0ea55072..c361db7b76b 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -100,7 +100,7 @@ class AppManagerTest extends TestCase { $this->cache = $this->createMock(ICache::class); $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->cacheFactory->expects($this->any()) - ->method('create') + ->method('createDistributed') ->with('settings') ->willReturn($this->cache); $this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher); diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php index 240aecc115e..9da719c26de 100644 --- a/tests/lib/AvatarTest.php +++ b/tests/lib/AvatarTest.php @@ -210,7 +210,7 @@ class AvatarTest extends \Test\TestCase { ->method('putContent') ->with($image->data()); - $this->config->expects($this->once()) + $this->config->expects($this->exactly(3)) ->method('setUserValue'); $this->config->expects($this->once()) ->method('getUserValue'); diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index 9c9d9cff909..b728ae521e2 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -31,6 +31,8 @@ use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; use OCP\Federation\ICloudIdManager; use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IUserSession; use OCP\Share; use Test\TestCase; @@ -50,17 +52,25 @@ class MailPluginTest extends TestCase { /** @var SearchResult */ protected $searchResult; + /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $groupManager; + + /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */ + protected $userSession; + public function setUp() { parent::setUp(); $this->config = $this->createMock(IConfig::class); $this->contactsManager = $this->createMock(IManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userSession = $this->createMock(IUserSession::class); $this->cloudIdManager = new CloudIdManager(); $this->searchResult = new SearchResult(); } public function instantiatePlugin() { - $this->plugin = new MailPlugin($this->contactsManager, $this->cloudIdManager, $this->config); + $this->plugin = new MailPlugin($this->contactsManager, $this->cloudIdManager, $this->config, $this->groupManager, $this->userSession); } /** @@ -333,4 +343,131 @@ class MailPluginTest extends TestCase { ] ]; } + + /** + * @dataProvider dataGetEmailGroupsOnly + * + * @param string $searchTerm + * @param array $contacts + * @param array $expected + * @param bool $exactIdMatch + * @param bool $reachedEnd + * @param array groups + */ + public function testSearchGroupsOnly($searchTerm, $contacts, $expected, $exactIdMatch, $reachedEnd, $userToGroupMapping) { + $this->config->expects($this->any()) + ->method('getAppValue') + ->willReturnCallback( + function($appName, $key, $default) { + if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { + return 'yes'; + } else if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') { + return 'yes'; + } + return $default; + } + ); + + $this->instantiatePlugin(); + + /** @var \OCP\IUser | \PHPUnit_Framework_MockObject_MockObject */ + $currentUser = $this->createMock('\OCP\IUser'); + + $currentUser->expects($this->any()) + ->method('getUID') + ->willReturn('currentUser'); + + $this->contactsManager->expects($this->any()) + ->method('search') + ->with($searchTerm, ['EMAIL', 'FN']) + ->willReturn($contacts); + + $this->userSession->expects($this->any()) + ->method('getUser') + ->willReturn($currentUser); + + $this->groupManager->expects($this->any()) + ->method('getUserGroupIds') + ->willReturnCallback(function(\OCP\IUser $user) use ($userToGroupMapping) { + return $userToGroupMapping[$user->getUID()]; + }); + + $this->groupManager->expects($this->any()) + ->method('isInGroup') + ->willReturnCallback(function($userId, $group) use ($userToGroupMapping) { + return in_array($group, $userToGroupMapping[$userId]); + }); + + $moreResults = $this->plugin->search($searchTerm, 0, 0, $this->searchResult); + $result = $this->searchResult->asArray(); + + $this->assertSame($exactIdMatch, $this->searchResult->hasExactIdMatch(new SearchResultType('emails'))); + $this->assertEquals($expected, $result); + $this->assertSame($reachedEnd, $moreResults); + } + + public function dataGetEmailGroupsOnly() { + return [ + // The user `User` can share with the current user + [ + 'test', + [ + [ + 'FN' => 'User', + 'EMAIL' => ['test@example.com'], + 'CLOUD' => ['test@localhost'], + 'isLocalSystemBook' => true, + 'UID' => 'User' + ] + ], + ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]], + false, + true, + [ + "currentUser" => ["group1"], + "User" => ["group1"] + ] + ], + // The user `User` cannot share with the current user + [ + 'test', + [ + [ + 'FN' => 'User', + 'EMAIL' => ['test@example.com'], + 'CLOUD' => ['test@localhost'], + 'isLocalSystemBook' => true, + 'UID' => 'User' + ] + ], + ['emails'=> [], 'exact' => ['emails' => []]], + false, + true, + [ + "currentUser" => ["group1"], + "User" => ["group2"] + ] + ], + // The user `User` cannot share with the current user, but there is an exact match on the e-mail address -> share by e-mail + [ + 'test@example.com', + [ + [ + 'FN' => 'User', + 'EMAIL' => ['test@example.com'], + 'CLOUD' => ['test@localhost'], + 'isLocalSystemBook' => true, + 'UID' => 'User' + ] + ], + ['emails' => [], 'exact' => ['emails' => [['label' => 'test@example.com', 'value' => ['shareType' => 4,'shareWith' => 'test@example.com']]]]], + false, + true, + [ + "currentUser" => ["group1"], + "User" => ["group2"] + ] + ] + ]; + } } diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index 049017cb5e8..09e6990a0f3 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -60,7 +60,7 @@ class CheckerTest extends TestCase { $this->cacheFactory ->expects($this->any()) - ->method('create') + ->method('createDistributed') ->with('oc.integritycheck.checker') ->will($this->returnValue(new NullCache())); diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php index f1e22ea600e..736c5bf7fad 100644 --- a/tests/lib/LegacyHelperTest.php +++ b/tests/lib/LegacyHelperTest.php @@ -12,6 +12,17 @@ use OC\Files\View; use OC_Helper; class LegacyHelperTest extends \Test\TestCase { + /** @var string */ + private $originalWebRoot; + + public function setUp() { + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; + } /** * @dataProvider humanFileSizeProvider diff --git a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php index 34c326e72e1..bacd2b7bf6f 100644 --- a/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php +++ b/tests/lib/Security/RateLimiting/Backend/MemoryCacheTest.php @@ -46,7 +46,7 @@ class MemoryCacheTest extends TestCase { $this->cacheFactory ->expects($this->once()) - ->method('create') + ->method('createDistributed') ->with('OC\Security\RateLimiting\Backend\MemoryCache') ->willReturn($this->cache); diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index 3825bc44c59..fca9500810e 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -352,19 +352,10 @@ class SCSSCacherTest extends \Test\TestCase { } public function testRebaseUrls() { - $webDir = 'apps/files/css'; + $webDir = '/apps/files/css'; $css = '#id { background-image: url(\'../img/image.jpg\'); }'; $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../../apps/files/css/../img/image.jpg\'); }'; - $this->assertEquals($expected, $actual); - } - - public function testRebaseUrlsIgnoreFrontendController() { - $this->config->expects($this->once())->method('getSystemValue')->with('htaccess.IgnoreFrontController', false)->willReturn(true); - $webDir = 'apps/files/css'; - $css = '#id { background-image: url(\'../img/image.jpg\'); }'; - $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$css, $webDir]); - $expected = '#id { background-image: url(\'../../apps/files/css/../img/image.jpg\'); }'; + $expected = '#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'; $this->assertEquals($expected, $actual); } @@ -393,4 +384,55 @@ class SCSSCacherTest extends \Test\TestCase { $this->assertEquals(substr($result, 1), $actual); } + private function randomString() { + return sha1(uniqid(mt_rand(), true)); + } + + private function rrmdir($directory) { + $files = array_diff(scandir($directory), array('.','..')); + foreach ($files as $file) { + if (is_dir($directory . '/' . $file)) { + $this->rrmdir($directory . '/' . $file); + } else { + unlink($directory . '/' . $file); + } + } + return rmdir($directory); + } + + public function dataGetWebDir() { + return [ + // Root installation + ['/http/core/css', 'core', '', '/http', '/core/css'], + ['/http/apps/scss/css', 'scss', '', '/http', '/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '', '/http', '/apps2/scss/css'], + // Sub directory install + ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'], + ['/http/nextcloud/apps/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/scss/css'], + ['/srv/apps2/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/apps2/scss/css'] + ]; + } + + /** + * @param $path + * @param $appName + * @param $webRoot + * @param $serverRoot + * @dataProvider dataGetWebDir + */ + public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWebDir) { + $tmpDir = sys_get_temp_dir().'/'.$this->randomString(); + // Adding fake apps folder and create fake app install + \OC::$APPSROOTS[] = [ + 'path' => $tmpDir.'/srv/apps2', + 'url' => '/apps2', + 'writable' => false + ]; + mkdir($tmpDir.$path, 0777, true); + $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]); + $this->assertEquals($correctWebDir, $actual); + array_pop(\OC::$APPSROOTS); + $this->rrmdir($tmpDir.$path); + } + } diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index ff04aa17681..89a335722d7 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -161,7 +161,7 @@ class VersionCheckTest extends \Test\TestCase { $this->config ->expects($this->at(6)) ->method('setAppValue') - ->with('core', 'lastupdateResult', 'false'); + ->with('core', 'lastupdateResult', '[]'); $updateXml = 'Invalid XML Response!'; $this->updater @@ -265,4 +265,55 @@ class VersionCheckTest extends \Test\TestCase { $this->assertSame($expectedResult, $this->updater->check()); } + + public function testCheckWithMissingAttributeXmlResponse() { + $expectedResult = [ + 'version' => '', + 'versionstring' => '', + 'url' => '', + 'web' => '', + 'autoupdater' => '', + ]; + + $this->config + ->expects($this->at(0)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue(0)); + $this->config + ->expects($this->at(1)) + ->method('getSystemValue') + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') + ->willReturnArgument(1); + $this->config + ->expects($this->at(2)) + ->method('setAppValue') + ->with('core', 'lastupdatedat', $this->isType('integer')); + $this->config + ->expects($this->at(4)) + ->method('getAppValue') + ->with('core', 'installedat') + ->will($this->returnValue('installedat')); + $this->config + ->expects($this->at(5)) + ->method('getAppValue') + ->with('core', 'lastupdatedat') + ->will($this->returnValue('lastupdatedat')); + + // missing autoupdater element should still not fail + $updateXml = '<?xml version="1.0"?> +<owncloud> + <version></version> + <versionstring></versionstring> + <url></url> + <web></web> +</owncloud>'; + $this->updater + ->expects($this->once()) + ->method('getUrlContent') + ->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/')) + ->will($this->returnValue($updateXml)); + + $this->assertSame($expectedResult, $this->updater->check()); + } } diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 69067f51e08..340c9c7082d 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -27,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase { private $request; /** @var IURLGenerator */ private $urlGenerator; + /** @var string */ + private $originalWebRoot; public function setUp() { parent::setUp(); @@ -38,6 +40,12 @@ class UrlGeneratorTest extends \Test\TestCase { $this->cacheFactory, $this->request ); + $this->originalWebRoot = \OC::$WEBROOT; + } + + public function tearDown() { + // Reset webRoot + \OC::$WEBROOT = $this->originalWebRoot; } private function mockBaseUrl() { @@ -47,7 +55,6 @@ class UrlGeneratorTest extends \Test\TestCase { $this->request->expects($this->once()) ->method('getServerHost') ->willReturn('localhost'); - } /** @@ -156,4 +163,3 @@ class UrlGeneratorTest extends \Test\TestCase { } } - |