diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/appframework/http/HttpTest.php | 8 | ||||
-rw-r--r-- | tests/lib/autoloader.php | 2 | ||||
-rw-r--r-- | tests/lib/encryption/keys/storage.php | 59 | ||||
-rw-r--r-- | tests/lib/encryption/managertest.php | 10 | ||||
-rw-r--r-- | tests/lib/encryption/utiltest.php | 19 | ||||
-rw-r--r-- | tests/lib/security/certificatemanager.php | 6 | ||||
-rw-r--r-- | tests/lib/template.php | 72 |
7 files changed, 125 insertions, 51 deletions
diff --git a/tests/lib/appframework/http/HttpTest.php b/tests/lib/appframework/http/HttpTest.php index e9be3e73904..4bcc8305db4 100644 --- a/tests/lib/appframework/http/HttpTest.php +++ b/tests/lib/appframework/http/HttpTest.php @@ -65,6 +65,14 @@ class HttpTest extends \Test\TestCase { } + public function testQuotedEtagMatchReturnsNotModified() { + $http = new Http(array('HTTP_IF_NONE_MATCH' => '"hi"')); + + $header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi'); + $this->assertEquals('HTTP/1.1 304 Not Modified', $header); + } + + public function testLastModifiedMatchReturnsNotModified() { $dateTime = new \DateTime(null, new \DateTimeZone('GMT')); $dateTime->setTimestamp('12'); diff --git a/tests/lib/autoloader.php b/tests/lib/autoloader.php index bf63094a9ef..6d9d3bd8eba 100644 --- a/tests/lib/autoloader.php +++ b/tests/lib/autoloader.php @@ -16,7 +16,7 @@ class AutoLoader extends TestCase { protected function setUp() { parent::setUp(); - $this->loader = new \OC\AutoLoader(); + $this->loader = new \OC\AutoLoader([]); } public function testLeadingSlashOnClassName() { diff --git a/tests/lib/encryption/keys/storage.php b/tests/lib/encryption/keys/storage.php index 2f3aa3527b9..b5b91f886a3 100644 --- a/tests/lib/encryption/keys/storage.php +++ b/tests/lib/encryption/keys/storage.php @@ -37,6 +37,9 @@ class StorageTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ protected $view; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + protected $config; + public function setUp() { parent::setUp(); @@ -48,6 +51,10 @@ class StorageTest extends TestCase { ->disableOriginalConstructor() ->getMock(); + $this->config = $this->getMockBuilder('OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $this->storage = new Storage($this->view, $this->util); } @@ -88,7 +95,7 @@ class StorageTest extends TestCase { * @param bool $originalKeyExists * @param string $expectedKeyContent */ - public function testGetFileKey2($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) { + public function testGetFileKey($path, $strippedPartialName, $originalKeyExists, $expectedKeyContent) { $this->util->expects($this->any()) ->method('getUidAndFilename') ->willReturnMap([ @@ -414,9 +421,12 @@ class StorageTest extends TestCase { * * @param string $path * @param boolean $systemWideMountPoint + * @param string $storageRoot * @param string $expected */ - public function testGetPathToKeys($path, $systemWideMountPoint, $expected) { + public function testGetPathToKeys($path, $systemWideMountPoint, $storageRoot, $expected) { + + $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]); $this->util->expects($this->any()) ->method('getUidAndFilename') @@ -431,10 +441,12 @@ class StorageTest extends TestCase { } public function dataTestGetPathToKeys() { - return array( - array('/user1/files/source.txt', false, '/user1/files_encryption/keys/files/source.txt/'), - array('/user1/files/source.txt', true, '/files_encryption/keys/files/source.txt/') - ); + return [ + ['/user1/files/source.txt', false, '', '/user1/files_encryption/keys/files/source.txt/'], + ['/user1/files/source.txt', true, '', '/files_encryption/keys/files/source.txt/'], + ['/user1/files/source.txt', false, 'storageRoot', '/storageRoot/user1/files_encryption/keys/files/source.txt/'], + ['/user1/files/source.txt', true, 'storageRoot', '/storageRoot/files_encryption/keys/files/source.txt/'], + ]; } public function testKeySetPreparation() { @@ -463,4 +475,39 @@ class StorageTest extends TestCase { $this->assertSame($expected, $args[0]); } + /** + * @dataProvider dataTestGetFileKeyDir + * + * @param bool $isSystemWideMountPoint + * @param string $storageRoot + * @param string $expected + */ + public function testGetFileKeyDir($isSystemWideMountPoint, $storageRoot, $expected) { + + $path = '/user1/files/foo/bar.txt'; + $owner = 'user1'; + $relativePath = '/foo/bar.txt'; + + $this->invokePrivate($this->storage, 'root_dir', [$storageRoot]); + + $this->util->expects($this->once())->method('isSystemWideMountPoint') + ->willReturn($isSystemWideMountPoint); + $this->util->expects($this->once())->method('getUidAndFilename') + ->with($path)->willReturn([$owner, $relativePath]); + + $this->assertSame($expected, + $this->invokePrivate($this->storage, 'getFileKeyDir', ['OC_DEFAULT_MODULE', $path]) + ); + + } + + public function dataTestGetFileKeyDir() { + return [ + [false, '', '/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [true, '', '/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [false, 'newStorageRoot', '/newStorageRoot/user1/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + [true, 'newStorageRoot', '/newStorageRoot/files_encryption/keys/foo/bar.txt/OC_DEFAULT_MODULE/'], + ]; + } + } diff --git a/tests/lib/encryption/managertest.php b/tests/lib/encryption/managertest.php index 9af7bc2c134..6355c706b61 100644 --- a/tests/lib/encryption/managertest.php +++ b/tests/lib/encryption/managertest.php @@ -19,12 +19,20 @@ class ManagerTest extends TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject */ private $l10n; + /** @var \PHPUnit_Framework_MockObject_MockObject */ + private $view; + + /** @var \PHPUnit_Framework_MockObject_MockObject */ + private $util; + public function setUp() { parent::setUp(); $this->config = $this->getMock('\OCP\IConfig'); $this->logger = $this->getMock('\OCP\ILogger'); $this->l10n = $this->getMock('\OCP\Il10n'); - $this->manager = new Manager($this->config, $this->logger, $this->l10n); + $this->view = $this->getMock('\OC\Files\View'); + $this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock(); + $this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util); } public function testManagerIsDisabled() { diff --git a/tests/lib/encryption/utiltest.php b/tests/lib/encryption/utiltest.php index 5aadb4e857f..449326bb351 100644 --- a/tests/lib/encryption/utiltest.php +++ b/tests/lib/encryption/utiltest.php @@ -109,7 +109,11 @@ class UtilTest extends TestCase { /** * @dataProvider providePathsForTestIsExcluded */ - public function testIsExcluded($path, $expected) { + public function testIsExcluded($path, $keyStorageRoot, $expected) { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('core', 'encryption_key_storage_root', '') + ->willReturn($keyStorageRoot); $this->userManager ->expects($this->any()) ->method('userExists') @@ -122,11 +126,14 @@ class UtilTest extends TestCase { public function providePathsForTestIsExcluded() { return array( - array('/files_encryption', true), - array('files_encryption/foo.txt', true), - array('test/foo.txt', false), - array('/user1/files_encryption/foo.txt', true), - array('/user1/files/foo.txt', false), + array('/files_encryption', '', true), + array('files_encryption/foo.txt', '', true), + array('test/foo.txt', '', false), + array('/user1/files_encryption/foo.txt', '', true), + array('/user1/files/foo.txt', '', false), + array('/keyStorage/user1/files/foo.txt', 'keyStorage', true), + array('/keyStorage/files_encryption', '/keyStorage', true), + array('keyStorage/user1/files_encryption', '/keyStorage/', true), ); } diff --git a/tests/lib/security/certificatemanager.php b/tests/lib/security/certificatemanager.php index fab1c208443..092f9efdd18 100644 --- a/tests/lib/security/certificatemanager.php +++ b/tests/lib/security/certificatemanager.php @@ -26,7 +26,11 @@ class CertificateManagerTest extends \Test\TestCase { \OC\Files\Filesystem::tearDown(); \OC_Util::setupFS($this->username); - $this->certificateManager = new CertificateManager($this->username, new \OC\Files\View()); + $config = $this->getMock('OCP\IConfig'); + $config->expects($this->any())->method('getSystemValue') + ->with('installed', false)->willReturn(true); + + $this->certificateManager = new CertificateManager($this->username, new \OC\Files\View(), $config); } protected function tearDown() { diff --git a/tests/lib/template.php b/tests/lib/template.php index db58238eae8..6e62d3955f1 100644 --- a/tests/lib/template.php +++ b/tests/lib/template.php @@ -1,31 +1,31 @@ <?php -/** -* ownCloud -* -* @author Bernhard Posselt -* @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/>. -* -*/ +/** + * ownCloud + * + * @author Bernhard Posselt + * @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/>. + * + */ class Test_TemplateFunctions extends \Test\TestCase { protected function setUp() { parent::setUp(); - $loader = new \OC\Autoloader(); + $loader = new \OC\Autoloader([OC::$SERVERROOT . '/lib']); $loader->load('OC_Template'); } @@ -60,7 +60,7 @@ class Test_TemplateFunctions extends \Test\TestCase { // --------------------------------------------------------------------------- // Test relative_modified_date with dates only // --------------------------------------------------------------------------- - public function testRelativeDateToday(){ + public function testRelativeDateToday() { $currentTime = 1380703592; $elementTime = $currentTime; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -74,7 +74,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('today', $result); } - public function testRelativeDateYesterday(){ + public function testRelativeDateYesterday() { $currentTime = 1380703592; $elementTime = $currentTime - 24 * 3600; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -88,7 +88,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('yesterday', $result); } - public function testRelativeDate2DaysAgo(){ + public function testRelativeDate2DaysAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 48 * 3600; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -102,7 +102,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('2 days ago', $result); } - public function testRelativeDateLastMonth(){ + public function testRelativeDateLastMonth() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 31; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -115,7 +115,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('last month', $result); } - public function testRelativeDateMonthsAgo(){ + public function testRelativeDateMonthsAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 65; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -128,7 +128,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('4 months ago', $result); } - public function testRelativeDateLastYear(){ + public function testRelativeDateLastYear() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 365; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -141,7 +141,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('last year', $result); } - public function testRelativeDateYearsAgo(){ + public function testRelativeDateYearsAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 365.25 * 2; $result = (string)relative_modified_date($elementTime, $currentTime, true); @@ -158,7 +158,7 @@ class Test_TemplateFunctions extends \Test\TestCase { // Test relative_modified_date with timestamps only (date + time value) // --------------------------------------------------------------------------- - public function testRelativeTimeSecondsAgo(){ + public function testRelativeTimeSecondsAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 5; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -166,7 +166,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('seconds ago', $result); } - public function testRelativeTimeMinutesAgo(){ + public function testRelativeTimeMinutesAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 190; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -174,7 +174,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('3 minutes ago', $result); } - public function testRelativeTimeHoursAgo(){ + public function testRelativeTimeHoursAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 7500; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -182,7 +182,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('2 hours ago', $result); } - public function testRelativeTime2DaysAgo(){ + public function testRelativeTime2DaysAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 48 * 3600; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -196,7 +196,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('2 days ago', $result); } - public function testRelativeTimeLastMonth(){ + public function testRelativeTimeLastMonth() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 31; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -209,7 +209,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('last month', $result); } - public function testRelativeTimeMonthsAgo(){ + public function testRelativeTimeMonthsAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 65; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -222,7 +222,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('4 months ago', $result); } - public function testRelativeTimeLastYear(){ + public function testRelativeTimeLastYear() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 365; $result = (string)relative_modified_date($elementTime, $currentTime, false); @@ -235,7 +235,7 @@ class Test_TemplateFunctions extends \Test\TestCase { $this->assertEquals('last year', $result); } - public function testRelativeTimeYearsAgo(){ + public function testRelativeTimeYearsAgo() { $currentTime = 1380703592; $elementTime = $currentTime - 86400 * 365.25 * 2; $result = (string)relative_modified_date($elementTime, $currentTime, false); |