diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 6 | ||||
-rw-r--r-- | tests/acceptance/composer.json | 4 | ||||
-rw-r--r-- | tests/acceptance/features/app-comments.feature | 9 | ||||
-rw-r--r-- | tests/acceptance/features/app-files-sharing.feature | 59 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/NotificationsContext.php | 2 | ||||
-rw-r--r-- | tests/acceptance/features/bootstrap/SettingsContext.php | 44 | ||||
-rw-r--r-- | tests/lib/AppTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Collaboration/Collaborators/UserPluginTest.php | 144 | ||||
-rw-r--r-- | tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php | 103 | ||||
-rw-r--r-- | tests/lib/Support/Subscription/RegistryTest.php | 18 | ||||
-rw-r--r-- | tests/lib/Updater/ChangesCheckTest.php | 17 | ||||
-rw-r--r-- | tests/lib/User/UserTest.php | 13 |
12 files changed, 370 insertions, 58 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index 284c82310a1..5c66c06a2c5 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -193,6 +193,8 @@ class AvatarControllerTest extends \Test\TestCase { $this->assertEquals(Http::STATUS_OK, $response->getStatus()); $this->assertArrayHasKey('Content-Type', $response->getHeaders()); $this->assertEquals('image type', $response->getHeaders()['Content-Type']); + $this->assertArrayHasKey('X-NC-IsCustomAvatar', $response->getHeaders()); + $this->assertEquals('1', $response->getHeaders()['X-NC-IsCustomAvatar']); $this->assertEquals('my etag', $response->getETag()); } @@ -206,9 +208,11 @@ class AvatarControllerTest extends \Test\TestCase { $response = $this->avatarController->getAvatar('userId', 32); - $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); + $this->assertEquals(Http::STATUS_OK, $response->getStatus()); $this->assertArrayHasKey('Content-Type', $response->getHeaders()); $this->assertEquals('image type', $response->getHeaders()['Content-Type']); + $this->assertArrayHasKey('X-NC-IsCustomAvatar', $response->getHeaders()); + $this->assertEquals('0', $response->getHeaders()['X-NC-IsCustomAvatar']); $this->assertEquals('my etag', $response->getETag()); } diff --git a/tests/acceptance/composer.json b/tests/acceptance/composer.json index 244aa976692..d15d8e13e55 100644 --- a/tests/acceptance/composer.json +++ b/tests/acceptance/composer.json @@ -1,9 +1,9 @@ { "require-dev": { "behat/behat": "^3.0", - "behat/mink": "^1.5", + "behat/mink": "1.7.1", "behat/mink-extension": "*", - "behat/mink-selenium2-driver": "*", + "behat/mink-selenium2-driver": "1.3.1", "phpunit/phpunit": "~4.6" }, "autoload": { diff --git a/tests/acceptance/features/app-comments.feature b/tests/acceptance/features/app-comments.feature index 001d0967c18..b57883d8ba8 100644 --- a/tests/acceptance/features/app-comments.feature +++ b/tests/acceptance/features/app-comments.feature @@ -47,7 +47,6 @@ Feature: app-comments And I create a new comment with "Hello world" as message And I see a comment with "Hello world" as message When I act as Jane - And I accept the share for "shared.txt" in the notifications # The Files app is open again to reload the file list and the comments And I open the Files app And I open the details view for "shared.txt" @@ -64,7 +63,6 @@ Feature: app-comments And I share "shared.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "shared.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app And I open the details view for "shared.txt" @@ -94,7 +92,6 @@ Feature: app-comments And I create a new comment with "Hello world" as message And I see a comment with "Hello world" as message When I act as Jane - And I accept the share for "shared.txt" in the notifications # The Files app is open again to reload the file list and the comments And I open the Files app Then I see that "shared.txt" has unread comments @@ -112,7 +109,6 @@ Feature: app-comments And I share "shared.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "shared.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app And I open the details view for "shared.txt" @@ -141,7 +137,6 @@ Feature: app-comments And I create a new comment with "Hello world" as message And I see a comment with "Hello world" as message When I act as Jane - And I accept the share for "Folder" in the notifications # The Files app is open again to reload the file list and the comments And I open the Files app Then I see that "Folder" has unread comments @@ -159,7 +154,6 @@ Feature: app-comments And I share "Folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I open the details view for "Folder" @@ -190,7 +184,6 @@ Feature: app-comments And I create a new comment with "Hello world" as message And I see a comment with "Hello world" as message When I act as Jane - And I accept the share for "Folder" in the notifications # The Files app is open again to reload the file list and the comments And I open the Files app And I enter in the folder named "Folder" @@ -209,7 +202,6 @@ Feature: app-comments And I share "Folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Folder" @@ -264,7 +256,6 @@ Feature: app-comments And I share "shared.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "shared.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app And I open the details view for "shared.txt" diff --git a/tests/acceptance/features/app-files-sharing.feature b/tests/acceptance/features/app-files-sharing.feature index 15ed42aba6a..e3b0ec30cf8 100644 --- a/tests/acceptance/features/app-files-sharing.feature +++ b/tests/acceptance/features/app-files-sharing.feature @@ -11,7 +11,33 @@ Feature: app-files-sharing When I share "farewell.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "farewell.txt" in the notifications + # The Files app is open again to reload the file list + And I open the Files app + Then I see that the file list contains a file named "farewell.txt" + And I open the details view for "farewell.txt" + And I see that the details view 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 + And I see that the file is shared with me by "admin" + + Scenario: share a file with another user that needs to accept shares + Given I act as John + And I am logged in as the admin + And I act as Jane + And I am logged in + And I visit the settings page + And I open the "Sharing" section + And I disable accepting the shares by default + And I see that shares are not accepted by default + And I act as John + And I rename "welcome.txt" to "farewell.txt" + And I see that the file list contains a file named "farewell.txt" + When I share "farewell.txt" with "user0" + And I see that the file is shared with "user0" + And I act as Jane + And I open the Files app + And I see that the file list does not contain a file named "farewell.txt" + And I accept the share for "/farewell.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app Then I see that the file list contains a file named "farewell.txt" @@ -30,7 +56,6 @@ Feature: app-files-sharing When I share "welcome.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "welcome.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app Then I see that the file list contains a file named "welcome (2).txt" @@ -40,6 +65,24 @@ Feature: app-files-sharing And I see that the "Sharing" tab in the details view is eventually loaded And I see that the file is shared with me by "admin" + Scenario: share a skeleton file with another user before first login + # If a file is shared with a user before her first login the skeleton would + # not have been created, so if the shared file has the same name as one from + # the skeleton the shared file will take its place and the skeleton file + # will not be added. + Given I act as John + And I am logged in as the admin + When I share "welcome.txt" with "user0" + And I see that the file is shared with "user0" + And I act as Jane + And I am logged in + Then I see that the file list contains a file named "welcome.txt" + And I open the details view for "welcome.txt" + And I see that the details view 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 + And I see that the file is shared with me by "admin" + Scenario: reshare a file with another user Given I act as John And I am logged in as the admin @@ -53,13 +96,11 @@ Feature: app-files-sharing And I share "farewell.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "farewell.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app When I share "farewell.txt" with "user1" And I see that the file is shared with "user1" And I act as Jim - And I accept the share for "farewell.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app Then I see that the file list contains a file named "farewell.txt" @@ -80,7 +121,6 @@ Feature: app-files-sharing And I share "farewell.txt" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "farewell.txt" in the notifications # The Files app is open again to reload the file list And I open the Files app And I share "farewell.txt" with "user1" @@ -106,7 +146,6 @@ Feature: app-files-sharing When I share "Shared folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app Then I see that the file list contains a file named "Shared folder" @@ -130,7 +169,6 @@ Feature: app-files-sharing And I create a new folder named "Subfolder" And I see that the file list contains a file named "Subfolder" When I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Shared folder" @@ -147,7 +185,6 @@ Feature: app-files-sharing And I share "Shared folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Shared folder" @@ -170,7 +207,6 @@ Feature: app-files-sharing And I share "Shared folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I share "Shared folder" with "user1" @@ -179,7 +215,6 @@ Feature: app-files-sharing And I create a new folder named "Subfolder" And I see that the file list contains a file named "Subfolder" When I act as Jim - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Shared folder" @@ -198,12 +233,10 @@ Feature: app-files-sharing And I share "Shared folder" with "user0" And I see that the file is shared with "user0" And I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I share "Shared folder" with "user1" And I act as Jim - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Shared folder" @@ -226,7 +259,6 @@ Feature: app-files-sharing And I set the share with "user0" as not reshareable And I see that "user0" can not reshare the share When I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app Then I see that the file list contains a file named "Shared folder" @@ -253,7 +285,6 @@ Feature: app-files-sharing And I create a new folder named "Subfolder" And I see that the file list contains a file named "Subfolder" When I act as Jane - And I accept the share for "Shared folder" in the notifications # The Files app is open again to reload the file list And I open the Files app And I enter in the folder named "Shared folder" diff --git a/tests/acceptance/features/bootstrap/NotificationsContext.php b/tests/acceptance/features/bootstrap/NotificationsContext.php index 6f959f0468c..13717b0ba03 100644 --- a/tests/acceptance/features/bootstrap/NotificationsContext.php +++ b/tests/acceptance/features/bootstrap/NotificationsContext.php @@ -87,7 +87,7 @@ class NotificationsContext implements Context, ActorAwareInterface { // As the waiting is long enough already the find timeout multiplier is // capped at 2 when finding notifications. $findTimeoutMultiplier = $this->actor->getFindTimeoutMultiplier(); - $this->actor->setFindTimeoutMultiplier(max(2, $findTimeoutMultiplier)); + $this->actor->setFindTimeoutMultiplier(min(2, $findTimeoutMultiplier)); $this->actor->find(self::acceptButtonInIncomingShareNotificationForFile($fileName), 35)->click(); $this->actor->setFindTimeoutMultiplier($findTimeoutMultiplier); diff --git a/tests/acceptance/features/bootstrap/SettingsContext.php b/tests/acceptance/features/bootstrap/SettingsContext.php index edbb6a94d15..82b22c43338 100644 --- a/tests/acceptance/features/bootstrap/SettingsContext.php +++ b/tests/acceptance/features/bootstrap/SettingsContext.php @@ -30,6 +30,25 @@ class SettingsContext implements Context, ActorAwareInterface { /** * @return Locator */ + public static function acceptSharesByDefaultCheckbox() { + // forThe()->checkbox("Accept user...") can not be used here; that would + // return the checkbox itself, but the element that the user interacts + // with is the label. + return Locator::forThe()->xpath("//label[normalize-space() = 'Accept user and group shares by default']")-> + describedAs("Accept shares by default checkbox in Sharing section in Personal Sharing Settings"); + } + + /** + * @return Locator + */ + public static function acceptSharesByDefaultCheckboxInput() { + return Locator::forThe()->checkbox("Accept user and group shares by default")-> + describedAs("Accept shares by default checkbox input in Sharing section in Personal Sharing Settings"); + } + + /** + * @return Locator + */ public static function systemTagsSelectTagButton() { return Locator::forThe()->id("s2id_systemtag")-> describedAs("Select tag button in system tags section in Administration Settings"); @@ -85,6 +104,15 @@ class SettingsContext implements Context, ActorAwareInterface { } /** + * @When I disable accepting the shares by default + */ + public function iDisableAcceptingTheSharesByDefault() { + $this->iSeeThatSharesAreAcceptedByDefault(); + + $this->actor->find(self::acceptSharesByDefaultCheckbox(), 2)->click(); + } + + /** * @When I create the tag :tag in the settings */ public function iCreateTheTagInTheSettings($tag) { @@ -94,6 +122,22 @@ class SettingsContext implements Context, ActorAwareInterface { } /** + * @Then I see that shares are accepted by default + */ + public function iSeeThatSharesAreAcceptedByDefault() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked()); + } + + /** + * @Then I see that shares are not accepted by default + */ + public function iSeeThatSharesAreNotAcceptedByDefault() { + PHPUnit_Framework_Assert::assertFalse( + $this->actor->find(self::acceptSharesByDefaultCheckboxInput(), 10)->isChecked()); + } + + /** * @Then I see that the button to select tags is shown */ public function iSeeThatTheButtonToSelectTagsIsShown() { diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 4ef370cd349..412db90849b 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -9,6 +9,7 @@ namespace Test; +use OC\App\AppManager; use OC\App\InfoParser; use OC\AppConfig; use OCP\IAppConfig; @@ -546,8 +547,8 @@ class AppTest extends \Test\TestCase { * @param IAppConfig $appConfig app config mock */ private function registerAppConfig(AppConfig $appConfig) { - $this->overwriteService('AppConfig', $appConfig); - $this->overwriteService('AppManager', new \OC\App\AppManager( + $this->overwriteService(AppConfig::class, $appConfig); + $this->overwriteService(AppManager::class, new \OC\App\AppManager( \OC::$server->getUserSession(), \OC::$server->getConfig(), $appConfig, @@ -562,8 +563,8 @@ class AppTest extends \Test\TestCase { * Restore the original app config service. */ private function restoreAppConfig() { - $this->restoreService('AppConfig'); - $this->restoreService('AppManager'); + $this->restoreService(AppConfig::class); + $this->restoreService(AppManager::class); // Remove the cache of the mocked apps list with a forceRefresh \OC_App::getEnabledApps(); diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index 3aeeaa3eecb..ff916d63b38 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -89,7 +89,27 @@ class UserPluginTest extends TestCase { ); } - public function getUserMock($uid, $displayName, $enabled = true) { + public function mockConfig($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup) { + $this->config->expects($this->any()) + ->method('getAppValue') + ->willReturnCallback( + function($appName, $key, $default) + use ($shareWithGroupOnly, $shareeEnumeration, $shareeEnumerationLimitToGroup) + { + if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') { + return $shareWithGroupOnly ? 'yes' : 'no'; + } else if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { + return $shareeEnumeration ? 'yes' : 'no'; + } else if ($appName === 'core' && $key === 'shareapi_restrict_user_enumeration_to_group') { + return $shareeEnumerationLimitToGroup ? 'yes' : 'no'; + } + return $default; + } + ); + + } + + public function getUserMock($uid, $displayName, $enabled = true, $groups = []) { $user = $this->createMock(IUser::class); $user->expects($this->any()) @@ -383,21 +403,7 @@ class UserPluginTest extends TestCase { $reachedEnd, $singleUser ) { - $this->config->expects($this->any()) - ->method('getAppValue') - ->willReturnCallback( - function($appName, $key, $default) - use ($shareWithGroupOnly, $shareeEnumeration) - { - if ($appName === 'core' && $key === 'shareapi_only_share_with_group_members') { - return $shareWithGroupOnly ? 'yes' : 'no'; - } else if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { - return $shareeEnumeration ? 'yes' : 'no'; - } - return $default; - } - ); - + $this->mockConfig($shareWithGroupOnly, $shareeEnumeration, false); $this->instantiatePlugin(); $this->session->expects($this->any()) @@ -493,4 +499,110 @@ class UserPluginTest extends TestCase { $this->plugin->takeOutCurrentUser($users); $this->assertSame($expectedUIDs, array_keys($users)); } + + public function dataSearchEnumeration() { + return [ + [ + 'test', + ['groupA'], + [ + [ 'uid' => 'test1', 'groups' => ['groupA'] ], + [ 'uid' => 'test2', 'groups' => ['groupB'] ] + ], + ['test1'] + ], + [ + 'test', + ['groupA'], + [ + [ 'uid' => 'test1', 'groups' => ['groupA'] ], + [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ] + ], + ['test1', 'test2'] + ], + [ + 'test', + ['groupA'], + [ + [ 'uid' => 'test1', 'groups' => ['groupA', 'groupC'] ], + [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ] + ], + ['test1', 'test2'] + ], + [ + 'test', + ['groupC', 'groupB'], + [ + [ 'uid' => 'test1', 'groups' => ['groupA', 'groupC'] ], + [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ] + ], + ['test1', 'test2'] + ], + [ + 'test', + [], + [ + [ 'uid' => 'test1', 'groups' => ['groupA'] ], + [ 'uid' => 'test2', 'groups' => ['groupB', 'groupA'] ] + ], + [] + ], + [ + 'test', + ['groupC', 'groupB'], + [ + [ 'uid' => 'test1', 'groups' => [] ], + [ 'uid' => 'test2', 'groups' => [] ] + ], + [] + ], + ]; + } + + /** + * @dataProvider dataSearchEnumeration + */ + public function testSearchEnumerationLimit($search, $userGroups, $matchingUsers, $result) { + $this->mockConfig(false, true, true); + + $userResults = array_map(function ($user) { + return $this->getUserMock($user['uid'], $user['uid']); + }, $matchingUsers); + + $mappedResult = array_map(function ($user) { + return ['label' => $user, 'value' => [ 'shareType' => 0, 'shareWith' => $user ]]; + }, $result); + + $this->userManager->expects($this->once()) + ->method('searchDisplayName') + ->willReturn($userResults); + $this->session->expects($this->any()) + ->method('getUser') + ->willReturn($this->getUserMock('test', 'foo')); + // current user + $this->groupManager->expects($this->at(0)) + ->method('getUserGroupIds') + ->willReturn($userGroups); + $this->groupManager->expects($this->any()) + ->method('getUserGroupIds') + ->willReturnCallback(function ($user) use ($matchingUsers) { + $neededObject = array_filter( + $matchingUsers, + function ($e) use ($user) { + return $user->getUID() === $e['uid']; + } + ); + if (count($neededObject) > 0) { + return array_shift($neededObject)['groups']; + } + return []; + }); + + $this->instantiatePlugin(); + $this->plugin->search($search, $this->limit, $this->offset, $this->searchResult); + $result = $this->searchResult->asArray(); + + $this->assertEquals([], $result['exact']['users']); + $this->assertEquals($mappedResult, $result['users']); + } } diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php index 49dc1d9d823..31b0261cb80 100644 --- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php +++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php @@ -178,15 +178,20 @@ class ContactsStoreTest extends TestCase { $this->config->expects($this->at(1)) ->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes')) + ->willReturn('no'); + + $this->config->expects($this->at(2)) + ->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no')) ->willReturn('yes'); - $this->config->expects($this->at(2)) + $this->config->expects($this->at(3)) ->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no')) ->willReturn('yes'); - $this->config->expects($this->at(3)) + $this->config->expects($this->at(4)) ->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups_list'), $this->equalTo('')) ->willReturn('["group1", "group5", "group6"]'); @@ -223,16 +228,20 @@ class ContactsStoreTest extends TestCase { $this->assertCount(0, $entries); } - public function testGetContactsOnlyIfInTheSameGroup() { + public function testGetContactsOnlyShareIfInTheSameGroup() { $this->config->expects($this->at(0))->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes')) ->willReturn('yes'); $this->config->expects($this->at(1)) ->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes')) + ->willReturn('no'); + + $this->config->expects($this->at(2)) ->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no')) ->willReturn('no'); - $this->config->expects($this->at(2)) + $this->config->expects($this->at(3)) ->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no')) ->willReturn('yes'); @@ -305,6 +314,92 @@ class ContactsStoreTest extends TestCase { $this->assertEquals('contact', $entries[2]->getProperty('UID')); } + public function testGetContactsOnlyEnumerateIfInTheSameGroup() { + $this->config->expects($this->at(0))->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes')) + ->willReturn('yes'); + + $this->config->expects($this->at(1)) ->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_restrict_user_enumeration_to_group'), $this->equalTo('yes')) + ->willReturn('yes'); + + $this->config->expects($this->at(2)) ->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_exclude_groups'), $this->equalTo('no')) + ->willReturn('no'); + + $this->config->expects($this->at(3)) + ->method('getAppValue') + ->with($this->equalTo('core'), $this->equalTo('shareapi_only_share_with_group_members'), $this->equalTo('no')) + ->willReturn('no'); + + /** @var IUser|PHPUnit_Framework_MockObject_MockObject $currentUser */ + $currentUser = $this->createMock(IUser::class); + $currentUser->expects($this->once()) + ->method('getUID') + ->willReturn('user001'); + + $this->groupManager->expects($this->at(0)) + ->method('getUserGroupIds') + ->with($this->equalTo($currentUser)) + ->willReturn(['group1', 'group2', 'group3']); + + $user1 = $this->createMock(IUser::class); + $this->userManager->expects($this->at(0)) + ->method('get') + ->with('user1') + ->willReturn($user1); + $this->groupManager->expects($this->at(1)) + ->method('getUserGroupIds') + ->with($this->equalTo($user1)) + ->willReturn(['group1']); + $user2 = $this->createMock(IUser::class); + $this->userManager->expects($this->at(1)) + ->method('get') + ->with('user2') + ->willReturn($user2); + $this->groupManager->expects($this->at(2)) + ->method('getUserGroupIds') + ->with($this->equalTo($user2)) + ->willReturn(['group2', 'group3']); + $user3 = $this->createMock(IUser::class); + $this->userManager->expects($this->at(2)) + ->method('get') + ->with('user3') + ->willReturn($user3); + $this->groupManager->expects($this->at(3)) + ->method('getUserGroupIds') + ->with($this->equalTo($user3)) + ->willReturn(['group8', 'group9']); + + $this->contactsManager->expects($this->once()) + ->method('search') + ->with($this->equalTo(''), $this->equalTo(['FN', 'EMAIL'])) + ->willReturn([ + [ + 'UID' => 'user1', + 'isLocalSystemBook' => true + ], + [ + 'UID' => 'user2', + 'isLocalSystemBook' => true + ], + [ + 'UID' => 'user3', + 'isLocalSystemBook' => true + ], + [ + 'UID' => 'contact', + ], + ]); + + $entries = $this->contactsStore->getContacts($currentUser, ''); + + $this->assertCount(3, $entries); + $this->assertEquals('user1', $entries[0]->getProperty('UID')); + $this->assertEquals('user2', $entries[1]->getProperty('UID')); + $this->assertEquals('contact', $entries[2]->getProperty('UID')); + } + public function testGetContactsWithFilter() { $this->config->expects($this->at(0))->method('getAppValue') ->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes')) diff --git a/tests/lib/Support/Subscription/RegistryTest.php b/tests/lib/Support/Subscription/RegistryTest.php index 3793026be0f..3e316792682 100644 --- a/tests/lib/Support/Subscription/RegistryTest.php +++ b/tests/lib/Support/Subscription/RegistryTest.php @@ -23,8 +23,10 @@ namespace Test\Support\Subscription; use OC\Support\Subscription\Registry; +use OCP\IConfig; use OCP\Support\Subscription\ISubscription; use OCP\Support\Subscription\ISupportedApps; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RegistryTest extends TestCase { @@ -32,10 +34,14 @@ class RegistryTest extends TestCase { /** @var Registry */ private $registry; + /** @var MockObject|IConfig */ + private $config; + protected function setUp(): void { parent::setUp(); - $this->registry = new Registry(); + $this->config = $this->createMock(IConfig::class); + $this->registry = new Registry($this->config); } /** @@ -74,6 +80,16 @@ class RegistryTest extends TestCase { $this->assertSame(true, $this->registry->delegateHasValidSubscription()); } + public function testDelegateHasValidSubscriptionConfig() { + /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */ + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_valid_subscription') + ->willReturn(true); + + $this->assertSame(true, $this->registry->delegateHasValidSubscription()); + } + public function testDelegateHasExtendedSupport() { /* @var ISubscription|\PHPUnit_Framework_MockObject_MockObject $subscription */ $subscription = $this->createMock(ISubscription::class); diff --git a/tests/lib/Updater/ChangesCheckTest.php b/tests/lib/Updater/ChangesCheckTest.php index 30cb9df2956..1bc8b47e58f 100644 --- a/tests/lib/Updater/ChangesCheckTest.php +++ b/tests/lib/Updater/ChangesCheckTest.php @@ -380,4 +380,21 @@ class ChangesCheckTest extends TestCase { $this->assertTrue(isset($data['whatsNew']['en']['regular'])); $this->assertTrue(isset($data['changelogURL'])); } + + public function testGetChangesForVersionEmptyData() { + $entry = $this->createMock(ChangesResult::class); + $entry->expects($this->once()) + ->method('__call') + ->with('getData') + ->willReturn(''); + + $this->mapper->expects($this->once()) + ->method('getChanges') + ->with('13.0.7') + ->willReturn($entry); + + $this->expectException(DoesNotExistException::class); + /** @noinspection PhpUnhandledExceptionInspection */ + $this->checker->getChangesForVersion('13.0.7'); + } } diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php index 0bf582727ff..8431f14f8a2 100644 --- a/tests/lib/User/UserTest.php +++ b/tests/lib/User/UserTest.php @@ -9,6 +9,7 @@ namespace Test\User; +use OC\AllConfig; use OC\Hooks\PublicEmitter; use OC\User\User; use OCP\Comments\ICommentsManager; @@ -558,15 +559,15 @@ class UserTest extends TestCase { ->method('markProcessed'); } - $this->overwriteService('NotificationManager', $notificationManager); - $this->overwriteService('CommentsManager', $commentsManager); - $this->overwriteService('AllConfig', $config); + $this->overwriteService(\OCP\Notification\IManager::class, $notificationManager); + $this->overwriteService(\OCP\Comments\ICommentsManager::class, $commentsManager); + $this->overwriteService(AllConfig::class, $config); $this->assertSame($result, $user->delete()); - $this->restoreService('AllConfig'); - $this->restoreService('CommentsManager'); - $this->restoreService('NotificationManager'); + $this->restoreService(AllConfig::class); + $this->restoreService(\OCP\Comments\ICommentsManager::class); + $this->restoreService(\OCP\Notification\IManager::class); $this->assertEquals($expectedHooks, $hooksCalled); } |