diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-24 01:01:36 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-24 01:01:36 +0200 |
commit | c517c845f6c4d1199e1485adb8947e01602659e5 (patch) | |
tree | c587821a0440db48808c64ddcfbd1fa2c5451efe /tests | |
parent | cfac7fcd53974ddf20ddb75a0cb3b5a73047568a (diff) | |
parent | 5fc0535f1b6d94140eed2234e4cb6e38219a74d1 (diff) | |
download | nextcloud-server-c517c845f6c4d1199e1485adb8947e01602659e5.tar.gz nextcloud-server-c517c845f6c4d1199e1485adb8947e01602659e5.zip |
Merge branch 'master' into storage-test-cleanup
Conflicts:
tests/lib/files/storage/storage.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/config.php | 47 | ||||
-rw-r--r-- | tests/lib/db.php | 4 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 8 | ||||
-rw-r--r-- | tests/lib/files/view.php | 9 | ||||
-rw-r--r-- | tests/lib/memcache/cache.php | 2 | ||||
-rw-r--r-- | tests/lib/template/resourcelocator.php | 69 |
6 files changed, 104 insertions, 35 deletions
diff --git a/tests/lib/config.php b/tests/lib/config.php index 87ee2807c2d..1a1d062d688 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -43,26 +43,15 @@ class Test_Config extends PHPUnit_Framework_TestCase { $this->config->setValue('foo', 'moo'); $this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<<EOL -<?php -\$CONFIG = array ( - 'foo' => 'moo', -); -EOL - , $content); + $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n);\n"; + $this->assertEquals($expected, $content); $this->config->setValue('bar', 'red'); $this->assertAttributeEquals(array('foo' => 'moo', 'bar' => 'red'), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<<EOL -<?php -\$CONFIG = array ( - 'foo' => 'moo', - 'bar' => 'red', -); -EOL - , $content); + $expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'bar' => 'red',\n);\n"; + $this->assertEquals($expected, $content); } public function testDeleteKey() { @@ -70,13 +59,9 @@ EOL $this->config->deleteKey('foo'); $this->assertAttributeEquals(array(), 'cache', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<<EOL -<?php -\$CONFIG = array ( -); -EOL - , $content); + $expected = "<?php\n\$CONFIG = array (\n);\n"; + $this->assertEquals($expected, $content); } public function testSavingDebugMode() { @@ -85,14 +70,9 @@ EOL $this->assertAttributeEquals(array(), 'cache', $this->config); $this->assertAttributeEquals(true, 'debugMode', $this->config); $content = file_get_contents(self::CONFIG_FILE); - $this->assertEquals(<<<EOL -<?php -define('DEBUG',true); -\$CONFIG = array ( -); -EOL - , $content); + $expected = "<?php\ndefine('DEBUG',true);\n\$CONFIG = array (\n);\n"; + $this->assertEquals($expected, $content); } /** @@ -100,6 +80,17 @@ EOL */ public function testWriteData() { $config = new OC\Config('/non-writable'); + // TODO never get's called, because the previous call throws the exception + // maybe include some more logic to create a readable dir and then try to + // write to this dir + // + // console commands: + // $ sudo touch /non-writableconfig.php + // $ sudo chmod go-rwx /non-writableconfig.php + // ---- call the tests now -> above statemant throws the exception + // + // $ sudo chmod go+r /non-writableconfig.php + // ---- call the tests now -> bellow statemant throws the exception $config->setValue('foo', 'bar'); } } diff --git a/tests/lib/db.php b/tests/lib/db.php index 69e3542f926..e817a2db5ed 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -37,7 +37,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); $row = $result->fetchRow(); - $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null + $this->assertFalse($row); $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); $this->assertEquals(1, $result); @@ -94,7 +94,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals(4, $result->numRows()); + $this->assertEquals(4, count($result->fetchAll())); } public function testinsertIfNotExistDontOverwrite() { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 46818c3b4a1..3f339a10016 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -168,10 +168,10 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertTrue($this->instance->isReadable('/lorem.txt')); $ctimeEnd = time(); $mTime = $this->instance->filemtime('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 1)); - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); - $this->assertTrue(($ctimeStart - 1) <= $mTime); + $this->assertTrue(($ctimeStart - 5) <= $mTime); $this->assertTrue($mTime <= ($ctimeEnd + 1)); $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); @@ -188,7 +188,7 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $mtimeStart = time(); $this->instance->unlink('/lorem.txt'); - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 1)); + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } public function testFOpen() { diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 830913a91ad..3bac9e770aa 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -20,10 +20,19 @@ class View extends \PHPUnit_Framework_TestCase { private $storages = array(); public function setUp() { + \OC_User::clearBackends(); + \OC_User::useBackend(new \OC_User_Dummy()); + + //login + \OC_User::createUser('test', 'test'); + $this->user=\OC_User::getUser(); + \OC_User::setUserId('test'); + \OC\Files\Filesystem::clearMounts(); } public function tearDown() { + \OC_User::setUserId($this->user); foreach ($this->storages as $storage) { $cache = $storage->getCache(); $ids = $cache->getAll(); diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php index e2643b9fcd9..d07c492cef0 100644 --- a/tests/lib/memcache/cache.php +++ b/tests/lib/memcache/cache.php @@ -9,7 +9,7 @@ namespace Test\Memcache; -class Cache extends \Test_Cache { +abstract class Cache extends \Test_Cache { public function testExistsAfterSet() { $this->assertFalse($this->instance->hasKey('foo')); $this->instance->set('foo', 'bar'); diff --git a/tests/lib/template/resourcelocator.php b/tests/lib/template/resourcelocator.php new file mode 100644 index 00000000000..d80d222e2c9 --- /dev/null +++ b/tests/lib/template/resourcelocator.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_ResourceLocator extends PHPUnit_Framework_TestCase { + public function getResourceLocator( $theme, $form_factor, $core_map, $party_map, $appsroots ) { + return $this->getMockForAbstractClass('OC\Template\ResourceLocator', + array( $theme, $form_factor, $core_map, $party_map, $appsroots ), + '', true, true, true, array()); + } + + public function testConstructor() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $this->assertAttributeEquals('theme', 'theme', $locator); + $this->assertAttributeEquals('form_factor', 'form_factor', $locator); + $this->assertAttributeEquals('core', 'serverroot', $locator); + $this->assertAttributeEquals(array('core'=>'map','3rd'=>'party'), 'mapping', $locator); + $this->assertAttributeEquals('3rd', 'thirdpartyroot', $locator); + $this->assertAttributeEquals('map', 'webroot', $locator); + $this->assertAttributeEquals(array(), 'resources', $locator); + } + + public function testFind() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo'); + $locator->expects($this->once()) + ->method('doFindTheme') + ->with('foo'); + $locator->find(array('foo')); + + $locator = $this->getResourceLocator('theme', 'form_factor', + array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $locator->expects($this->once()) + ->method('doFind') + ->with('foo') + ->will($this->throwException(new Exception('test'))); + try { + $locator->find(array('foo')); + } catch (\Exception $e) { + $this->assertEquals('test formfactor:form_factor serverroot:core', $e->getMessage()); + } + } + + public function testAppendIfExist() { + $locator = $this->getResourceLocator('theme', 'form_factor', + array(__DIR__=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + $method = new ReflectionMethod($locator, 'appendIfExist'); + $method->setAccessible(true); + + $method->invoke($locator, __DIR__, basename(__FILE__), 'webroot'); + $resource1 = array(__DIR__, 'webroot', basename(__FILE__)); + $this->assertEquals(array($resource1), $locator->getResources()); + + $method->invoke($locator, __DIR__, basename(__FILE__)); + $resource2 = array(__DIR__, 'map', basename(__FILE__)); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + + $method->invoke($locator, __DIR__, 'does-not-exist'); + $this->assertEquals(array($resource1, $resource2), $locator->getResources()); + } +} |