summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/activitymanager.php202
-rw-r--r--tests/lib/appconfig.php66
-rw-r--r--tests/lib/appframework/db/mappertest.php (renamed from tests/lib/appframework/db/MapperTest.php)9
-rw-r--r--tests/lib/appframework/db/mappertestutility.php (renamed from tests/lib/appframework/db/MapperTestUtility.php)2
-rw-r--r--tests/lib/appframework/http/DispatcherTest.php8
-rw-r--r--tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php4
-rw-r--r--tests/lib/appframework/routing/RoutingTest.php8
-rw-r--r--tests/lib/archive/tar.php6
-rw-r--r--tests/lib/connector/sabre/aborteduploaddetectionplugin.php100
-rw-r--r--tests/lib/connector/sabre/file.php51
-rw-r--r--tests/lib/contacts/localadressbook.php95
-rw-r--r--tests/lib/db.php41
-rw-r--r--tests/lib/db/migrator.php44
-rw-r--r--tests/lib/db/mysqlmigration.php39
-rw-r--r--tests/lib/db/sqlitemigration.php39
-rw-r--r--tests/lib/files/cache/cache.php6
-rw-r--r--tests/lib/files/node/folder.php127
-rw-r--r--tests/lib/files/objectstore/swift.php8
-rw-r--r--tests/lib/files/storage/home.php6
-rw-r--r--tests/lib/group/backend.php44
-rw-r--r--tests/lib/group/database.php6
-rw-r--r--tests/lib/group/metadata.php101
-rw-r--r--tests/lib/logger.php2
-rw-r--r--tests/lib/ocs/privatedata.php25
-rw-r--r--tests/lib/preferences-singleton.php172
-rw-r--r--tests/lib/preferences.php219
-rw-r--r--tests/lib/repair/repaircollation.php73
-rw-r--r--tests/lib/repair/repairinnodb.php65
-rw-r--r--tests/lib/share/share.php107
-rw-r--r--tests/lib/user/backend.php17
-rw-r--r--tests/lib/user/database.php3
-rw-r--r--tests/lib/util.php68
-rw-r--r--tests/testcleanuplistener.php33
33 files changed, 1475 insertions, 321 deletions
diff --git a/tests/lib/activitymanager.php b/tests/lib/activitymanager.php
new file mode 100644
index 00000000000..f21b82c52c3
--- /dev/null
+++ b/tests/lib/activitymanager.php
@@ -0,0 +1,202 @@
+<?php
+
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ *
+*/
+
+class Test_ActivityManager extends PHPUnit_Framework_TestCase {
+
+ /** @var \OC\ActivityManager */
+ private $activityManager;
+
+ public function setUp() {
+ $this->activityManager = new \OC\ActivityManager();
+ $this->activityManager->registerExtension(function() {
+ return new NoOpExtension();
+ });
+ $this->activityManager->registerExtension(function() {
+ return new SimpleExtension();
+ });
+ }
+
+ public function testNotificationTypes() {
+ $result = $this->activityManager->getNotificationTypes('en');
+ $this->assertTrue(is_array($result));
+ $this->assertEquals(2, sizeof($result));
+ }
+
+ public function testFilterNotificationTypes() {
+ $result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'FILTER1');
+ $this->assertTrue(is_array($result));
+ $this->assertEquals(3, sizeof($result));
+
+ $result = $this->activityManager->filterNotificationTypes(array('NT0', 'NT1', 'NT2', 'NT3'), 'FILTER2');
+ $this->assertTrue(is_array($result));
+ $this->assertEquals(4, sizeof($result));
+ }
+
+ public function testDefaultTypes() {
+ $result = $this->activityManager->getDefaultTypes('stream');
+ $this->assertTrue(is_array($result));
+ $this->assertEquals(1, sizeof($result));
+
+ $result = $this->activityManager->getDefaultTypes('email');
+ $this->assertTrue(is_array($result));
+ $this->assertEquals(0, sizeof($result));
+ }
+
+ public function testTranslate() {
+ $result = $this->activityManager->translate('APP0', '', '', array(), false, false, 'en');
+ $this->assertEquals('Stupid translation', $result);
+
+ $result = $this->activityManager->translate('APP1', '', '', array(), false, false, 'en');
+ $this->assertFalse($result);
+ }
+
+ public function testTypeIcon() {
+ $result = $this->activityManager->getTypeIcon('NT1');
+ $this->assertEquals('icon-nt-one', $result);
+
+ $result = $this->activityManager->getTypeIcon('NT2');
+ $this->assertEquals('', $result);
+ }
+
+ public function testGroupParameter() {
+ $result = $this->activityManager->getGroupParameter(array());
+ $this->assertEquals(5, $result);
+ }
+
+ public function testNavigation() {
+ $result = $this->activityManager->getNavigation();
+ $this->assertEquals(4, sizeof($result['apps']));
+ $this->assertEquals(2, sizeof($result['top']));
+ }
+
+ public function testIsFilterValid() {
+ $result = $this->activityManager->isFilterValid('fv01');
+ $this->assertTrue($result);
+
+ $result = $this->activityManager->isFilterValid('FV2');
+ $this->assertFalse($result);
+ }
+
+ public function testQueryForFilter() {
+ $result = $this->activityManager->getQueryForFilter('filter1');
+ $this->assertEquals(
+ array(
+ '`app` = ? and `message` like ?',
+ array('mail', 'ownCloud%')
+ ), $result
+ );
+
+ $result = $this->activityManager->isFilterValid('filter2');
+ $this->assertFalse($result);
+ }
+}
+
+class SimpleExtension implements \OCP\Activity\IExtension {
+
+ public function getNotificationTypes($languageCode) {
+ return array('NT1', 'NT2');
+ }
+
+ public function filterNotificationTypes($types, $filter) {
+ if ($filter === 'FILTER1') {
+ unset($types[0]);
+ }
+ return $types;
+ }
+
+ public function getDefaultTypes($method) {
+ if ($method === 'stream') {
+ return array('DT0');
+ }
+
+ return array();
+ }
+
+ public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
+ if ($app === 'APP0') {
+ return "Stupid translation";
+ }
+
+ return false;
+ }
+
+ public function getTypeIcon($type) {
+ if ($type === 'NT1') {
+ return 'icon-nt-one';
+ }
+ return '';
+ }
+
+ public function getGroupParameter($activity) {
+ return 5;
+ }
+
+ public function getNavigation() {
+ return array(
+ 'apps' => array('nav1', 'nav2', 'nav3', 'nav4'),
+ 'top' => array('top1', 'top2')
+ );
+ }
+
+ public function isFilterValid($filterValue) {
+ if ($filterValue === 'fv01') {
+ return true;
+ }
+
+ return false;
+ }
+
+ public function getQueryForFilter($filter) {
+ if ($filter === 'filter1') {
+ return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
+ }
+
+ return false;
+ }
+}
+
+class NoOpExtension implements \OCP\Activity\IExtension {
+
+ public function getNotificationTypes($languageCode) {
+ return false;
+ }
+
+ public function filterNotificationTypes($types, $filter) {
+ return false;
+ }
+
+ public function getDefaultTypes($method) {
+ return false;
+ }
+
+ public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
+ return false;
+ }
+
+ public function getTypeIcon($type) {
+ return false;
+ }
+
+ public function getGroupParameter($activity) {
+ return false;
+ }
+
+ public function getNavigation() {
+ return false;
+ }
+
+ public function isFilterValid($filterValue) {
+ return false;
+ }
+
+ public function getQueryForFilter($filter) {
+ return false;
+ }
+}
diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php
index 6ae790a9edd..9257ae45b0e 100644
--- a/tests/lib/appconfig.php
+++ b/tests/lib/appconfig.php
@@ -95,6 +95,72 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase {
$this->assertEquals('somevalue', $value['configvalue']);
}
+ public function testSetValueUnchanged() {
+ $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+ $statementMock->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue(false));
+
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+ .' WHERE `appid` = ?'), $this->equalTo(array('bar')))
+ ->will($this->returnValue($statementMock));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*appconfig'),
+ $this->equalTo(
+ array(
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->never())
+ ->method('update');
+
+ $appconfig = new OC\AppConfig($connectionMock);
+ $appconfig->setValue('bar', 'foo', 'v1');
+ $appconfig->setValue('bar', 'foo', 'v1');
+ $appconfig->setValue('bar', 'foo', 'v1');
+ }
+
+ public function testSetValueUnchanged2() {
+ $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false);
+ $statementMock->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue(false));
+
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->once())
+ ->method('executeQuery')
+ ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig`'
+ .' WHERE `appid` = ?'), $this->equalTo(array('bar')))
+ ->will($this->returnValue($statementMock));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*appconfig'),
+ $this->equalTo(
+ array(
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo('*PREFIX*appconfig'),
+ $this->equalTo(array('configvalue' => 'v2')),
+ $this->equalTo(array('appid' => 'bar', 'configkey' => 'foo'))
+ );
+
+ $appconfig = new OC\AppConfig($connectionMock);
+ $appconfig->setValue('bar', 'foo', 'v1');
+ $appconfig->setValue('bar', 'foo', 'v2');
+ $appconfig->setValue('bar', 'foo', 'v2');
+ }
+
public function testDeleteKey() {
\OC_Appconfig::deleteKey('testapp', 'deletethis');
$query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?');
diff --git a/tests/lib/appframework/db/MapperTest.php b/tests/lib/appframework/db/mappertest.php
index 4ddc4ef0422..42aa1ade810 100644
--- a/tests/lib/appframework/db/MapperTest.php
+++ b/tests/lib/appframework/db/mappertest.php
@@ -25,9 +25,7 @@
namespace OCP\AppFramework\Db;
use \OCP\IDb;
-
-
-require_once __DIR__ . '/MapperTestUtility.php';
+use Test\AppFramework\Db\MapperTestUtility;
/**
* @method integer getId()
@@ -54,6 +52,9 @@ class ExampleMapper extends Mapper {
class MapperTest extends MapperTestUtility {
+ /**
+ * @var Mapper
+ */
private $mapper;
public function setUp(){
@@ -276,4 +277,4 @@ class MapperTest extends MapperTestUtility {
$result = $this->mapper->findAllEntities($sql);
$this->assertEquals(array($entity1, $entity2), $result);
}
-} \ No newline at end of file
+}
diff --git a/tests/lib/appframework/db/MapperTestUtility.php b/tests/lib/appframework/db/mappertestutility.php
index fc0e5c2c445..0430eef2c21 100644
--- a/tests/lib/appframework/db/MapperTestUtility.php
+++ b/tests/lib/appframework/db/mappertestutility.php
@@ -22,7 +22,7 @@
*/
-namespace OCP\AppFramework\Db;
+namespace Test\AppFramework\Db;
/**
diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php
index 8117eec2075..9d5ec09a293 100644
--- a/tests/lib/appframework/http/DispatcherTest.php
+++ b/tests/lib/appframework/http/DispatcherTest.php
@@ -220,6 +220,10 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
public function testExceptionCallsAfterException() {
+ // TODO fails on PHP 5.3
+ if (version_compare(PHP_VERSION, '5.4.0', '<')) {
+ $this->markTestSkipped('Fails on PHP 5.3');
+ }
$out = 'yo';
$httpHeaders = 'Http';
$responseHeaders = array('hell' => 'yeah');
@@ -235,6 +239,10 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
public function testExceptionThrowsIfCanNotBeHandledByAfterException() {
+ // TODO fails on PHP 5.3 and crashed travis (10 minute timeout)
+ if (version_compare(PHP_VERSION, '5.4.0', '<')) {
+ $this->markTestSkipped('Fails on PHP 5.3 and causes infinite loop - travis fails after 10 minute timeout');
+ }
$out = 'yo';
$httpHeaders = 'Http';
$responseHeaders = array('hell' => 'yeah');
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
index 47556ca9542..74fc7907fb5 100644
--- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
@@ -313,7 +313,8 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
public function testAfterExceptionReturnsRedirect(){
$this->request = new Request(
array('server' =>
- array('HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
+ array('HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
+ 'REQUEST_URI' => 'owncloud/index.php/apps/specialapp')
)
);
$this->middleware = $this->getMiddleware(true, true);
@@ -321,6 +322,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
$this->secException);
$this->assertTrue($response instanceof RedirectResponse);
+ $this->assertEquals('?redirect_url=owncloud%2Findex.php%2Fapps%2Fspecialapp', $response->getRedirectURL());
}
diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php
index 261ab0b26af..7cd07db6ce1 100644
--- a/tests/lib/appframework/routing/RoutingTest.php
+++ b/tests/lib/appframework/routing/RoutingTest.php
@@ -6,7 +6,7 @@ use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\routing\RouteConfig;
-class RouteConfigTest extends \PHPUnit_Framework_TestCase
+class RoutingTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleRoute()
@@ -76,16 +76,16 @@ class RouteConfigTest extends \PHPUnit_Framework_TestCase
public function testResource()
{
- $routes = array('resources' => array('accounts' => array('url' => '/accounts')));
+ $routes = array('resources' => array('account' => array('url' => '/accounts')));
- $this->assertResource($routes, 'accounts', '/accounts', 'AccountsController', 'accountId');
+ $this->assertResource($routes, 'account', '/accounts', 'AccountController', 'id');
}
public function testResourceWithUnderScoreName()
{
$routes = array('resources' => array('admin_accounts' => array('url' => '/admin/accounts')));
- $this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'adminAccountId');
+ $this->assertResource($routes, 'admin_accounts', '/admin/accounts', 'AdminAccountsController', 'id');
}
/**
diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php
index d831487b16f..e66a8740879 100644
--- a/tests/lib/archive/tar.php
+++ b/tests/lib/archive/tar.php
@@ -10,12 +10,6 @@ require_once 'archive.php';
if (!OC_Util::runningOnWindows()) {
class Test_Archive_TAR extends Test_Archive {
- public function setUp() {
- if (floatval(phpversion())>=5.5) {
- $this->markTestSkipped('php 5.5 changed unpack function.');
- return;
- }
- }
protected function getExisting() {
$dir = OC::$SERVERROOT . '/tests/data';
return new OC_Archive_TAR($dir . '/data.tar.gz');
diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
deleted file mode 100644
index 7e9f70ddcd3..00000000000
--- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Thomas Müller <thomas.mueller@tmit.eu>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase {
-
- /**
- * @var \Sabre\DAV\Server
- */
- private $server;
-
- /**
- * @var OC_Connector_Sabre_AbortedUploadDetectionPlugin
- */
- private $plugin;
-
- private function init($view) {
- $this->server = new \Sabre\DAV\Server();
- $this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view);
- $this->plugin->initialize($this->server);
- }
-
- /**
- * @dataProvider lengthProvider
- */
- public function testLength($expected, $headers) {
- $this->init(null);
-
- $this->server->httpRequest = new \Sabre\HTTP\Request($headers);
- $length = $this->plugin->getLength();
- $this->assertEquals($expected, $length);
- }
-
- /**
- * @dataProvider verifyContentLengthProvider
- */
- public function testVerifyContentLength($method, $fileSize, $headers) {
- $this->init($this->buildFileViewMock($fileSize));
-
- $headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre\HTTP\Request($headers);
- $this->plugin->verifyContentLength('foo.txt');
- $this->assertTrue(true);
- }
-
- /**
- * @dataProvider verifyContentLengthFailedProvider
- * @expectedException \Sabre\DAV\Exception\BadRequest
- */
- public function testVerifyContentLengthFailed($method, $fileSize, $headers) {
- $view = $this->buildFileViewMock($fileSize);
- $this->init($view);
- // we expect unlink to be called
- $view->expects($this->once())->method('unlink');
-
- $headers['REQUEST_METHOD'] = $method;
- $this->server->httpRequest = new Sabre\HTTP\Request($headers);
- $this->plugin->verifyContentLength('foo.txt');
- }
-
- public function verifyContentLengthProvider() {
- return array(
- array('PUT', 1024, array()),
- array('PUT', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('PUT', 512, array('HTTP_CONTENT_LENGTH' => '512')),
- array('LOCK', 1024, array()),
- array('LOCK', 1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('LOCK', 512, array('HTTP_CONTENT_LENGTH' => '512')),
- );
- }
-
- public function verifyContentLengthFailedProvider() {
- return array(
- array('PUT', 1025, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array('PUT', 525, array('HTTP_CONTENT_LENGTH' => '512')),
- );
- }
-
- public function lengthProvider() {
- return array(
- array(null, array()),
- array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(512, array('HTTP_CONTENT_LENGTH' => '512')),
- array(2048, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
- );
- }
-
- private function buildFileViewMock($fileSize) {
- // mock filesystem
- $view = $this->getMock('\OC\Files\View', array('filesize', 'unlink'), array(), '', false);
- $view->expects($this->any())->method('filesize')->withAnyParameters()->will($this->returnValue($fileSize));
-
- return $view;
- }
-
-}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index 3dd5b328f46..ba4e775813b 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -29,7 +29,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file = new OC_Connector_Sabre_File($view, $info);
// action
- $etag = $file->put('test data');
+ $file->put('test data');
}
/**
@@ -37,7 +37,9 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
*/
public function testSimplePutFailsOnRename() {
// setup
- $view = $this->getMock('\OC\Files\View', array('file_put_contents', 'rename', 'getRelativePath'), array(), '', false);
+ $view = $this->getMock('\OC\Files\View',
+ array('file_put_contents', 'rename', 'getRelativePath', 'filesize'),
+ array(), '', false);
$view->expects($this->any())
->method('file_put_contents')
->withAnyParameters()
@@ -46,10 +48,14 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
->method('rename')
->withAnyParameters()
->will($this->returnValue(false));
-
$view->expects($this->any())
->method('getRelativePath')
->will($this->returnValue('/test.txt'));
+ $view->expects($this->any())
+ ->method('filesize')
+ ->will($this->returnValue(123456));
+
+ $_SERVER['CONTENT_LENGTH'] = 123456;
$info = new \OC\Files\FileInfo('/test.txt', null, null, array(
'permissions' => \OCP\PERMISSION_ALL
@@ -58,7 +64,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file = new OC_Connector_Sabre_File($view, $info);
// action
- $etag = $file->put('test data');
+ $file->put('test data');
}
/**
@@ -81,7 +87,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file = new OC_Connector_Sabre_File($view, $info);
// action
- $etag = $file->put('test data');
+ $file->put('test data');
}
/**
@@ -102,4 +108,39 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase {
$file = new OC_Connector_Sabre_File($view, $info);
$file->setName('/super*star.txt');
}
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ public function testUploadAbort() {
+ // setup
+ $view = $this->getMock('\OC\Files\View',
+ array('file_put_contents', 'rename', 'getRelativePath', 'filesize'),
+ array(), '', false);
+ $view->expects($this->any())
+ ->method('file_put_contents')
+ ->withAnyParameters()
+ ->will($this->returnValue(true));
+ $view->expects($this->any())
+ ->method('rename')
+ ->withAnyParameters()
+ ->will($this->returnValue(false));
+ $view->expects($this->any())
+ ->method('getRelativePath')
+ ->will($this->returnValue('/test.txt'));
+ $view->expects($this->any())
+ ->method('filesize')
+ ->will($this->returnValue(123456));
+
+ $_SERVER['CONTENT_LENGTH'] = 12345;
+
+ $info = new \OC\Files\FileInfo('/test.txt', null, null, array(
+ 'permissions' => \OCP\PERMISSION_ALL
+ ));
+
+ $file = new OC_Connector_Sabre_File($view, $info);
+
+ // action
+ $file->put('test data');
+ }
}
diff --git a/tests/lib/contacts/localadressbook.php b/tests/lib/contacts/localadressbook.php
new file mode 100644
index 00000000000..bb69910820f
--- /dev/null
+++ b/tests/lib/contacts/localadressbook.php
@@ -0,0 +1,95 @@
+<?php
+use OC\Contacts\LocalAddressBook;
+
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2014 Thomas Müller thomas.mueller@tmit.eu
+ *
+ * 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_LocalAddressBook extends PHPUnit_Framework_TestCase
+{
+
+ public function testSearchFN() {
+ $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName'));
+
+ $stub->expects($this->any())->method('searchDisplayName')->will($this->returnValue(array(
+ new SimpleUserForTesting('tom', 'Thomas'),
+ new SimpleUserForTesting('tomtom', 'Thomas T.'),
+ )));
+
+ $localAddressBook = new LocalAddressBook($stub);
+
+ $result = $localAddressBook->search('tom', array('FN'), array());
+ $this->assertEquals(2, count($result));
+ }
+
+ public function testSearchId() {
+ $stub = $this->getMockForAbstractClass('\OCP\IUserManager', array('searchDisplayName'));
+
+ $stub->expects($this->any())->method('search')->will($this->returnValue(array(
+ new SimpleUserForTesting('tom', 'Thomas'),
+ new SimpleUserForTesting('tomtom', 'Thomas T.'),
+ )));
+
+ $localAddressBook = new LocalAddressBook($stub);
+
+ $result = $localAddressBook->search('tom', array('id'), array());
+ $this->assertEquals(2, count($result));
+ }
+}
+
+
+class SimpleUserForTesting implements \OCP\IUser {
+
+ public function __construct($uid, $displayName) {
+
+ $this->uid = $uid;
+ $this->displayName = $displayName;
+ }
+
+ public function getUID() {
+ return $this->uid;
+ }
+
+ public function getDisplayName() {
+ return $this->displayName;
+ }
+
+ public function setDisplayName($displayName) {
+ }
+
+ public function getLastLogin() {
+ }
+
+ public function updateLastLoginTimestamp() {
+ }
+
+ public function delete() {
+ }
+
+ public function setPassword($password, $recoveryPassword = null) {
+ }
+
+ public function getHome() {
+ }
+
+ public function canChangeAvatar() {
+ }
+
+ public function canChangePassword() {
+ }
+
+ public function canChangeDisplayName() {
+ }
+
+ public function isEnabled() {
+ }
+
+ public function setEnabled($enabled) {
+ }
+}
diff --git a/tests/lib/db.php b/tests/lib/db.php
index 2fca67b5638..4b1a474c4ef 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -200,4 +200,45 @@ class Test_DB extends PHPUnit_Framework_TestCase {
}
}
+ public function testUpdateAffectedRowsNoMatch() {
+ $this->insertCardData('fullname1', 'uri1');
+ // The WHERE clause does not match any rows
+ $this->assertSame(0, $this->updateCardData('fullname3', 'uri2'));
+ }
+
+ public function testUpdateAffectedRowsDifferent() {
+ $this->insertCardData('fullname1', 'uri1');
+ // The WHERE clause matches a single row and the value we are updating
+ // is different from the one already present.
+ $this->assertSame(1, $this->updateCardData('fullname1', 'uri2'));
+ }
+
+ public function testUpdateAffectedRowsSame() {
+ $this->insertCardData('fullname1', 'uri1');
+ // The WHERE clause matches a single row and the value we are updating
+ // to is the same as the one already present. MySQL reports 0 here when
+ // the PDO::MYSQL_ATTR_FOUND_ROWS flag is not specified.
+ $this->assertSame(1, $this->updateCardData('fullname1', 'uri1'));
+ }
+
+ public function testUpdateAffectedRowsMultiple() {
+ $this->insertCardData('fullname1', 'uri1');
+ $this->insertCardData('fullname2', 'uri2');
+ // The WHERE clause matches two rows. One row contains a value that
+ // needs to be updated, the other one already contains the value we are
+ // updating to. MySQL reports 1 here when the PDO::MYSQL_ATTR_FOUND_ROWS
+ // flag is not specified.
+ $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ?");
+ $this->assertSame(2, $query->execute(array('uri1')));
+ }
+
+ protected function insertCardData($fullname, $uri) {
+ $query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)");
+ $this->assertSame(1, $query->execute(array($fullname, $uri, uniqid())));
+ }
+
+ protected function updateCardData($fullname, $uri) {
+ $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ? WHERE `fullname` = ?");
+ return $query->execute(array($uri, $fullname));
+ }
}
diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php
index e94d550f836..2e49086bd63 100644
--- a/tests/lib/db/migrator.php
+++ b/tests/lib/db/migrator.php
@@ -19,6 +19,11 @@ class Migrator extends \PHPUnit_Framework_TestCase {
*/
private $connection;
+ /**
+ * @var \OC\DB\MDB2SchemaManager
+ */
+ private $manager;
+
private $tableName;
public function setUp() {
@@ -26,6 +31,7 @@ class Migrator extends \PHPUnit_Framework_TestCase {
if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) {
$this->markTestSkipped('DB migration tests arent supported on OCI');
}
+ $this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
$this->tableName = 'test_' . uniqid();
}
@@ -62,14 +68,6 @@ class Migrator extends \PHPUnit_Framework_TestCase {
return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver;
}
- private function getMigrator() {
- if ($this->isSQLite()) {
- return new \OC\DB\SQLiteMigrator($this->connection);
- } else {
- return new \OC\DB\Migrator($this->connection);
- }
- }
-
/**
* @expectedException \OC\DB\MigrationException
*/
@@ -78,7 +76,7 @@ class Migrator extends \PHPUnit_Framework_TestCase {
$this->markTestSkipped('sqlite doesnt throw errors when creating a new key on existing data');
}
list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
- $migrator = $this->getMigrator();
+ $migrator = $this->manager->getMigrator();
$migrator->migrate($startSchema);
$this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
@@ -91,7 +89,7 @@ class Migrator extends \PHPUnit_Framework_TestCase {
public function testUpgrade() {
list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
- $migrator = $this->getMigrator();
+ $migrator = $this->manager->getMigrator();
$migrator->migrate($startSchema);
$this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
@@ -105,7 +103,7 @@ class Migrator extends \PHPUnit_Framework_TestCase {
public function testInsertAfterUpgrade() {
list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
- $migrator = $this->getMigrator();
+ $migrator = $this->manager->getMigrator();
$migrator->migrate($startSchema);
$migrator->migrate($endSchema);
@@ -132,7 +130,29 @@ class Migrator extends \PHPUnit_Framework_TestCase {
$table->addColumn('name', 'string');
$table->setPrimaryKey(array('id'));
- $migrator = $this->getMigrator();
+ $migrator = $this->manager->getMigrator();
+ $migrator->migrate($startSchema);
+
+ $migrator->checkMigrate($endSchema);
+ $migrator->migrate($endSchema);
+
+ $this->assertTrue(true);
+ }
+
+ public function testReservedKeywords() {
+ $startSchema = new Schema(array(), array(), $this->getSchemaConfig());
+ $table = $startSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer', array('autoincrement' => true));
+ $table->addColumn('user', 'string', array('length' => 255));
+ $table->setPrimaryKey(array('id'));
+
+ $endSchema = new Schema(array(), array(), $this->getSchemaConfig());
+ $table = $endSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer', array('autoincrement' => true));
+ $table->addColumn('user', 'string', array('length' => 64));
+ $table->setPrimaryKey(array('id'));
+
+ $migrator = $this->manager->getMigrator();
$migrator->migrate($startSchema);
$migrator->checkMigrate($endSchema);
diff --git a/tests/lib/db/mysqlmigration.php b/tests/lib/db/mysqlmigration.php
new file mode 100644
index 00000000000..584df1d4465
--- /dev/null
+++ b/tests/lib/db/mysqlmigration.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class TestMySqlMigration extends \PHPUnit_Framework_TestCase {
+
+ /** @var \Doctrine\DBAL\Connection */
+ private $connection;
+
+ /** @var string */
+ private $tableName;
+
+ public function setUp() {
+ $this->connection = \OC_DB::getConnection();
+ if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
+ $this->markTestSkipped("Test only relevant on MySql");
+ }
+
+ $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
+ $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
+ $this->connection->exec("CREATE TABLE $this->tableName(b BIT, e ENUM('1','2','3','4'))");
+ }
+
+ public function tearDown() {
+ $this->connection->getSchemaManager()->dropTable($this->tableName);
+ }
+
+ public function testNonOCTables() {
+ $manager = new \OC\DB\MDB2SchemaManager($this->connection);
+ $manager->updateDbFromStructure(__DIR__ . '/testschema.xml');
+
+ $this->assertTrue(true);
+ }
+
+}
diff --git a/tests/lib/db/sqlitemigration.php b/tests/lib/db/sqlitemigration.php
new file mode 100644
index 00000000000..adfc03a2ca7
--- /dev/null
+++ b/tests/lib/db/sqlitemigration.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class TestSqliteMigration extends \PHPUnit_Framework_TestCase {
+
+ /** @var \Doctrine\DBAL\Connection */
+ private $connection;
+
+ /** @var string */
+ private $tableName;
+
+ public function setUp() {
+ $this->connection = \OC_DB::getConnection();
+ if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
+ $this->markTestSkipped("Test only relevant on Sqlite");
+ }
+
+ $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
+ $this->tableName = uniqid($dbPrefix . "_enum_bit_test");
+ $this->connection->exec("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)");
+ }
+
+ public function tearDown() {
+ $this->connection->getSchemaManager()->dropTable($this->tableName);
+ }
+
+ public function testNonOCTables() {
+ $manager = new \OC\DB\MDB2SchemaManager($this->connection);
+ $manager->updateDbFromStructure(__DIR__ . '/testschema.xml');
+
+ $this->assertTrue(true);
+ }
+
+}
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 8ed2ecabd98..bf17f7a1620 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -239,6 +239,12 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($this->cache->search('folder%')));
$this->assertEquals(3, count($this->cache->search('%')));
+ // case insensitive search should match the same files
+ $this->assertEquals(2, count($this->cache->search('%Foo%')));
+ $this->assertEquals(1, count($this->cache->search('Foo')));
+ $this->assertEquals(1, count($this->cache->search('%Folder%')));
+ $this->assertEquals(1, count($this->cache->search('Folder%')));
+
$this->assertEquals(3, count($this->cache->searchByMime('foo')));
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php
index 08200f35f57..436161aba72 100644
--- a/tests/lib/files/node/folder.php
+++ b/tests/lib/files/node/folder.php
@@ -9,6 +9,7 @@
namespace Test\Files\Node;
use OC\Files\Cache\Cache;
+use OC\Files\Mount\Mount;
use OC\Files\Node\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
@@ -468,4 +469,130 @@ class Folder extends \PHPUnit_Framework_TestCase {
$file = new Node(null, null, '/foobar');
$this->assertFalse($folder->isSubNode($file));
}
+
+ public function testGetById() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $mount = new Mount($storage, '/bar');
+ $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+
+ $view->expects($this->once())
+ ->method('file_exists')
+ ->will($this->returnValue(true));
+
+ $storage->expects($this->once())
+ ->method('getCache')
+ ->will($this->returnValue($cache));
+
+ $cache->expects($this->once())
+ ->method('getPathById')
+ ->with('1')
+ ->will($this->returnValue('foo/qwerty'));
+
+ $root->expects($this->once())
+ ->method('getMountsIn')
+ ->with('/bar/foo')
+ ->will($this->returnValue(array()));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount));
+
+ $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $result = $node->getById(1);
+ $this->assertEquals(1, count($result));
+ $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
+ }
+
+ public function testGetByIdOutsideFolder() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $mount = new Mount($storage, '/bar');
+ $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+
+ $storage->expects($this->once())
+ ->method('getCache')
+ ->will($this->returnValue($cache));
+
+ $cache->expects($this->once())
+ ->method('getPathById')
+ ->with('1')
+ ->will($this->returnValue('foobar'));
+
+ $root->expects($this->once())
+ ->method('getMountsIn')
+ ->with('/bar/foo')
+ ->will($this->returnValue(array()));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount));
+
+ $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $result = $node->getById(1);
+ $this->assertCount(0, $result);
+ }
+
+ public function testGetByIdMultipleStorages() {
+ $manager = $this->getMock('\OC\Files\Mount\Manager');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user));
+ $root->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($this->user));
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ $mount1 = new Mount($storage, '/bar');
+ $mount2 = new Mount($storage, '/bar/foo/asd');
+ $cache = $this->getMock('\OC\Files\Cache\Cache', array(), array(''));
+
+ $view->expects($this->any())
+ ->method('file_exists')
+ ->will($this->returnValue(true));
+
+ $storage->expects($this->any())
+ ->method('getCache')
+ ->will($this->returnValue($cache));
+
+ $cache->expects($this->any())
+ ->method('getPathById')
+ ->with('1')
+ ->will($this->returnValue('foo/qwerty'));
+
+ $root->expects($this->any())
+ ->method('getMountsIn')
+ ->with('/bar/foo')
+ ->will($this->returnValue(array($mount2)));
+
+ $root->expects($this->once())
+ ->method('getMount')
+ ->with('/bar/foo')
+ ->will($this->returnValue($mount1));
+
+ $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
+ $result = $node->getById(1);
+ $this->assertEquals(2, count($result));
+ $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
+ $this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath());
+ }
}
diff --git a/tests/lib/files/objectstore/swift.php b/tests/lib/files/objectstore/swift.php
index 7f3b45c0dab..900367553d7 100644
--- a/tests/lib/files/objectstore/swift.php
+++ b/tests/lib/files/objectstore/swift.php
@@ -31,6 +31,9 @@ class Swift extends \Test\Files\Storage\Storage {
private $objectStorage;
public function setUp() {
+ if (!getenv('RUN_OBJECTSTORE_TESTS')) {
+ $this->markTestSkipped('objectstore tests are unreliable on travis');
+ }
\OC_App::disable('files_sharing');
\OC_App::disable('files_versions');
@@ -80,6 +83,11 @@ class Swift extends \Test\Files\Storage\Storage {
}
public function testStat() {
+ // TODO travis
+ if (getenv('TRAVIS')) {
+ $this->markTestSkipped('Fails on travis - connection times out sometimes');
+ }
+
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php
index 51315a2a556..953fcfc8a6a 100644
--- a/tests/lib/files/storage/home.php
+++ b/tests/lib/files/storage/home.php
@@ -53,6 +53,8 @@ class Home extends Storage {
*/
private $tmpDir;
+ private $userId;
+
/**
* @var \OC\User\User $user
*/
@@ -97,4 +99,8 @@ class Home extends Storage {
public function testGetCacheReturnsHomeCache() {
$this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache());
}
+
+ public function testGetOwner() {
+ $this->assertEquals($this->userId, $this->instance->getOwner(''));
+ }
}
diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php
index 2c563ae9ac9..95a5cf5f49c 100644
--- a/tests/lib/group/backend.php
+++ b/tests/lib/group/backend.php
@@ -31,8 +31,12 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
* test cases can override this in order to clean up created groups
* @return string
*/
- public function getGroupName() {
- return uniqid('test_');
+ public function getGroupName($name = null) {
+ if(is_null($name)) {
+ return uniqid('test_');
+ } else {
+ return $name;
+ }
}
/**
@@ -88,7 +92,7 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
$this->assertFalse($this->backend->inGroup($user2, $group1));
$this->assertFalse($this->backend->inGroup($user1, $group2));
$this->assertFalse($this->backend->inGroup($user2, $group2));
-
+
$this->assertFalse($this->backend->addToGroup($user1, $group1));
$this->assertEquals(array($user1), $this->backend->usersInGroup($group1));
@@ -102,4 +106,38 @@ abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
$this->assertEquals(array(), $this->backend->usersInGroup($group1));
$this->assertFalse($this->backend->inGroup($user1, $group1));
}
+
+ public function testSearchGroups() {
+ $name1 = $this->getGroupName('foobarbaz');
+ $name2 = $this->getGroupName('bazbarfoo');
+ $name3 = $this->getGroupName('notme');
+
+ $this->backend->createGroup($name1);
+ $this->backend->createGroup($name2);
+ $this->backend->createGroup($name3);
+
+ $result = $this->backend->getGroups('bar');
+ $this->assertSame(2, count($result));
+ }
+
+ public function testSearchUsers() {
+ $group = $this->getGroupName();
+ $this->backend->createGroup($group);
+
+ $name1 = 'foobarbaz';
+ $name2 = 'bazbarfoo';
+ $name3 = 'notme';
+
+ $this->backend->addToGroup($name1, $group);
+ $this->backend->addToGroup($name2, $group);
+ $this->backend->addToGroup($name3, $group);
+
+ $result = $this->backend->usersInGroup($group, 'bar');
+ $this->assertSame(2, count($result));
+
+ $result = $this->backend->countUsersInGroup($group, 'bar');
+ $this->assertSame(2, $result);
+ }
+
+
}
diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php
index 3e05c656061..9b39ac00452 100644
--- a/tests/lib/group/database.php
+++ b/tests/lib/group/database.php
@@ -28,8 +28,10 @@ class Test_Group_Database extends Test_Group_Backend {
* test cases can override this in order to clean up created groups
* @return string
*/
- public function getGroupName() {
- $name=uniqid('test_');
+ public function getGroupName($name = null) {
+ if(is_null($name)) {
+ $name=uniqid('test_');
+ }
$this->groups[]=$name;
return $name;
}
diff --git a/tests/lib/group/metadata.php b/tests/lib/group/metadata.php
new file mode 100644
index 00000000000..7ef2d6b35ff
--- /dev/null
+++ b/tests/lib/group/metadata.php
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * Copyright (c) 2014 Arthur Schiwon <blizzz@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Group;
+
+class Test_MetaData extends \PHPUnit_Framework_TestCase {
+ private function getGroupManagerMock() {
+ return $this->getMockBuilder('\OC\Group\Manager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ private function getGroupMock() {
+ $group = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $group->expects($this->exactly(9))
+ ->method('getGID')
+ ->will($this->onConsecutiveCalls(
+ 'admin', 'admin', 'admin',
+ 'g2', 'g2', 'g2',
+ 'g3', 'g3', 'g3'));
+
+ $group->expects($this->exactly(3))
+ ->method('count')
+ ->with('')
+ ->will($this->onConsecutiveCalls(2, 3, 5));
+
+ return $group;
+ }
+
+
+ public function testGet() {
+ $groupManager = $this->getGroupManagerMock();
+ $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager);
+ $group = $this->getGroupMock();
+ $groups = array_fill(0, 3, $group);
+
+ $groupManager->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue($groups));
+
+ list($adminGroups, $ordinaryGroups) = $groupMetaData->get();
+
+ $this->assertSame(1, count($adminGroups));
+ $this->assertSame(2, count($ordinaryGroups));
+
+ $this->assertSame('g2', $ordinaryGroups[0]['name']);
+ $this->assertSame(3, $ordinaryGroups[0]['usercount']);
+ }
+
+ public function testGetWithSorting() {
+ $groupManager = $this->getGroupManagerMock();
+ $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager);
+ $groupMetaData->setSorting($groupMetaData::SORT_USERCOUNT);
+ $group = $this->getGroupMock();
+ $groups = array_fill(0, 3, $group);
+
+ $groupManager->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue($groups));
+
+ list($adminGroups, $ordinaryGroups) = $groupMetaData->get();
+
+ $this->assertSame(1, count($adminGroups));
+ $this->assertSame(2, count($ordinaryGroups));
+
+ $this->assertSame('g3', $ordinaryGroups[0]['name']);
+ $this->assertSame(5, $ordinaryGroups[0]['usercount']);
+ }
+
+ public function testGetWithCache() {
+ $groupManager = $this->getGroupManagerMock();
+ $groupMetaData = new \OC\Group\MetaData('foo', true, $groupManager);
+ $group = $this->getGroupMock();
+ $groups = array_fill(0, 3, $group);
+
+ $groupManager->expects($this->once())
+ ->method('search')
+ ->with('')
+ ->will($this->returnValue($groups));
+
+ //two calls, if caching fails call counts for group and groupmanager
+ //are exceeded
+ $groupMetaData->get();
+ $groupMetaData->get();
+ }
+
+ //get() does not need to be tested with search parameters, because they are
+ //solely and only passed to GroupManager and Group.
+
+}
diff --git a/tests/lib/logger.php b/tests/lib/logger.php
index 7d5d4049b28..fcdf5b58670 100644
--- a/tests/lib/logger.php
+++ b/tests/lib/logger.php
@@ -19,7 +19,7 @@ class Logger extends \PHPUnit_Framework_TestCase {
public function setUp() {
self::$logs = array();
- $this->logger = new Log($this);
+ $this->logger = new Log('Test\Logger');
}
public function testInterpolation() {
diff --git a/tests/lib/ocs/privatedata.php b/tests/lib/ocs/privatedata.php
index 498ab718621..530750fabea 100644
--- a/tests/lib/ocs/privatedata.php
+++ b/tests/lib/ocs/privatedata.php
@@ -79,6 +79,31 @@ class Test_OC_OCS_Privatedata extends PHPUnit_Framework_TestCase
$this->assertEquals('updated', $data['value']);
}
+ public function testSetSameValue() {
+ $_POST = array('value' => 123456789);
+ $params = array('app' => $this->appKey, 'key' => 'k-10');
+ $result = OC_OCS_Privatedata::set($params);
+ $this->assertEquals(100, $result->getStatusCode());
+
+ $result = OC_OCS_Privatedata::get($params);
+ $this->assertOcsResult(1, $result);
+ $data = $result->getData();
+ $data = $data[0];
+ $this->assertEquals('123456789', $data['value']);
+
+ // set the same value again
+ $_POST = array('value' => 123456789);
+ $params = array('app' => $this->appKey, 'key' => 'k-10');
+ $result = OC_OCS_Privatedata::set($params);
+ $this->assertEquals(100, $result->getStatusCode());
+
+ $result = OC_OCS_Privatedata::get($params);
+ $this->assertOcsResult(1, $result);
+ $data = $result->getData();
+ $data = $data[0];
+ $this->assertEquals('123456789', $data['value']);
+ }
+
public function testSetMany() {
$_POST = array('value' => 123456789);
diff --git a/tests/lib/preferences-singleton.php b/tests/lib/preferences-singleton.php
new file mode 100644
index 00000000000..7abf5a6be36
--- /dev/null
+++ b/tests/lib/preferences-singleton.php
@@ -0,0 +1,172 @@
+<?php
+/**
+ * Copyright (c) 2013 Christopher Schäpers <christopher@schaepers.it>
+ * 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_Preferences extends PHPUnit_Framework_TestCase {
+ public static function setUpBeforeClass() {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)');
+ $query->execute(array("Someuser", "someapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getusersapp", "somekey", "somevalue"));
+ $query->execute(array("Anotheruser", "getusersapp", "somekey", "someothervalue"));
+ $query->execute(array("Anuser", "getusersapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getappsapp", "somekey", "somevalue"));
+
+ $query->execute(array("Someuser", "getkeysapp", "firstkey", "somevalue"));
+ $query->execute(array("Someuser", "getkeysapp", "anotherkey", "somevalue"));
+ $query->execute(array("Someuser", "getkeysapp", "key-tastic", "somevalue"));
+
+ $query->execute(array("Someuser", "getvalueapp", "key", "a value for a key"));
+
+ $query->execute(array("Deleteuser", "deleteapp", "deletekey", "somevalue"));
+ $query->execute(array("Deleteuser", "deleteapp", "somekey", "somevalue"));
+ $query->execute(array("Deleteuser", "someapp", "somekey", "somevalue"));
+ }
+
+ public static function tearDownAfterClass() {
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $query->execute(array('Someuser'));
+ $query->execute(array('Anotheruser'));
+ $query->execute(array('Anuser'));
+ }
+
+ public function testGetUsers() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`');
+ $result = $query->execute();
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['userid'];
+ }
+
+ sort($expected);
+ $users = \OC_Preferences::getUsers();
+ sort($users);
+ $this->assertEquals($expected, $users);
+ }
+
+ public function testGetApps() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $result = $query->execute(array('Someuser'));
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['appid'];
+ }
+
+ sort($expected);
+ $apps = \OC_Preferences::getApps('Someuser');
+ sort($apps);
+ $this->assertEquals($expected, $apps);
+ }
+
+ public function testGetKeys() {
+ $query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
+ $result = $query->execute(array('Someuser', 'getkeysapp'));
+ $expected = array();
+ while ($row = $result->fetchRow()) {
+ $expected[] = $row['configkey'];
+ }
+
+ sort($expected);
+ $keys = \OC_Preferences::getKeys('Someuser', 'getkeysapp');
+ sort($keys);
+ $this->assertEquals($expected, $keys);
+ }
+
+ public function testGetValue() {
+ $this->assertNull(\OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant'));
+
+ $this->assertEquals('default', \OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant', 'default'));
+
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'getvalueapp', 'key'));
+ $row = $result->fetchRow();
+ $expected = $row['configvalue'];
+ $this->assertEquals($expected, \OC_Preferences::getValue('Someuser', 'getvalueapp', 'key'));
+ }
+
+ public function testSetValue() {
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('newvalue', $value);
+
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('othervalue', $value);
+ }
+
+ public function testSetValueWithPreCondition() {
+ // remove existing key
+ $this->assertTrue(\OC_Preferences::deleteKey('Someuser', 'setvalueapp', 'newkey'));
+
+ // add new preference with pre-condition should fails
+ $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue', 'preCondition'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $this->assertFalse($row);
+
+ // add new preference without pre-condition should insert the new value
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('newvalue', $value);
+
+ // wrong pre-condition, value should stay the same
+ $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'preCondition'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('newvalue', $value);
+
+ // correct pre-condition, value should change
+ $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'newvalue'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
+ $row = $result->fetchRow();
+ $value = $row['configvalue'];
+ $this->assertEquals('othervalue', $value);
+ }
+
+ public function testDeleteKey() {
+ $this->assertTrue(\OC_Preferences::deleteKey('Deleteuser', 'deleteapp', 'deletekey'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
+ $result = $query->execute(array('Deleteuser', 'deleteapp', 'deletekey'));
+ $this->assertEquals(0, count($result->fetchAll()));
+ }
+
+ public function testDeleteApp() {
+ $this->assertTrue(\OC_Preferences::deleteApp('Deleteuser', 'deleteapp'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
+ $result = $query->execute(array('Deleteuser', 'deleteapp'));
+ $this->assertEquals(0, count($result->fetchAll()));
+ }
+
+ public function testDeleteUser() {
+ $this->assertTrue(\OC_Preferences::deleteUser('Deleteuser'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?');
+ $result = $query->execute(array('Deleteuser'));
+ $this->assertEquals(0, count($result->fetchAll()));
+ }
+
+ public function testDeleteAppFromAllUsers() {
+ $this->assertTrue(\OC_Preferences::deleteAppFromAllUsers('someapp'));
+ $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `appid` = ?');
+ $result = $query->execute(array('someapp'));
+ $this->assertEquals(0, count($result->fetchAll()));
+ }
+}
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index d31b0257bad..fe8e3e8b48c 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -7,161 +7,6 @@
* See the COPYING-README file.
*/
-class Test_Preferences extends PHPUnit_Framework_TestCase {
- public static function setUpBeforeClass() {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)');
- $query->execute(array("Someuser", "someapp", "somekey", "somevalue"));
-
- $query->execute(array("Someuser", "getusersapp", "somekey", "somevalue"));
- $query->execute(array("Anotheruser", "getusersapp", "somekey", "someothervalue"));
- $query->execute(array("Anuser", "getusersapp", "somekey", "somevalue"));
-
- $query->execute(array("Someuser", "getappsapp", "somekey", "somevalue"));
-
- $query->execute(array("Someuser", "getkeysapp", "firstkey", "somevalue"));
- $query->execute(array("Someuser", "getkeysapp", "anotherkey", "somevalue"));
- $query->execute(array("Someuser", "getkeysapp", "key-tastic", "somevalue"));
-
- $query->execute(array("Someuser", "getvalueapp", "key", "a value for a key"));
-
- $query->execute(array("Deleteuser", "deleteapp", "deletekey", "somevalue"));
- $query->execute(array("Deleteuser", "deleteapp", "somekey", "somevalue"));
- $query->execute(array("Deleteuser", "someapp", "somekey", "somevalue"));
- }
-
- public static function tearDownAfterClass() {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?');
- $query->execute(array('Someuser'));
- $query->execute(array('Anotheruser'));
- $query->execute(array('Anuser'));
- }
-
- public function testGetUsers() {
- $query = \OC_DB::prepare('SELECT DISTINCT `userid` FROM `*PREFIX*preferences`');
- $result = $query->execute();
- $expected = array();
- while ($row = $result->fetchRow()) {
- $expected[] = $row['userid'];
- }
-
- $this->assertEquals($expected, \OC_Preferences::getUsers());
- }
-
- public function testGetApps() {
- $query = \OC_DB::prepare('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?');
- $result = $query->execute(array('Someuser'));
- $expected = array();
- while ($row = $result->fetchRow()) {
- $expected[] = $row['appid'];
- }
-
- $this->assertEquals($expected, \OC_Preferences::getApps('Someuser'));
- }
-
- public function testGetKeys() {
- $query = \OC_DB::prepare('SELECT DISTINCT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
- $result = $query->execute(array('Someuser', 'getkeysapp'));
- $expected = array();
- while ($row = $result->fetchRow()) {
- $expected[] = $row['configkey'];
- }
-
- $this->assertEquals($expected, \OC_Preferences::getKeys('Someuser', 'getkeysapp'));
- }
-
- public function testGetValue() {
- $this->assertNull(\OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant'));
-
- $this->assertEquals('default', \OC_Preferences::getValue('nonexistant', 'nonexistant', 'nonexistant', 'default'));
-
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'getvalueapp', 'key'));
- $row = $result->fetchRow();
- $expected = $row['configvalue'];
- $this->assertEquals($expected, \OC_Preferences::getValue('Someuser', 'getvalueapp', 'key'));
- }
-
- public function testSetValue() {
- $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $value = $row['configvalue'];
- $this->assertEquals('newvalue', $value);
-
- $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $value = $row['configvalue'];
- $this->assertEquals('othervalue', $value);
- }
-
- public function testSetValueWithPreCondition() {
- // remove existing key
- $this->assertTrue(\OC_Preferences::deleteKey('Someuser', 'setvalueapp', 'newkey'));
-
- // add new preference with pre-condition should fails
- $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue', 'preCondition'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $this->assertFalse($row);
-
- // add new preference without pre-condition should insert the new value
- $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'newvalue'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $value = $row['configvalue'];
- $this->assertEquals('newvalue', $value);
-
- // wrong pre-condition, value should stay the same
- $this->assertFalse(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'preCondition'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $value = $row['configvalue'];
- $this->assertEquals('newvalue', $value);
-
- // correct pre-condition, value should change
- $this->assertTrue(\OC_Preferences::setValue('Someuser', 'setvalueapp', 'newkey', 'othervalue', 'newvalue'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Someuser', 'setvalueapp', 'newkey'));
- $row = $result->fetchRow();
- $value = $row['configvalue'];
- $this->assertEquals('othervalue', $value);
- }
-
- public function testDeleteKey() {
- $this->assertTrue(\OC_Preferences::deleteKey('Deleteuser', 'deleteapp', 'deletekey'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?');
- $result = $query->execute(array('Deleteuser', 'deleteapp', 'deletekey'));
- $this->assertEquals(0, count($result->fetchAll()));
- }
-
- public function testDeleteApp() {
- $this->assertTrue(\OC_Preferences::deleteApp('Deleteuser', 'deleteapp'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?');
- $result = $query->execute(array('Deleteuser', 'deleteapp'));
- $this->assertEquals(0, count($result->fetchAll()));
- }
-
- public function testDeleteUser() {
- $this->assertTrue(\OC_Preferences::deleteUser('Deleteuser'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?');
- $result = $query->execute(array('Deleteuser'));
- $this->assertEquals(0, count($result->fetchAll()));
- }
-
- public function testDeleteAppFromAllUsers() {
- $this->assertTrue(\OC_Preferences::deleteAppFromAllUsers('someapp'));
- $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `appid` = ?');
- $result = $query->execute(array('someapp'));
- $this->assertEquals(0, count($result->fetchAll()));
- }
-}
-
class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
public function testGetUsers()
{
@@ -185,10 +30,69 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
$connectionMock->expects($this->exactly(2))
->method('fetchColumn')
- ->with($this->equalTo('SELECT COUNT(*) FROM `*PREFIX*preferences`'
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
+ .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'foo')))
+ ->will($this->onConsecutiveCalls(false, 'v1'));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->once())
+ ->method('executeUpdate')
+ ->with($this->equalTo("UPDATE `*PREFIX*preferences` SET `configvalue` = ?"
+ . " WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?"),
+ $this->equalTo(array('v2', 'grg', 'bar', 'foo'))
+ );
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v2');
+ }
+
+ public function testSetValueUnchanged() {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(3))
+ ->method('fetchColumn')
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
.' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
$this->equalTo(array('grg', 'bar', 'foo')))
- ->will($this->onConsecutiveCalls(0, 1));
+ ->will($this->onConsecutiveCalls(false, 'v1', 'v1'));
+ $connectionMock->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo('*PREFIX*preferences'),
+ $this->equalTo(
+ array(
+ 'userid' => 'grg',
+ 'appid' => 'bar',
+ 'configkey' => 'foo',
+ 'configvalue' => 'v1',
+ )
+ ));
+ $connectionMock->expects($this->never())
+ ->method('executeUpdate');
+
+ $preferences = new OC\Preferences($connectionMock);
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ $preferences->setValue('grg', 'bar', 'foo', 'v1');
+ }
+
+ public function testSetValueUnchanged2() {
+ $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
+ $connectionMock->expects($this->exactly(3))
+ ->method('fetchColumn')
+ ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences`'
+ .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'),
+ $this->equalTo(array('grg', 'bar', 'foo')))
+ ->will($this->onConsecutiveCalls(false, 'v1', 'v2'));
$connectionMock->expects($this->once())
->method('insert')
->with($this->equalTo('*PREFIX*preferences'),
@@ -210,6 +114,7 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
$preferences = new OC\Preferences($connectionMock);
$preferences->setValue('grg', 'bar', 'foo', 'v1');
$preferences->setValue('grg', 'bar', 'foo', 'v2');
+ $preferences->setValue('grg', 'bar', 'foo', 'v2');
}
public function testGetUserValues()
diff --git a/tests/lib/repair/repaircollation.php b/tests/lib/repair/repaircollation.php
new file mode 100644
index 00000000000..362feb8463f
--- /dev/null
+++ b/tests/lib/repair/repaircollation.php
@@ -0,0 +1,73 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class TestCollationRepair extends \OC\Repair\Collation {
+ /**
+ * @param \Doctrine\DBAL\Connection $connection
+ * @return string[]
+ */
+ public function getAllNonUTF8BinTables($connection) {
+ return parent::getAllNonUTF8BinTables($connection);
+ }
+}
+
+/**
+ * Tests for the converting of MySQL tables to InnoDB engine
+ *
+ * @see \OC\Repair\RepairMimeTypes
+ */
+class TestRepairCollation extends PHPUnit_Framework_TestCase {
+
+ /**
+ * @var TestCollationRepair
+ */
+ private $repair;
+
+ /**
+ * @var \Doctrine\DBAL\Connection
+ */
+ private $connection;
+
+ /**
+ * @var string
+ */
+ private $tableName;
+
+ /**
+ * @var \OCP\IConfig
+ */
+ private $config;
+
+ public function setUp() {
+ $this->connection = \OC_DB::getConnection();
+ $this->config = \OC::$server->getConfig();
+ if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
+ $this->markTestSkipped("Test only relevant on MySql");
+ }
+
+ $dbPrefix = $this->config->getSystemValue("dbtableprefix");
+ $this->tableName = uniqid($dbPrefix . "_collation_test");
+ $this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");
+
+ $this->repair = new TestCollationRepair($this->config, $this->connection);
+ }
+
+ public function tearDown() {
+ $this->connection->getSchemaManager()->dropTable($this->tableName);
+ }
+
+ public function testCollationConvert() {
+ $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
+ $this->assertGreaterThanOrEqual(1, count($tables));
+
+ $this->repair->run();
+
+ $tables = $this->repair->getAllNonUTF8BinTables($this->connection);
+ $this->assertCount(0, $tables);
+ }
+}
diff --git a/tests/lib/repair/repairinnodb.php b/tests/lib/repair/repairinnodb.php
new file mode 100644
index 00000000000..e7d2442f127
--- /dev/null
+++ b/tests/lib/repair/repairinnodb.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Tests for the converting of MySQL tables to InnoDB engine
+ *
+ * @see \OC\Repair\RepairMimeTypes
+ */
+class TestRepairInnoDB extends PHPUnit_Framework_TestCase {
+
+ /** @var \OC\RepairStep */
+ private $repair;
+
+ /** @var \Doctrine\DBAL\Connection */
+ private $connection;
+
+ /** @var string */
+ private $tableName;
+
+ public function setUp() {
+ $this->connection = \OC_DB::getConnection();
+ if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
+ $this->markTestSkipped("Test only relevant on MySql");
+ }
+
+ $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
+ $this->tableName = uniqid($dbPrefix . "_innodb_test");
+ $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM");
+
+ $this->repair = new \OC\Repair\InnoDB();
+ }
+
+ public function tearDown() {
+ $this->connection->getSchemaManager()->dropTable($this->tableName);
+ }
+
+ public function testInnoDBConvert() {
+ $result = $this->countMyIsamTables();
+ $this->assertEquals(1, $result);
+
+ $this->repair->run();
+
+ $result = $this->countMyIsamTables();
+ $this->assertEquals(0, $result);
+ }
+
+ /**
+ * @param $dbName
+ * @return mixed
+ */
+ private function countMyIsamTables() {
+ $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
+
+ $result = $this->connection->fetchColumn(
+ "SELECT count(*) FROM information_schema.tables WHERE table_schema = ? and table_name = ? AND engine = 'MyISAM'",
+ array($dbName, $this->tableName)
+ );
+ return $result;
+ }
+}
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 5920b44a8e0..bb827eece73 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -326,10 +326,14 @@ class Test_Share extends PHPUnit_Framework_TestCase {
$this->shareUserOneTestFileWithUserTwo();
$this->shareUserTestFileAsLink();
- $this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
- 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
- );
+ // manipulate share table and set expire date to the past
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?');
+ $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime');
+ $query->bindValue(2, 'test');
+ $query->bindValue(3, 'test.txt');
+ $query->bindValue(4, $this->user1);
+ $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);
+ $query->execute();
$shares = OCP\Share::getItemsShared('test');
$this->assertSame(1, count($shares));
@@ -337,6 +341,24 @@ class Test_Share extends PHPUnit_Framework_TestCase {
$this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']);
}
+ public function testSetExpireDateInPast() {
+ OC_User::setUserId($this->user1);
+ $this->shareUserOneTestFileWithUserTwo();
+ $this->shareUserTestFileAsLink();
+
+ $setExpireDateFailed = false;
+ try {
+ $this->assertTrue(
+ OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast, ''),
+ 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
+ );
+ } catch (\Exception $e) {
+ $setExpireDateFailed = true;
+ }
+
+ $this->assertTrue($setExpireDateFailed);
+ }
+
public function testShareWithUserExpirationValid() {
OC_User::setUserId($this->user1);
$this->shareUserOneTestFileWithUserTwo();
@@ -344,7 +366,7 @@ class Test_Share extends PHPUnit_Framework_TestCase {
$this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
+ OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''),
'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'
);
@@ -353,6 +375,39 @@ class Test_Share extends PHPUnit_Framework_TestCase {
}
+ /*
+ * if user is in a group excluded from resharing, then the share permission should
+ * be removed
+ */
+ public function testShareWithUserAndUserIsExcludedFromResharing() {
+
+ OC_User::setUserId($this->user1);
+ $this->assertTrue(
+ OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_USER, $this->user4, OCP\PERMISSION_ALL),
+ 'Failed asserting that user 1 successfully shared text.txt with user 4.'
+ );
+ $this->assertContains(
+ 'test.txt',
+ OCP\Share::getItemShared('test', 'test.txt', Test_Share_Backend::FORMAT_SOURCE),
+ 'Failed asserting that test.txt is a shared file of user 1.'
+ );
+
+ // exclude group2 from sharing
+ \OC_Appconfig::setValue('core', 'shareapi_exclude_groups_list', $this->group2);
+ \OC_Appconfig::setValue('core', 'shareapi_exclude_groups', "yes");
+
+ OC_User::setUserId($this->user4);
+
+ $share = OCP\Share::getItemSharedWith('test', 'test.txt');
+
+ $this->assertSame(\OCP\PERMISSION_ALL & ~OCP\PERMISSION_SHARE, $share['permissions'],
+ 'Failed asserting that user 4 is excluded from re-sharing');
+
+ \OC_Appconfig::deleteKey('core', 'shareapi_exclude_groups_list');
+ \OC_Appconfig::deleteKey('core', 'shareapi_exclude_groups');
+
+ }
+
protected function shareUserOneTestFileWithGroupOne() {
OC_User::setUserId($this->user1);
$this->assertTrue(
@@ -552,7 +607,7 @@ class Test_Share extends PHPUnit_Framework_TestCase {
// testGetShareByTokenExpirationValid
$this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture),
+ OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''),
'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'
);
$row = $this->getShareByValidToken($token);
@@ -561,17 +616,47 @@ class Test_Share extends PHPUnit_Framework_TestCase {
'Failed asserting that the returned row has an expiration date.'
);
- // testGetShareByTokenExpirationExpired
- $this->assertTrue(
- OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast),
- 'Failed asserting that user 1 successfully set a past expiration date for the test.txt share.'
- );
+ // manipulate share table and set expire date to the past
+ $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?');
+ $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime');
+ $query->bindValue(2, 'test');
+ $query->bindValue(3, 'test.txt');
+ $query->bindValue(4, $this->user1);
+ $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK);
+ $query->execute();
+
$this->assertFalse(
OCP\Share::getShareByToken($token),
'Failed asserting that an expired share could not be found.'
);
}
+ public function testShareItemWithLinkAndDefaultExpireDate() {
+ OC_User::setUserId($this->user1);
+
+ \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes');
+ \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2');
+
+ $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ);
+ $this->assertInternalType(
+ 'string',
+ $token,
+ 'Failed asserting that user 1 successfully shared text.txt as link with token.'
+ );
+
+ // share should have default expire date
+
+ $row = $this->getShareByValidToken($token);
+ $this->assertNotEmpty(
+ $row['expiration'],
+ 'Failed asserting that the returned row has an default expiration date.'
+ );
+
+ \OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date');
+ \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days');
+
+ }
+
public function testUnshareAll() {
$this->shareUserTestFileWithUser($this->user1, $this->user2);
$this->shareUserTestFileWithUser($this->user2, $this->user3);
diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php
index 1384c54a921..0d3914c7ca6 100644
--- a/tests/lib/user/backend.php
+++ b/tests/lib/user/backend.php
@@ -96,4 +96,21 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
$this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1'));
$this->assertFalse($this->backend->checkPassword($name2, 'newpass1'));
}
+
+ public function testSearch() {
+ $name1 = 'foobarbaz';
+ $name2 = 'bazbarfoo';
+ $name3 = 'notme';
+
+ $this->backend->createUser($name1, 'pass1');
+ $this->backend->createUser($name2, 'pass2');
+ $this->backend->createUser($name3, 'pass3');
+
+ $result = $this->backend->getUsers('bar');
+ $this->assertSame(2, count($result));
+
+ $result = $this->backend->getDisplayNames('bar');
+ $this->assertSame(2, count($result));
+ }
+
}
diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php
index d7cc39ae387..a8e497720c2 100644
--- a/tests/lib/user/database.php
+++ b/tests/lib/user/database.php
@@ -32,6 +32,9 @@ class Test_User_Database extends Test_User_Backend {
}
public function tearDown() {
+ if(!isset($this->users)) {
+ return;
+ }
foreach($this->users as $user) {
$this->backend->deleteUser($user);
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index aaa47f033de..c2bb99c3b2e 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -290,4 +290,72 @@ class Test_Util extends PHPUnit_Framework_TestCase {
array(array('g1', 'g2', 'g3'), array('g1', 'g2'), array('g1', 'g2', 'g3'), true),
);
}
+
+ /**
+ * Test default apps
+ *
+ * @dataProvider defaultAppsProvider
+ */
+ function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) {
+ $oldDefaultApps = \OCP\Config::getSystemValue('core', 'defaultapp', '');
+ // CLI is doing messy stuff with the webroot, so need to work it around
+ $oldWebRoot = \OC::$WEBROOT;
+ \OC::$WEBROOT = '';
+
+ Dummy_OC_App::setEnabledApps($enabledApps);
+ \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
+ $this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl());
+
+ // restore old state
+ \OC::$WEBROOT = $oldWebRoot;
+ Dummy_OC_App::restore();
+ \OCP\Config::setSystemValue('defaultapp', $oldDefaultApps);
+ }
+
+ function defaultAppsProvider() {
+ return array(
+ // none specified, default to files
+ array(
+ '',
+ 'index.php/apps/files/',
+ array('files'),
+ ),
+ // unexisting or inaccessible app specified, default to files
+ array(
+ 'unexist',
+ 'index.php/apps/files/',
+ array('files'),
+ ),
+ // non-standard app
+ array(
+ 'calendar',
+ 'index.php/apps/calendar/',
+ array('files', 'calendar'),
+ ),
+ // non-standard app with fallback
+ array(
+ 'contacts,calendar',
+ 'index.php/apps/calendar/',
+ array('files', 'calendar'),
+ ),
+ );
+ }
+
+}
+
+/**
+ * Dummy OC Apps class to make it possible to override
+ * enabled apps
+ */
+class Dummy_OC_App extends OC_App {
+ private static $enabledAppsCacheBackup;
+
+ public static function setEnabledApps($enabledApps) {
+ self::$enabledAppsCacheBackup = self::$enabledAppsCache;
+ self::$enabledAppsCache = $enabledApps;
+ }
+
+ public static function restore() {
+ self::$enabledAppsCache = self::$enabledAppsCacheBackup;
+ }
}
diff --git a/tests/testcleanuplistener.php b/tests/testcleanuplistener.php
index 7065f0337b9..7b442bbd4f7 100644
--- a/tests/testcleanuplistener.php
+++ b/tests/testcleanuplistener.php
@@ -41,20 +41,23 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
- if ($this->cleanStorages() && $this->isShowSuiteWarning()) {
- printf("TestSuite '%s': Did not clean up storages\n", $suite->getName());
- }
- if ($this->cleanFileCache() && $this->isShowSuiteWarning()) {
- printf("TestSuite '%s': Did not clean up file cache\n", $suite->getName());
- }
- if ($this->cleanStrayDataFiles() && $this->isShowSuiteWarning()) {
- printf("TestSuite '%s': Did not clean up data dir\n", $suite->getName());
- }
- if ($this->cleanStrayHooks() && $this->isShowSuiteWarning()) {
- printf("TestSuite '%s': Did not clean up hooks\n", $suite->getName());
- }
- if ($this->cleanProxies() && $this->isShowSuiteWarning()) {
- printf("TestSuite '%s': Did not clean up proxies\n", $suite->getName());
+ // don't clean up the test environment if a data provider finished
+ if (!($suite instanceof PHPUnit_Framework_TestSuite_DataProvider)) {
+ if ($this->cleanStorages() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up storages\n", $suite->getName());
+ }
+ if ($this->cleanFileCache() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up file cache\n", $suite->getName());
+ }
+ if ($this->cleanStrayDataFiles() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up data dir\n", $suite->getName());
+ }
+ if ($this->cleanStrayHooks() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up hooks\n", $suite->getName());
+ }
+ if ($this->cleanProxies() && $this->isShowSuiteWarning()) {
+ printf("TestSuite '%s': Did not clean up proxies\n", $suite->getName());
+ }
}
}
@@ -166,6 +169,8 @@ class TestCleanupListener implements PHPUnit_Framework_TestListener {
private function cleanProxies() {
$proxies = OC_FileProxy::getProxies();
OC_FileProxy::clearProxies();
+ // reenable in case some test failed to reenable them
+ OC_FileProxy::$enabled = true;
return count($proxies) > 0;
}
}