diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/CheckSetupControllerTest.php | 1 | ||||
-rw-r--r-- | tests/lib/AppFramework/Http/RequestTest.php | 25 | ||||
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 132 | ||||
-rw-r--r-- | tests/lib/Files/Cache/QuerySearchHelperTest.php | 204 | ||||
-rw-r--r-- | tests/lib/Group/LegacyGroupTest.php | 208 | ||||
-rw-r--r-- | tests/lib/OCS/ProviderTest.php | 66 | ||||
-rw-r--r-- | tests/lib/Repair/NC12/UpdateLanguageCodesTest.php | 28 |
7 files changed, 438 insertions, 226 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index e600f7e5e9c..d9ba7d43672 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -339,6 +339,7 @@ class CheckSetupControllerTest extends TestCase { 'codeIntegrityCheckerDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-code-integrity', 'isOpcacheProperlySetup' => false, 'phpOpcacheDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-php-opcache', + 'isSettimelimitAvailable' => true, ] ); $this->assertEquals($expected, $this->checkSetupController->check()); diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index 6c6504b4de8..cc4bbee2d8d 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -1787,6 +1787,31 @@ class RequestTest extends \Test\TestCase { $this->assertFalse($request->passesLaxCookieCheck()); } + public function testSkipCookieCheckForOCSRequests() { + /** @var Request $request */ + $request = $this->getMockBuilder('\OC\AppFramework\Http\Request') + ->setMethods(['getScriptName']) + ->setConstructorArgs([ + [ + 'server' => [ + 'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds', + 'HTTP_OCS_APIREQUEST' => 'true', + ], + 'cookies' => [ + session_name() => 'asdf', + 'nc_sameSiteCookiestrict' => 'false', + ], + ], + $this->secureRandom, + $this->config, + $this->csrfTokenManager, + $this->stream + ]) + ->getMock(); + + $this->assertTrue($request->passesStrictCookieCheck()); + } + /** * @return array */ diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 4c4f43d63d5..0038cef1f63 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -11,6 +11,10 @@ namespace Test\Files\Cache; use Doctrine\DBAL\Platforms\MySqlPlatform; use OC\Files\Cache\Cache; +use OC\Files\Search\SearchComparison; +use OC\Files\Search\SearchQuery; +use OCP\Files\Search\ISearchComparison; +use OCP\IUser; class LongId extends \OC\Files\Storage\Temporary { public function getId() { @@ -111,15 +115,15 @@ class CacheTest extends \Test\TestCase { * @dataProvider folderDataProvider */ public function testFolder($folder) { - if(strpos($folder, 'F09F9890')) { + if (strpos($folder, 'F09F9890')) { // 4 byte UTF doesn't work on mysql $params = \OC::$server->getDatabaseConnection()->getParams(); - if(\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') { + if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') { $this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8'); } } - $file2 = $folder.'/bar'; - $file3 = $folder.'/foo'; + $file2 = $folder . '/bar'; + $file3 = $folder . '/foo'; $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); $fileData = array(); $fileData['bar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); @@ -138,7 +142,7 @@ class CacheTest extends \Test\TestCase { } } - $file4 = $folder.'/unkownSize'; + $file4 = $folder . '/unkownSize'; $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file'); $this->cache->put($file4, $fileData['unkownSize']); @@ -155,8 +159,8 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(0, $this->cache->calculateFolderSize($folder)); $this->cache->remove($folder); - $this->assertFalse($this->cache->inCache($folder.'/foo')); - $this->assertFalse($this->cache->inCache($folder.'/bar')); + $this->assertFalse($this->cache->inCache($folder . '/foo')); + $this->assertFalse($this->cache->inCache($folder . '/bar')); } public function testRemoveRecursive() { @@ -165,7 +169,7 @@ class CacheTest extends \Test\TestCase { $folders = ['folder', 'folder/subfolder', 'folder/sub2', 'folder/sub2/sub3']; $files = ['folder/foo.txt', 'folder/bar.txt', 'folder/subfolder/asd.txt', 'folder/sub2/qwerty.txt', 'folder/sub2/sub3/foo.txt']; - foreach($folders as $folder){ + foreach ($folders as $folder) { $this->cache->put($folder, $folderData); } foreach ($files as $file) { @@ -360,7 +364,9 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(2, count($results)); - usort($results, function($value1, $value2) { return $value1['name'] >= $value2['name']; }); + usort($results, function ($value1, $value2) { + return $value1['name'] >= $value2['name']; + }); $this->assertEquals('folder', $results[0]['name']); $this->assertEquals('foo', $results[1]['name']); @@ -368,11 +374,15 @@ class CacheTest extends \Test\TestCase { // use tag id $tags = $tagManager->getTagsForUser($userId); $this->assertNotEmpty($tags); - $tags = array_filter($tags, function($tag) { return $tag->getName() === 'tag2'; }); + $tags = array_filter($tags, function ($tag) { + return $tag->getName() === 'tag2'; + }); $results = $this->cache->searchByTag(current($tags)->getId(), $userId); $this->assertEquals(3, count($results)); - usort($results, function($value1, $value2) { return $value1['name'] >= $value2['name']; }); + usort($results, function ($value1, $value2) { + return $value1['name'] >= $value2['name']; + }); $this->assertEquals('folder', $results[0]['name']); $this->assertEquals('foo2', $results[1]['name']); @@ -383,7 +393,99 @@ class CacheTest extends \Test\TestCase { $this->logout(); $user = \OC::$server->getUserManager()->get($userId); - if ($user !== null) { $user->delete(); } + if ($user !== null) { + $user->delete(); + } + } + + function testSearchQueryByTag() { + $userId = static::getUniqueID('user'); + \OC::$server->getUserManager()->createUser($userId, $userId); + static::loginAsUser($userId); + $user = new \OC\User\User($userId, null); + + $file1 = 'folder'; + $file2 = 'folder/foobar'; + $file3 = 'folder/foo'; + $file4 = 'folder/foo2'; + $file5 = 'folder/foo3'; + $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'); + $fileData = array(); + $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); + $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file'); + $fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file'); + $fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file'); + + $id1 = $this->cache->put($file1, $data1); + $id2 = $this->cache->put($file2, $fileData['foobar']); + $id3 = $this->cache->put($file3, $fileData['foo']); + $id4 = $this->cache->put($file4, $fileData['foo2']); + $id5 = $this->cache->put($file5, $fileData['foo3']); + + $tagManager = \OC::$server->getTagManager()->load('files', null, null, $userId); + $this->assertTrue($tagManager->tagAs($id1, 'tag1')); + $this->assertTrue($tagManager->tagAs($id1, 'tag2')); + $this->assertTrue($tagManager->tagAs($id2, 'tag2')); + $this->assertTrue($tagManager->tagAs($id3, 'tag1')); + $this->assertTrue($tagManager->tagAs($id4, 'tag2')); + + $results = $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', 'tag2'), + 0, 0, [], $user + )); + $this->assertEquals(3, count($results)); + + usort($results, function ($value1, $value2) { + return $value1['name'] >= $value2['name']; + }); + + $this->assertEquals('folder', $results[0]['name']); + $this->assertEquals('foo2', $results[1]['name']); + $this->assertEquals('foobar', $results[2]['name']); + + $tagManager->delete('tag1'); + $tagManager->delete('tag2'); + + static::logout(); + $user = \OC::$server->getUserManager()->get($userId); + if ($user !== null) { + $user->delete(); + } + } + + function testSearchByQuery() { + $file1 = 'folder'; + $file2 = 'folder/foobar'; + $file3 = 'folder/foo'; + $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'); + $fileData = array(); + $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); + $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file'); + + $this->cache->put($file1, $data1); + $this->cache->put($file2, $fileData['foobar']); + $this->cache->put($file3, $fileData['foo']); + /** @var IUser $user */ + $user = $this->createMock(IUser::class); + + $this->assertCount(1, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo') + , 10, 0, [], $user))); + $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%') + , 10, 0, [], $user))); + $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'foo/file') + , 10, 0, [], $user))); + $this->assertCount(3, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'foo/%') + , 10, 0, [], $user))); + $this->assertCount(1, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'size', 100) + , 10, 0, [], $user))); + $this->assertCount(2, $this->cache->searchQuery(new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100) + , 10, 0, [], $user))); } function testMove() { @@ -626,9 +728,9 @@ class CacheTest extends \Test\TestCase { public function escapingProvider() { return [ - ['foo'], - ['o%'], - ['oth_r'], + ['foo'], + ['o%'], + ['oth_r'], ]; } diff --git a/tests/lib/Files/Cache/QuerySearchHelperTest.php b/tests/lib/Files/Cache/QuerySearchHelperTest.php new file mode 100644 index 00000000000..f458ef039e1 --- /dev/null +++ b/tests/lib/Files/Cache/QuerySearchHelperTest.php @@ -0,0 +1,204 @@ +<?php +/** + * @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.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\Files\Cache; + +use OC\DB\QueryBuilder\Literal; +use OC\Files\Cache\QuerySearchHelper; +use OC\Files\Search\SearchBinaryOperator; +use OC\Files\Search\SearchComparison; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\IMimeTypeLoader; +use OCP\Files\Search\ISearchBinaryOperator; +use OCP\Files\Search\ISearchComparison; +use OCP\Files\Search\ISearchOperator; +use Test\TestCase; + +/** + * @group DB + */ +class QuerySearchHelperTest extends TestCase { + /** @var IQueryBuilder */ + private $builder; + + /** @var IMimeTypeLoader|\PHPUnit_Framework_MockObject_MockObject */ + private $mimetypeLoader; + + /** @var QuerySearchHelper */ + private $querySearchHelper; + + /** @var integer */ + private $numericStorageId; + + public function setUp() { + parent::setUp(); + $this->builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $this->mimetypeLoader = $this->createMock(IMimeTypeLoader::class); + + $this->mimetypeLoader->expects($this->any()) + ->method('getId') + ->willReturnMap([ + ['text', 1], + ['text/plain', 2], + ['text/xml', 3], + ['image/jpg', 4], + ['image/png', 5], + ['image', 6], + ]); + + $this->mimetypeLoader->expects($this->any()) + ->method('getMimetypeById') + ->willReturnMap([ + [1, 'text'], + [2, 'text/plain'], + [3, 'text/xml'], + [4, 'image/jpg'], + [5, 'image/png'], + [6, 'image'] + ]); + + $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader); + $this->numericStorageId = 10000; + + $this->builder->select(['fileid']) + ->from('filecache') + ->where($this->builder->expr()->eq('storage', new Literal($this->numericStorageId))); + } + + public function tearDown() { + parent::tearDown(); + + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + + $builder->delete('filecache') + ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->numericStorageId, IQueryBuilder::PARAM_INT))); + + $builder->execute(); + } + + private function addCacheEntry(array $data) { + $data['storage'] = $this->numericStorageId; + $data['etag'] = 'unimportant'; + $data['storage_mtime'] = $data['mtime']; + if (!isset($data['path'])) { + $data['path'] = 'random/' . $this->getUniqueID(); + } + $data['path_hash'] = md5($data['path']); + if (!isset($data['mtime'])) { + $data['mtime'] = 100; + } + if (!isset($data['size'])) { + $data['size'] = 100; + } + $data['name'] = basename($data['path']); + $data['parent'] = -1; + if (isset($data['mimetype'])) { + list($mimepart,) = explode('/', $data['mimetype']); + $data['mimepart'] = $this->mimetypeLoader->getId($mimepart); + $data['mimetype'] = $this->mimetypeLoader->getId($data['mimetype']); + } else { + $data['mimepart'] = 1; + $data['mimetype'] = 1; + } + + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + + $values = []; + foreach ($data as $key => $value) { + $values[$key] = $builder->createNamedParameter($value); + } + + $builder->insert('filecache') + ->values($values) + ->execute(); + } + + private function search(ISearchOperator $operator) { + $dbOperator = $this->querySearchHelper->searchOperatorToDBExpr($this->builder, $operator); + $this->builder->andWhere($dbOperator); + return $this->builder->execute()->fetchAll(\PDO::FETCH_COLUMN); + } + + public function comparisonProvider() { + return [ + [new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1002]], + [new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [1001]], + [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 125), []], + [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50), [1001, 1002]], + [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), [1001]], + [new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%'), [1001, 1002]], + [new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'image/jpg'), [1001]], + [new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'image/%'), [1001, 1002]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [ + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'size', 50), + new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [1001] + ]), [1001]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [ + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 100), + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 150), + ]), [1001, 1002]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [ + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mtime', 150), + ]), [1001]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [ + new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), + ]), [1001]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [ + new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), + ]), [1002]], + [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_NOT, [ + new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%bar'), + ]), [1002]], + + ]; + } + + /** + * @dataProvider comparisonProvider + * + * @param ISearchOperator $operator + * @param array $fileIds + */ + public function testComparison(ISearchOperator $operator, array $fileIds) { + $this->addCacheEntry([ + 'path' => 'foobar', + 'fileid' => 1001, + 'mtime' => 100, + 'size' => 50, + 'mimetype' => 'image/jpg' + ]); + + $this->addCacheEntry([ + 'path' => 'fooasd', + 'fileid' => 1002, + 'mtime' => 150, + 'size' => 50, + 'mimetype' => 'image/png' + ]); + + $results = $this->search($operator); + + sort($fileIds); + sort($results); + + $this->assertEquals($fileIds, $results); + } +} diff --git a/tests/lib/Group/LegacyGroupTest.php b/tests/lib/Group/LegacyGroupTest.php deleted file mode 100644 index b7d13437a64..00000000000 --- a/tests/lib/Group/LegacyGroupTest.php +++ /dev/null @@ -1,208 +0,0 @@ -<?php -/** - * ownCloud - * - * @author Robin Appelman - * @author Bernhard Posselt - * @copyright 2012 Robin Appelman <icewind@owncloud.com> - * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library 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 library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace Test\Group; - -use OC_Group; -use OC_User; - -/** - * Class LegacyGroupTest - * - * @package Test\Group - * @group DB - */ -class LegacyGroupTest extends \Test\TestCase { - protected function setUp() { - parent::setUp(); - OC_Group::clearBackends(); - OC_User::clearBackends(); - } - - public function testSingleBackend() { - $userBackend = new \Test\Util\User\Dummy(); - \OC::$server->getUserManager()->registerBackend($userBackend); - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - - $group1 = $this->getUniqueID(); - $group2 = $this->getUniqueID(); - OC_Group::createGroup($group1); - OC_Group::createGroup($group2); - - $user1 = $this->getUniqueID(); - $user2 = $this->getUniqueID(); - $userBackend->createUser($user1, ''); - $userBackend->createUser($user2, ''); - - $this->assertFalse(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is not in group1'); - $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1'); - $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2'); - $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2'); - - $this->assertTrue(OC_Group::addToGroup($user1, $group1)); - - $this->assertTrue(OC_Group::inGroup($user1, $group1), 'Asserting that user1 is in group1'); - $this->assertFalse(OC_Group::inGroup($user2, $group1), 'Asserting that user2 is not in group1'); - $this->assertFalse(OC_Group::inGroup($user1, $group2), 'Asserting that user1 is not in group2'); - $this->assertFalse(OC_Group::inGroup($user2, $group2), 'Asserting that user2 is not in group2'); - - $this->assertTrue(OC_Group::addToGroup($user1, $group1)); - - $this->assertEquals(array($user1), OC_Group::usersInGroup($group1)); - $this->assertEquals(array(), OC_Group::usersInGroup($group2)); - - $this->assertEquals(array($group1), OC_Group::getUserGroups($user1)); - $this->assertEquals(array(), OC_Group::getUserGroups($user2)); - - OC_Group::deleteGroup($group1); - $this->assertEquals(array(), OC_Group::getUserGroups($user1)); - $this->assertEquals(array(), OC_Group::usersInGroup($group1)); - $this->assertFalse(OC_Group::inGroup($user1, $group1)); - } - - - public function testNoEmptyGIDs() { - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - $emptyGroup = null; - - $this->assertFalse(OC_Group::createGroup($emptyGroup)); - } - - - public function testNoGroupsTwice() { - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - $group = $this->getUniqueID(); - OC_Group::createGroup($group); - - $groupCopy = $group; - - OC_Group::createGroup($groupCopy); - $this->assertEquals(array($group), OC_Group::getGroups()); - } - - - public function testDontDeleteAdminGroup() { - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - $adminGroup = 'admin'; - OC_Group::createGroup($adminGroup); - - $this->assertFalse(OC_Group::deleteGroup($adminGroup)); - $this->assertEquals(array($adminGroup), OC_Group::getGroups()); - } - - - public function testDontAddUserToNonexistentGroup() { - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - $groupNonExistent = 'notExistent'; - $user = $this->getUniqueID(); - - $this->assertEquals(false, OC_Group::addToGroup($user, $groupNonExistent)); - $this->assertEquals(array(), OC_Group::getGroups()); - } - - public function testUsersInGroup() { - OC_Group::useBackend(new \Test\Util\Group\Dummy()); - $userBackend = new \Test\Util\User\Dummy(); - \OC::$server->getUserManager()->registerBackend($userBackend); - - $group1 = $this->getUniqueID(); - $group2 = $this->getUniqueID(); - $group3 = $this->getUniqueID(); - $user1 = $this->getUniqueID(); - $user2 = $this->getUniqueID(); - $user3 = $this->getUniqueID(); - OC_Group::createGroup($group1); - OC_Group::createGroup($group2); - OC_Group::createGroup($group3); - - $userBackend->createUser($user1, ''); - $userBackend->createUser($user2, ''); - $userBackend->createUser($user3, ''); - - OC_Group::addToGroup($user1, $group1); - OC_Group::addToGroup($user2, $group1); - OC_Group::addToGroup($user3, $group1); - OC_Group::addToGroup($user3, $group2); - - $this->assertEquals(array($user1, $user2, $user3), - OC_Group::usersInGroups(array($group1, $group2, $group3))); - - // FIXME: needs more parameter variation - } - - public function testMultiBackend() { - $userBackend = new \Test\Util\User\Dummy(); - \OC::$server->getUserManager()->registerBackend($userBackend); - $backend1 = new \Test\Util\Group\Dummy(); - $backend2 = new \Test\Util\Group\Dummy(); - OC_Group::useBackend($backend1); - OC_Group::useBackend($backend2); - - $group1 = $this->getUniqueID(); - $group2 = $this->getUniqueID(); - OC_Group::createGroup($group1); - - //groups should be added to the first registered backend - $this->assertEquals(array($group1), $backend1->getGroups()); - $this->assertEquals(array(), $backend2->getGroups()); - - $this->assertEquals(array($group1), OC_Group::getGroups()); - $this->assertTrue(OC_Group::groupExists($group1)); - $this->assertFalse(OC_Group::groupExists($group2)); - - $backend1->createGroup($group2); - - $this->assertEquals(array($group1, $group2), OC_Group::getGroups()); - $this->assertTrue(OC_Group::groupExists($group1)); - $this->assertTrue(OC_Group::groupExists($group2)); - - $user1 = $this->getUniqueID(); - $user2 = $this->getUniqueID(); - - $userBackend->createUser($user1, ''); - $userBackend->createUser($user2, ''); - - $this->assertFalse(OC_Group::inGroup($user1, $group1)); - $this->assertFalse(OC_Group::inGroup($user2, $group1)); - - - $this->assertTrue(OC_Group::addToGroup($user1, $group1)); - - $this->assertTrue(OC_Group::inGroup($user1, $group1)); - $this->assertFalse(OC_Group::inGroup($user2, $group1)); - $this->assertFalse($backend2->inGroup($user1, $group1)); - - OC_Group::addToGroup($user1, $group1); - - $this->assertEquals(array($user1), OC_Group::usersInGroup($group1)); - - $this->assertEquals(array($group1), OC_Group::getUserGroups($user1)); - $this->assertEquals(array(), OC_Group::getUserGroups($user2)); - - OC_Group::deleteGroup($group1); - $this->assertEquals(array(), OC_Group::getUserGroups($user1)); - $this->assertEquals(array(), OC_Group::usersInGroup($group1)); - $this->assertFalse(OC_Group::inGroup($user1, $group1)); - } -} diff --git a/tests/lib/OCS/ProviderTest.php b/tests/lib/OCS/ProviderTest.php index 399fd3933d9..9444544d12a 100644 --- a/tests/lib/OCS/ProviderTest.php +++ b/tests/lib/OCS/ProviderTest.php @@ -48,11 +48,16 @@ class ProviderTest extends \Test\TestCase { $this->appManager ->expects($this->at(1)) ->method('isEnabledForUser') - ->with('activity') + ->with('federation') ->will($this->returnValue(false)); $this->appManager ->expects($this->at(2)) ->method('isEnabledForUser') + ->with('activity') + ->will($this->returnValue(false)); + $this->appManager + ->expects($this->at(3)) + ->method('isEnabledForUser') ->with('provisioning_api') ->will($this->returnValue(false)); @@ -84,11 +89,16 @@ class ProviderTest extends \Test\TestCase { $this->appManager ->expects($this->at(1)) ->method('isEnabledForUser') - ->with('activity') + ->with('federation') ->will($this->returnValue(false)); $this->appManager ->expects($this->at(2)) ->method('isEnabledForUser') + ->with('activity') + ->will($this->returnValue(false)); + $this->appManager + ->expects($this->at(3)) + ->method('isEnabledForUser') ->with('provisioning_api') ->will($this->returnValue(false)); @@ -124,6 +134,55 @@ class ProviderTest extends \Test\TestCase { $this->assertEquals($expected, $this->ocsProvider->buildProviderList()); } + public function testBuildProviderListWithFederationEnabled() { + $this->appManager + ->expects($this->at(0)) + ->method('isEnabledForUser') + ->with('files_sharing') + ->will($this->returnValue(false)); + $this->appManager + ->expects($this->at(1)) + ->method('isEnabledForUser') + ->with('federation') + ->will($this->returnValue(true)); + $this->appManager + ->expects($this->at(2)) + ->method('isEnabledForUser') + ->with('activity') + ->will($this->returnValue(false)); + $this->appManager + ->expects($this->at(3)) + ->method('isEnabledForUser') + ->with('provisioning_api') + ->will($this->returnValue(false)); + + $expected = new \OCP\AppFramework\Http\JSONResponse( + [ + 'version' => 2, + 'services' => [ + 'PRIVATE_DATA' => [ + 'version' => 1, + 'endpoints' => [ + 'store' => '/ocs/v2.php/privatedata/setattribute', + 'read' => '/ocs/v2.php/privatedata/getattribute', + 'delete' => '/ocs/v2.php/privatedata/deleteattribute', + ], + ], + 'FEDERATED_SHARING' => [ + 'version' => 1, + 'endpoints' => [ + 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', + 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', + 'carddav-user' => 'system' + ], + ], + ], + ] + ); + + $this->assertEquals($expected, $this->ocsProvider->buildProviderList()); + } + public function testBuildProviderListWithEverythingEnabled() { $this->appManager ->expects($this->any()) @@ -147,6 +206,9 @@ class ProviderTest extends \Test\TestCase { 'endpoints' => [ 'share' => '/ocs/v2.php/cloud/shares', 'webdav' => '/public.php/webdav/', + 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', + 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', + 'carddav-user' => 'system' ], ], 'SHARING' => [ diff --git a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php index 95ccd0935a1..4379d1ba589 100644 --- a/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php +++ b/tests/lib/Repair/NC12/UpdateLanguageCodesTest.php @@ -24,6 +24,7 @@ namespace Test\Repair\NC12; use OC\Repair\NC12\UpdateLanguageCodes; +use OCP\IConfig; use OCP\Migration\IOutput; use Test\TestCase; @@ -38,10 +39,14 @@ class UpdateLanguageCodesTest extends TestCase { /** @var \OCP\IDBConnection */ protected $connection; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + private $config; + protected function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); + $this->config = $this->createMock(IConfig::class); } public function testRun() { @@ -112,8 +117,13 @@ class UpdateLanguageCodesTest extends TestCase { ->method('info') ->with('Changed 2 setting(s) from "th_TH" to "th" in preferences table.'); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('version', '0.0.0') + ->willReturn('12.0.0.13'); + // run repair step - $repair = new UpdateLanguageCodes($this->connection); + $repair = new UpdateLanguageCodes($this->connection, $this->config); $repair->run($outputMock); // check if test data is correctly modified in DB @@ -147,4 +157,20 @@ class UpdateLanguageCodesTest extends TestCase { } } + public function testSecondRun() { + /** @var IOutput|\PHPUnit_Framework_MockObject_MockObject $outputMock */ + $outputMock = $this->createMock(IOutput::class); + $outputMock->expects($this->never()) + ->method('info'); + + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('version', '0.0.0') + ->willReturn('12.0.0.14'); + + // run repair step + $repair = new UpdateLanguageCodes($this->connection, $this->config); + $repair->run($outputMock); + } + } |