From c546874159d7880e3c8665eaaa7ae9a42b66adbb Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 2 Mar 2013 17:17:11 +0100 Subject: Convert OC_Appconfig to object interface Implemented unittest for OC\AppConfig --- tests/lib/appconfig.php | 181 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 4d82cd5ba7b..1b7a1c668e7 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -1,6 +1,7 @@ + * Copyright (c) 2013 Bart Visscher * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -130,3 +131,183 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $values); } } + +class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { + public function testGetApps() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(2)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('executeQuery') + ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`')) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $apps = $appconfig->getApps(); + $this->assertEquals(array('foo'), $apps); + } + + public function testGetKeys() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(2)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $keys = $appconfig->getKeys('bar'); + $this->assertEquals(array('foo'), $keys); + } + + public function testGetValue() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('fetchAssoc') + ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'), + $this->equalTo(array('bar', 'red'))) + ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null)); + + $appconfig = new OC\AppConfig($connectionMock); + $value = $appconfig->getValue('bar', 'red'); + $this->assertEquals('foo', $value); + $value = $appconfig->getValue('bar', 'red', 'def'); + $this->assertEquals('def', $value); + } + + public function testHasKey() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(3)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false, false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $this->assertTrue($appconfig->hasKey('bar', 'foo')); + $this->assertFalse($appconfig->hasKey('bar', 'foo')); + } + + public function testSetValue() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(4)) + ->method('fetchColumn') + ->will($this->onConsecutiveCalls('foo', false, 'foo', false)); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->exactly(2)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `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' => 'moo', + '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', 'moo', 'v1'); + $appconfig->setValue('bar', 'foo', 'v2'); + } + + public function testDeleteKey() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('delete') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'appid' => 'bar', + 'configkey' => 'foo', + ) + )); + + $appconfig = new OC\AppConfig($connectionMock); + $appconfig->deleteKey('bar', 'foo'); + } + + public function testDeleteApp() + { + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->once()) + ->method('delete') + ->with($this->equalTo('*PREFIX*appconfig'), + $this->equalTo( + array( + 'appid' => 'bar', + ) + )); + + $appconfig = new OC\AppConfig($connectionMock); + $appconfig->deleteApp('bar'); + } + + public function testGetValues() + { + $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); + $statementMock->expects($this->exactly(4)) + ->method('fetch') + ->with(\PDO::FETCH_ASSOC) + ->will($this->onConsecutiveCalls( + array('configvalue' =>'bar', 'configkey' => 'x'), + false, + array('configvalue' =>'foo', 'appid' => 'y'), + false + )); + $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); + $connectionMock->expects($this->at(0)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), + $this->equalTo(array('foo'))) + ->will($this->returnValue($statementMock)); + $connectionMock->expects($this->at(1)) + ->method('executeQuery') + ->with($this->equalTo('SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?'), + $this->equalTo(array('bar'))) + ->will($this->returnValue($statementMock)); + + $appconfig = new OC\AppConfig($connectionMock); + $values = $appconfig->getValues('foo', false); + //$this->assertEquals(array('x'=> 'bar'), $values); + $values = $appconfig->getValues(false, 'bar'); + //$this->assertEquals(array('y'=> 'foo'), $values); + $values = $appconfig->getValues(false, false); + //$this->assertEquals(false, $values); + $values = $appconfig->getValues('x', 'x'); + //$this->assertEquals(false, $values); + } +} -- cgit v1.2.3 From 6619d8273aa264d39c34a13ecafe720fc2356f90 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 25 Aug 2013 22:40:23 +0200 Subject: Enable appconfig asserts --- tests/lib/appconfig.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/lib') diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 1b7a1c668e7..1f605263560 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -302,12 +302,12 @@ class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { $appconfig = new OC\AppConfig($connectionMock); $values = $appconfig->getValues('foo', false); - //$this->assertEquals(array('x'=> 'bar'), $values); + $this->assertEquals(array('x'=> 'bar'), $values); $values = $appconfig->getValues(false, 'bar'); - //$this->assertEquals(array('y'=> 'foo'), $values); + $this->assertEquals(array('y'=> 'foo'), $values); $values = $appconfig->getValues(false, false); - //$this->assertEquals(false, $values); + $this->assertEquals(false, $values); $values = $appconfig->getValues('x', 'x'); - //$this->assertEquals(false, $values); + $this->assertEquals(false, $values); } } -- cgit v1.2.3 From 4cdf83e6d257c57ebad60e60dec474faa83a51d9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 7 Feb 2014 14:03:57 +0100 Subject: Remove the Test_AppConfig_Object tests as they no longer make sense with caching --- tests/lib/appconfig.php | 180 ------------------------------------------------ 1 file changed, 180 deletions(-) (limited to 'tests/lib') diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 29b29778fd2..5cbdf80502f 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -131,183 +131,3 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $values); } } - -class Test_AppConfig_Object extends PHPUnit_Framework_TestCase { - public function testGetApps() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`')) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $apps = $appconfig->getApps(); - $this->assertEquals(array('foo'), $apps); - } - - public function testGetKeys() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $keys = $appconfig->getKeys('bar'); - $this->assertEquals(array('foo'), $keys); - } - - public function testGetValue() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('fetchAssoc') - ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'), - $this->equalTo(array('bar', 'red'))) - ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null)); - - $appconfig = new OC\AppConfig($connectionMock); - $value = $appconfig->getValue('bar', 'red'); - $this->assertEquals('foo', $value); - $value = $appconfig->getValue('bar', 'red', 'def'); - $this->assertEquals('def', $value); - } - - public function testHasKey() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(3)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false, false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $this->assertTrue($appconfig->hasKey('bar', 'foo')); - $this->assertFalse($appconfig->hasKey('bar', 'foo')); - } - - public function testSetValue() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(4)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false, 'foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `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' => 'moo', - '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', 'moo', 'v1'); - $appconfig->setValue('bar', 'foo', 'v2'); - } - - public function testDeleteKey() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('delete') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'appid' => 'bar', - 'configkey' => 'foo', - ) - )); - - $appconfig = new OC\AppConfig($connectionMock); - $appconfig->deleteKey('bar', 'foo'); - } - - public function testDeleteApp() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('delete') - ->with($this->equalTo('*PREFIX*appconfig'), - $this->equalTo( - array( - 'appid' => 'bar', - ) - )); - - $appconfig = new OC\AppConfig($connectionMock); - $appconfig->deleteApp('bar'); - } - - public function testGetValues() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(4)) - ->method('fetch') - ->with(\PDO::FETCH_ASSOC) - ->will($this->onConsecutiveCalls( - array('configvalue' =>'bar', 'configkey' => 'x'), - false, - array('configvalue' =>'foo', 'appid' => 'y'), - false - )); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->at(0)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configvalue`, `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'), - $this->equalTo(array('foo'))) - ->will($this->returnValue($statementMock)); - $connectionMock->expects($this->at(1)) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configvalue`, `appid` FROM `*PREFIX*appconfig` WHERE `configkey` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $appconfig = new OC\AppConfig($connectionMock); - $values = $appconfig->getValues('foo', false); - $this->assertEquals(array('x'=> 'bar'), $values); - $values = $appconfig->getValues(false, 'bar'); - $this->assertEquals(array('y'=> 'foo'), $values); - $values = $appconfig->getValues(false, false); - $this->assertEquals(false, $values); - $values = $appconfig->getValues('x', 'x'); - $this->assertEquals(false, $values); - } -} -- cgit v1.2.3 From 9a39cd3b38837421a5ac476a78207402e4c6c91c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 15 Jan 2014 18:26:06 +0100 Subject: test for share dialoge sorter --- tests/lib/share/searchresultsorter.php | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/lib/share/searchresultsorter.php (limited to 'tests/lib') diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php new file mode 100644 index 00000000000..f24e40ea059 --- /dev/null +++ b/tests/lib/share/searchresultsorter.php @@ -0,0 +1,40 @@ + +* +* 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 . +*/ + +class Test_Share_Search extends \PHPUnit_Framework_TestCase { + public function testSort() { + $search = 'lin'; + $sorter = new \OC\Share\SearchResultSorter($search, 'foobar'); + + $result = array( + array('foobar' => 'woot'), + array('foobar' => 'linux'), + array('foobar' => 'Linus'), + array('foobar' => 'Bicyclerepairwoman'), + ); + + usort($result, array($sorter, 'sort')); + $this->assertTrue($result[0]['foobar'] === 'Linus'); + $this->assertTrue($result[1]['foobar'] === 'linux'); + $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman'); + $this->assertTrue($result[3]['foobar'] === 'woot'); + } +} -- cgit v1.2.3 From 32afdcbefec5793fb28162c456919d2b0be5cfe9 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 16 Jan 2014 11:00:22 +0100 Subject: Inject logger --- lib/private/share/searchresultsorter.php | 9 ++++++--- tests/lib/share/searchresultsorter.php | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'tests/lib') diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php index 4f8799494f5..f81a94c749d 100644 --- a/lib/private/share/searchresultsorter.php +++ b/lib/private/share/searchresultsorter.php @@ -12,16 +12,19 @@ class SearchResultSorter { private $search; private $encoding; private $key; + private $log; /** * @param $search the search term as was given by the user * @param $key the array key containing the value that should be compared * against * @param $encoding optional, encoding to use, defaults to UTF-8 + * @param $log optional, an \OC\Log instance */ - public function __construct($search, $key, $encoding = 'UTF-8') { + public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) { $this->encoding = $encoding; $this->key = $key; + $this->log = is_null($log) ? new \OC\Log() : $log; $this->search = mb_strtolower($search, $this->encoding); } @@ -32,8 +35,8 @@ class SearchResultSorter { */ public function sort($a, $b) { if(!isset($a[$this->key]) || !isset($b[$this->key])) { - \OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'. - 'array key', \OC_Log::ERROR); + $this->log->error('Sharing dialogue: cannot sort due to missing array key', + array('app' => 'core')); return 0; } $nameA = mb_strtolower($a[$this->key], $this->encoding); diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php index f24e40ea059..efc3e1b7aa3 100644 --- a/tests/lib/share/searchresultsorter.php +++ b/tests/lib/share/searchresultsorter.php @@ -37,4 +37,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase { $this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman'); $this->assertTrue($result[3]['foobar'] === 'woot'); } + + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testSortWrongLog() { + $sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar'); + } } -- cgit v1.2.3 From 72f134cfce05eb089a6d8271e73d6eb95cbe94a4 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 5 Feb 2014 17:12:17 +0100 Subject: intendation --- tests/lib/share/searchresultsorter.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/lib') diff --git a/tests/lib/share/searchresultsorter.php b/tests/lib/share/searchresultsorter.php index efc3e1b7aa3..eaf93400a7d 100644 --- a/tests/lib/share/searchresultsorter.php +++ b/tests/lib/share/searchresultsorter.php @@ -25,11 +25,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase { $sorter = new \OC\Share\SearchResultSorter($search, 'foobar'); $result = array( - array('foobar' => 'woot'), - array('foobar' => 'linux'), - array('foobar' => 'Linus'), - array('foobar' => 'Bicyclerepairwoman'), - ); + array('foobar' => 'woot'), + array('foobar' => 'linux'), + array('foobar' => 'Linus'), + array('foobar' => 'Bicyclerepairwoman'), + ); usort($result, array($sorter, 'sort')); $this->assertTrue($result[0]['foobar'] === 'Linus'); -- cgit v1.2.3 From a6399f9ceffcf9865b8a2be155dc4f98bd2ee5dc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 11 Feb 2014 14:00:24 +0100 Subject: Add the background job list to the public server container --- cron.php | 4 +- lib/private/backgroundjob/job.php | 4 +- lib/private/backgroundjob/joblist.php | 68 +++++++++++++++++------------ lib/private/server.php | 16 +++++++ lib/public/backgroundjob.php | 14 +++--- lib/public/backgroundjob/ijob.php | 29 +++++++++++++ lib/public/backgroundjob/ijoblist.php | 73 ++++++++++++++++++++++++++++++++ lib/public/iservercontainer.php | 7 +++ tests/lib/backgroundjob/dummyjoblist.php | 2 + 9 files changed, 179 insertions(+), 38 deletions(-) create mode 100644 lib/public/backgroundjob/ijob.php create mode 100644 lib/public/backgroundjob/ijoblist.php (limited to 'tests/lib') diff --git a/cron.php b/cron.php index 0d2c07b2d95..44ca421328b 100644 --- a/cron.php +++ b/cron.php @@ -97,7 +97,7 @@ try { touch(TemporaryCronClass::$lockfile); // Work - $jobList = new \OC\BackgroundJob\JobList(); + $jobList = \OC::$server->getJobList(); $jobs = $jobList->getAll(); foreach ($jobs as $job) { $job->execute($jobList, $logger); @@ -109,7 +109,7 @@ try { OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); } else { // Work and success :-) - $jobList = new \OC\BackgroundJob\JobList(); + $jobList = \OC::$server->getJobList(); $job = $jobList->getNext(); $job->execute($jobList, $logger); $jobList->setLastJob($job); diff --git a/lib/private/backgroundjob/job.php b/lib/private/backgroundjob/job.php index 92bd0f8fdbd..0cef401bc24 100644 --- a/lib/private/backgroundjob/job.php +++ b/lib/private/backgroundjob/job.php @@ -8,7 +8,9 @@ namespace OC\BackgroundJob; -abstract class Job { +use OCP\BackgroundJob\IJob; + +abstract class Job implements IJob { /** * @var int $id */ diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 99743a70c77..6b0df9e0d63 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -8,14 +8,26 @@ namespace OC\BackgroundJob; -/** - * Class QueuedJob - * - * create a background job that is to be executed once - * - * @package OC\BackgroundJob - */ class JobList { + /** + * @var \OCP\IDBConnection + */ + private $conn; + + /** + * @var \OCP\IConfig $config + */ + private $config; + + /** + * @param \OCP\IDBConnection $conn + * @param \OCP\IConfig $config + */ + public function __construct($conn, $config) { + $this->conn = $conn; + $this->config = $config; + } + /** * @param Job|string $job * @param mixed $argument @@ -28,7 +40,7 @@ class JobList { $class = $job; } $argument = json_encode($argument); - $query = \OC_DB::prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)'); + $query = $this->conn->prepare('INSERT INTO `*PREFIX*jobs`(`class`, `argument`, `last_run`) VALUES(?, ?, 0)'); $query->execute(array($class, $argument)); } } @@ -45,10 +57,10 @@ class JobList { } if (!is_null($argument)) { $argument = json_encode($argument); - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); + $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); $query->execute(array($class, $argument)); } else { - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?'); + $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `class` = ?'); $query->execute(array($class)); } } @@ -67,9 +79,9 @@ class JobList { $class = $job; } $argument = json_encode($argument); - $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); - $result = $query->execute(array($class, $argument)); - return (bool)$result->fetchRow(); + $query = $this->conn->prepare('SELECT `id` FROM `*PREFIX*jobs` WHERE `class` = ? AND `argument` = ?'); + $query->execute(array($class, $argument)); + return (bool)$query->fetch(); } /** @@ -78,10 +90,10 @@ class JobList { * @return Job[] */ public function getAll() { - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`'); - $result = $query->execute(); + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs`'); + $query->execute(); $jobs = array(); - while ($row = $result->fetchRow()) { + while ($row = $query->fetch()) { $jobs[] = $this->buildJob($row); } return $jobs; @@ -94,15 +106,15 @@ class JobList { */ public function getNext() { $lastId = $this->getLastJob(); - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1); - $result = $query->execute(array($lastId)); - if ($row = $result->fetchRow()) { + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1); + $query->execute(array($lastId)); + if ($row = $query->fetch()) { return $this->buildJob($row); } else { //begin at the start of the queue - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1); - $result = $query->execute(); - if ($row = $result->fetchRow()) { + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1); + $query->execute(); + if ($row = $query->fetch()) { return $this->buildJob($row); } else { return null; //empty job list @@ -115,9 +127,9 @@ class JobList { * @return Job */ public function getById($id) { - $query = \OC_DB::prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?'); - $result = $query->execute(array($id)); - if ($row = $result->fetchRow()) { + $query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?'); + $query->execute(array($id)); + if ($row = $query->fetch()) { return $this->buildJob($row); } else { return null; @@ -148,7 +160,7 @@ class JobList { * @param Job $job */ public function setLastJob($job) { - \OC_Appconfig::setValue('backgroundjob', 'lastjob', $job->getId()); + $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId()); } /** @@ -157,7 +169,7 @@ class JobList { * @return int */ public function getLastJob() { - return \OC_Appconfig::getValue('backgroundjob', 'lastjob', 0); + $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** @@ -166,7 +178,7 @@ class JobList { * @param Job $job */ public function setLastRun($job) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?'); + $query = $this->conn->prepare('UPDATE `*PREFIX*jobs` SET `last_run` = ? WHERE `id` = ?'); $query->execute(array(time(), $job->getId())); } } diff --git a/lib/private/server.php b/lib/private/server.php index c9e593ec2ed..b5ffd08ce79 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -148,6 +148,13 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('AvatarManager', function($c) { return new AvatarManager(); }); + $this->registerService('JobList', function ($c) { + /** + * @var Server $c + */ + $config = $c->getConfig(); + return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); + }); } /** @@ -336,4 +343,13 @@ class Server extends SimpleContainer implements IServerContainer { function getActivityManager() { return $this->query('ActivityManager'); } + + /** + * Returns an job list for controlling background jobs + * + * @return \OCP\BackgroundJob\IJobList + */ + function getJobList(){ + return $this->query('JobList'); + } } diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index a7f54491dfa..bcaf6e35454 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -33,7 +33,7 @@ use \OC\BackgroundJob\JobList; /** * This class provides functions to register backgroundjobs in ownCloud * - * To create a new backgroundjob create a new class that inharits from either \OC\BackgroundJob\Job, + * To create a new backgroundjob create a new class that inherits from either \OC\BackgroundJob\Job, * \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using * \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function * of the job when the job is executed. @@ -73,7 +73,7 @@ class BackgroundJob { * @param mixed $argument */ public static function registerJob($job, $argument = null) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $jobList->add($job, $argument); } @@ -99,7 +99,7 @@ class BackgroundJob { * key is string "$klass-$method", value is array( $klass, $method ) */ static public function allRegularTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $regularJobs = array(); foreach ($allJobs as $job) { @@ -118,7 +118,7 @@ class BackgroundJob { * @return associative array */ public static function findQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); return $jobList->getById($id); } @@ -128,7 +128,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function allQueuedTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -148,7 +148,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function queuedTaskWhereAppIs($app) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -186,7 +186,7 @@ class BackgroundJob { * Deletes a report */ public static function deleteQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $job = $jobList->getById($id); if ($job) { $jobList->remove($job); diff --git a/lib/public/backgroundjob/ijob.php b/lib/public/backgroundjob/ijob.php new file mode 100644 index 00000000000..c427b50401d --- /dev/null +++ b/lib/public/backgroundjob/ijob.php @@ -0,0 +1,29 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJob { + /** + * @param \OCP\BackgroundJob\IJobList $jobList + * @param \OC\Log $logger + */ + public function execute($jobList, $logger = null); + + public function setId($id); + + public function setLastRun($lastRun); + + public function setArgument($argument); + + public function getId(); + + public function getLastRun(); + + public function getArgument(); +} diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php new file mode 100644 index 00000000000..7e80d51755b --- /dev/null +++ b/lib/public/backgroundjob/ijoblist.php @@ -0,0 +1,73 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJobList { + /** + * @param \OCP\BackgroundJob\IJob |string $job + * @param mixed $argument + */ + public function add($job, $argument = null); + + /** + * @param \OCP\BackgroundJob\IJob|string $job + * @param mixed $argument + */ + public function remove($job, $argument = null); + + /** + * check if a job is in the list + * + * @param $job + * @param mixed $argument + * @return bool + */ + public function has($job, $argument); + + /** + * get all jobs in the list + * + * @return \OCP\BackgroundJob\IJob[] + */ + public function getAll(); + + /** + * get the next job in the list + * + * @return \OCP\BackgroundJob\IJob + */ + public function getNext(); + + /** + * @param int $id + * @return \OCP\BackgroundJob\IJob + */ + public function getById($id); + + /** + * set the job that was last ran + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastJob($job); + + /** + * get the id of the last ran job + * + * @return int + */ + public function getLastJob(); + + /** + * set the lastRun of $job to now + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastRun($job); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 5473f3ee334..0658bd0b022 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -176,4 +176,11 @@ interface IServerContainer { */ function getAvatarManager(); + /** + * Returns an job list for controlling background jobs + * + * @return \OCP\BackgroundJob\IJobList + */ + function getJobList(); + } diff --git a/tests/lib/backgroundjob/dummyjoblist.php b/tests/lib/backgroundjob/dummyjoblist.php index e1579c273bb..7801269b27e 100644 --- a/tests/lib/backgroundjob/dummyjoblist.php +++ b/tests/lib/backgroundjob/dummyjoblist.php @@ -21,6 +21,8 @@ class DummyJobList extends \OC\BackgroundJob\JobList { private $last = 0; + public function __construct(){} + /** * @param \OC\BackgroundJob\Job|string $job * @param mixed $argument -- cgit v1.2.3 From d6576c640c429d24a6329573c0dfaf99d82ac867 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 12 Feb 2014 13:52:13 +0100 Subject: Add unit tests for JobList --- lib/private/backgroundjob/joblist.php | 2 +- tests/lib/backgroundjob/job.php | 25 ----- tests/lib/backgroundjob/joblist.php | 203 ++++++++++++++++++++++++++++++++++ tests/lib/backgroundjob/testjob.php | 34 ++++++ 4 files changed, 238 insertions(+), 26 deletions(-) create mode 100644 tests/lib/backgroundjob/joblist.php create mode 100644 tests/lib/backgroundjob/testjob.php (limited to 'tests/lib') diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 5ec81dc3fc6..586e99a3cbc 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -171,7 +171,7 @@ class JobList implements IJobList { * @return int */ public function getLastJob() { - $this->config->getAppValue('backgroundjob', 'lastjob', 0); + return $this->config->getAppValue('backgroundjob', 'lastjob', 0); } /** diff --git a/tests/lib/backgroundjob/job.php b/tests/lib/backgroundjob/job.php index 7d66fa772d2..10a8f46462e 100644 --- a/tests/lib/backgroundjob/job.php +++ b/tests/lib/backgroundjob/job.php @@ -8,31 +8,6 @@ namespace Test\BackgroundJob; - -class TestJob extends \OC\BackgroundJob\Job { - private $testCase; - - /** - * @var callable $callback - */ - private $callback; - - /** - * @param Job $testCase - * @param callable $callback - */ - public function __construct($testCase, $callback) { - $this->testCase = $testCase; - $this->callback = $callback; - } - - public function run($argument) { - $this->testCase->markRun(); - $callback = $this->callback; - $callback($argument); - } -} - class Job extends \PHPUnit_Framework_TestCase { private $run = false; diff --git a/tests/lib/backgroundjob/joblist.php b/tests/lib/backgroundjob/joblist.php new file mode 100644 index 00000000000..c3318f80cb2 --- /dev/null +++ b/tests/lib/backgroundjob/joblist.php @@ -0,0 +1,203 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + +class JobList extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\BackgroundJob\JobList + */ + protected $instance; + + /** + * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject $config + */ + protected $config; + + public function setUp() { + $conn = \OC::$server->getDatabaseConnection(); + $this->config = $this->getMock('\OCP\IConfig'); + $this->instance = new \OC\BackgroundJob\JobList($conn, $this->config); + } + + public function argumentProvider() { + return array( + array(null), + array(false), + array('foobar'), + array(12), + array(array( + 'asd' => 5, + 'foo' => 'bar' + )) + ); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testAddRemove($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $this->assertCount(count($existingJobs) + 1, $jobs); + $addedJob = $jobs[count($jobs) - 1]; + $this->assertInstanceOf('\Test\BackgroundJob\TestJob', $addedJob); + $this->assertEquals($argument, $addedJob->getArgument()); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testRemoveDifferentArgument($argument) { + $existingJobs = $this->instance->getAll(); + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + $this->instance->remove($job, 10); + $jobs2 = $this->instance->getAll(); + + $this->assertEquals($jobs, $jobs2); + + $this->instance->remove($job, $argument); + + $jobs = $this->instance->getAll(); + $this->assertEquals($existingJobs, $jobs); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHas($argument) { + $job = new TestJob(); + $this->assertFalse($this->instance->has($job, $argument)); + $this->instance->add($job, $argument); + + $this->assertTrue($this->instance->has($job, $argument)); + + $this->instance->remove($job, $argument); + + $this->assertFalse($this->instance->has($job, $argument)); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testHasDifferentArgument($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $this->assertFalse($this->instance->has($job, 10)); + + $this->instance->remove($job, $argument); + } + + public function testGetLastJob() { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue(15)); + + $this->assertEquals(15, $this->instance->getLastJob()); + } + + public function testGetNext() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob1 = $jobs[count($jobs) - 2]; + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob1->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($savedJob2, $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + public function testGetNextWrapAround() { + $job = new TestJob(); + $this->instance->add($job, 1); + $this->instance->add($job, 2); + + $jobs = $this->instance->getAll(); + + $savedJob2 = $jobs[count($jobs) - 1]; + + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('backgroundjob', 'lastjob', 0) + ->will($this->returnValue($savedJob2->getId())); + + $nextJob = $this->instance->getNext(); + + $this->assertEquals($jobs[0], $nextJob); + + $this->instance->remove($job, 1); + $this->instance->remove($job, 2); + } + + /** + * @dataProvider argumentProvider + * @param $argument + */ + public function testGetById($argument) { + $job = new TestJob(); + $this->instance->add($job, $argument); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $this->assertEquals($addedJob, $this->instance->getById($addedJob->getId())); + + $this->instance->remove($job, $argument); + } + + public function testSetLastRun() { + $job = new TestJob(); + $this->instance->add($job); + + $jobs = $this->instance->getAll(); + + $addedJob = $jobs[count($jobs) - 1]; + + $timeStart = time(); + $this->instance->setLastRun($addedJob); + $timeEnd = time(); + + $addedJob = $this->instance->getById($addedJob->getId()); + + $this->assertGreaterThanOrEqual($timeStart, $addedJob->getLastRun()); + $this->assertLessThanOrEqual($timeEnd, $addedJob->getLastRun()); + + $this->instance->remove($job); + } +} diff --git a/tests/lib/backgroundjob/testjob.php b/tests/lib/backgroundjob/testjob.php new file mode 100644 index 00000000000..23fc4268d1a --- /dev/null +++ b/tests/lib/backgroundjob/testjob.php @@ -0,0 +1,34 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\BackgroundJob; + + +class TestJob extends \OC\BackgroundJob\Job { + private $testCase; + + /** + * @var callable $callback + */ + private $callback; + + /** + * @param Job $testCase + * @param callable $callback + */ + public function __construct($testCase = null, $callback = null) { + $this->testCase = $testCase; + $this->callback = $callback; + } + + public function run($argument) { + $this->testCase->markRun(); + $callback = $this->callback; + $callback($argument); + } +} -- cgit v1.2.3 From 3b1df2931818b90b734c8bc3a6e0dbdf1517feaf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 13 Feb 2014 13:56:02 +0100 Subject: sort expected result in tests --- tests/lib/appconfig.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/lib') diff --git a/tests/lib/appconfig.php b/tests/lib/appconfig.php index 5cbdf80502f..6ae790a9edd 100644 --- a/tests/lib/appconfig.php +++ b/tests/lib/appconfig.php @@ -42,6 +42,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while ($row = $result->fetchRow()) { $expected[] = $row['appid']; } + sort($expected); $apps = \OC_Appconfig::getApps(); $this->assertEquals($expected, $apps); } @@ -53,6 +54,7 @@ class Test_Appconfig extends PHPUnit_Framework_TestCase { while($row = $result->fetchRow()) { $expected[] = $row["configkey"]; } + sort($expected); $keys = \OC_Appconfig::getKeys('testapp'); $this->assertEquals($expected, $keys); } -- cgit v1.2.3 From b35f679483f2b8f1dab56b903ca2e942ac4606ff Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 14 Feb 2014 15:07:08 +0100 Subject: Fix test cases for group manager --- lib/private/group/manager.php | 4 ++-- tests/lib/group/manager.php | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'tests/lib') diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 29453c5da14..9b433b64fd4 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -108,8 +108,8 @@ class Manager extends PublicEmitter { public function createGroup($gid) { if (!$gid) { return false; - } else if ($this->groupExists($gid)) { - return $this->get($gid); + } else if ($group = $this->get($gid)) { + return $group; } else { $this->emit('\OC\Group', 'preCreate', array($gid)); foreach ($this->backends as $backend) { diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index 9d3adf51a0c..90f0e1b35e2 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -116,16 +116,22 @@ class Manager extends \PHPUnit_Framework_TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend */ + $backendGroupCreated = false; $backend = $this->getMock('\OC_Group_Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') - ->will($this->returnValue(false)); + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + return $backendGroupCreated; + })); $backend->expects($this->once()) ->method('implementsActions') ->will($this->returnValue(true)); $backend->expects($this->once()) - ->method('createGroup'); + ->method('createGroup') + ->will($this->returnCallback(function () use (&$backendGroupCreated) { + $backendGroupCreated = true; + }));; /** * @var \OC\User\Manager $userManager @@ -170,6 +176,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->once()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -193,6 +203,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -202,6 +215,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1') ->will($this->returnValue(array('group12', 'group1'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -228,6 +244,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 2, 1) ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 @@ -237,6 +256,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getGroups') ->with('1', 1, 0) ->will($this->returnValue(array('group12'))); + $backend2->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -263,6 +285,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend->expects($this->any()) + ->method('groupExists') + ->with('group1') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager @@ -286,6 +312,10 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 */ @@ -294,6 +324,9 @@ class Manager extends \PHPUnit_Framework_TestCase { ->method('getUserGroups') ->with('user1') ->will($this->returnValue(array('group1', 'group2'))); + $backend1->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); /** * @var \OC\User\Manager $userManager -- cgit v1.2.3