diff options
author | Julius Haertl <jus@bitgrid.net> | 2016-09-04 20:22:53 +0300 |
---|---|---|
committer | Julius Haertl <jus@bitgrid.net> | 2016-09-04 20:22:53 +0300 |
commit | 7af779c6722b75fb51669e8dae288c0d8d6fe60e (patch) | |
tree | 3816dc4dbac7e9cb4d5690a8e5b3387ae2f4a9ff /tests | |
parent | 3a22289a6271d7f5a784555f885c439990a4777e (diff) |
Code cleanup, copyright, documentation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 4 | ||||
-rw-r--r-- | tests/unit/UtilTest.php | 126 | ||||
-rw-r--r-- | tests/unit/controller/AppControllerTest.php | 44 | ||||
-rw-r--r-- | tests/unit/controller/SettingsControllerTest.php | 230 | ||||
-rw-r--r-- | tests/unit/service/ConfigServiceTest.php | 86 |
5 files changed, 270 insertions, 220 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ad27814..d90b738 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -25,8 +25,8 @@ require_once __DIR__ . '/../../../tests/bootstrap.php'; require_once __DIR__ . '/../appinfo/autoload.php'; -require_once __DIR__.'/../../../lib/base.php'; -if(!class_exists('PHPUnit_Framework_TestCase')) { +require_once __DIR__ . '/../../../lib/base.php'; +if (!class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); } diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php index 123386b..825d7af 100644 --- a/tests/unit/UtilTest.php +++ b/tests/unit/UtilTest.php @@ -24,76 +24,78 @@ namespace OCA\AppOrder; use OCA\AppOrder\Service\ConfigService; -use \OCA\AppOrder\Util; +use OCP\IConfig; class UtilTest extends \PHPUnit_Framework_TestCase { - /** - * @var ConfigService - */ - private $service; - private $userId; - private $util; - private $config; - public function setUp() { + /** @var ConfigService */ + private $service; + /** @var string */ + private $userId; + /** @var Util */ + private $util; + /** @var IConfig */ + private $config; - parent::setUp(); + public function setUp() { - $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') - ->disableOriginalConstructor() - ->getMock(); - $this->userId = 'admin'; - $this->util = new Util($this->service, $this->userId); + parent::setUp(); - } + $this->config = $this->getMockBuilder('OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') + ->disableOriginalConstructor() + ->getMock(); + $this->userId = 'admin'; + $this->util = new Util($this->service, $this->userId); - public function testMatchOrder() { - $nav = [ - ['href' => '/app/files/', 'name' => 'Files'], - ['href' => '/app/calendar/', 'name' => 'Calendar'], - ['href' => '/app/tasks/', 'name' => 'Tasks'], - ]; - $order = ['/app/calendar/', '/app/tasks/']; - $result = $this->util->matchOrder($nav, $order); - $expected = [ - '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], - '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], - '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], - ]; - $this->assertEquals($expected, $result); - } + } - public function testGetAppOrder() { - $nav_system = ['/app/calendar/', '/app/tasks/']; - $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; - $this->service->expects($this->once()) - ->method('getAppValue') - ->with('order') - ->will($this->returnValue(json_encode($nav_system))); - $this->service->expects($this->once()) - ->method('getUserValue') - ->with('order', $this->userId) - ->will($this->returnValue(json_encode($nav_user))); - $result = $this->util->getAppOrder(); - $this->assertEquals(json_encode($nav_user), $result); - } + public function testMatchOrder() { + $nav = [ + ['href' => '/app/files/', 'name' => 'Files'], + ['href' => '/app/calendar/', 'name' => 'Calendar'], + ['href' => '/app/tasks/', 'name' => 'Tasks'], + ]; + $order = ['/app/calendar/', '/app/tasks/']; + $result = $this->util->matchOrder($nav, $order); + $expected = [ + '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], + '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], + '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], + ]; + $this->assertEquals($expected, $result); + } - public function testGetAppOrderNoUser() { - $nav_system = ['/app/calendar/', '/app/tasks/']; - $nav_user = ''; - $this->service->expects($this->once()) - ->method('getAppValue') - ->with('order') - ->will($this->returnValue(json_encode($nav_system))); - $this->service->expects($this->once()) - ->method('getUserValue') - ->with('order', $this->userId) - ->will($this->returnValue($nav_user)); - $result = $this->util->getAppOrder(); - $this->assertEquals(json_encode($nav_system), $result); - } + public function testGetAppOrder() { + $nav_system = ['/app/calendar/', '/app/tasks/']; + $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; + $this->service->expects($this->once()) + ->method('getAppValue') + ->with('order') + ->will($this->returnValue(json_encode($nav_system))); + $this->service->expects($this->once()) + ->method('getUserValue') + ->with('order', $this->userId) + ->will($this->returnValue(json_encode($nav_user))); + $result = $this->util->getAppOrder(); + $this->assertEquals(json_encode($nav_user), $result); + } + + public function testGetAppOrderNoUser() { + $nav_system = ['/app/calendar/', '/app/tasks/']; + $nav_user = ''; + $this->service->expects($this->once()) + ->method('getAppValue') + ->with('order') + ->will($this->returnValue(json_encode($nav_system))); + $this->service->expects($this->once()) + ->method('getUserValue') + ->with('order', $this->userId) + ->will($this->returnValue($nav_user)); + $result = $this->util->getAppOrder(); + $this->assertEquals(json_encode($nav_system), $result); + } } diff --git a/tests/unit/controller/AppControllerTest.php b/tests/unit/controller/AppControllerTest.php index e2281d7..74864d5 100644 --- a/tests/unit/controller/AppControllerTest.php +++ b/tests/unit/controller/AppControllerTest.php @@ -23,62 +23,57 @@ namespace OCA\AppOrder\Tests\Unit\Controller; -use OCP\IRequest; -use OCP\AppFramework\Http\DataResponse; +use OCA\AppOrder\Util; use OCP\AppFramework\Http; -use \OCA\AppOrder\Service; -use \OCA\AppOrder\AppInfo\Application; -use \OCA\AppOrder\Controller; use OCA\AppOrder\Controller\AppController; +use OCP\IConfig; +use OCP\IRequest; +use OCP\IURLGenerator; -class AppControllerTest extends \Test\TestCase { +class AppControllerTest extends \PHPUnit_Framework_TestCase { - private $container; + /** @var IRequest */ private $request; - private $service; + /** @var IURLGenerator */ private $urlGenerator; + /** @var string */ private $userId; + /** @var string */ private $appName; - /** - * @var AppController - */ + /** @var AppController */ private $controller; + /** @var IConfig */ private $config; + /** @var Util */ private $util; public function setUp() { - parent::setUp(); - - $app = new \OCA\AppOrder\AppInfo\Application(); - $this->container = $app->getContainer(); $this->request = $this->getMockBuilder('OCP\IRequest') ->disableOriginalConstructor() ->getMock(); $this->config = $this->getMockBuilder('OCP\IConfig') ->disableOriginalConstructor() ->getMock(); - $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') + $this->util = $this->getMockBuilder('\OCA\AppOrder\Util') ->disableOriginalConstructor() ->getMock(); $this->urlGenerator = \OC::$server->getURLGenerator(); - $this->util = $this->getMockBuilder('\OCA\AppOrder\Util')->disableOriginalConstructor()->getMock(); - $this->userId = 'admin'; $this->appName = 'apporder'; $this->controller = new AppController( - $this->appName, $this->request, $this->service, $this->urlGenerator, $this->util, + $this->appName, + $this->request, + $this->urlGenerator, + $this->util, $this->userId ); - } public function testIndex() { - $this->util->expects($this->once()) + $this->util->expects($this->once()) ->method('getAppOrder') - ->willReturn( - json_encode(['/index.php/foo/bar', '/index.php/bar/foo']) - ); + ->willReturn(json_encode(['/index.php/foo/bar', '/index.php/bar/foo'])); $expected = new Http\RedirectResponse('/index.php/foo/bar'); $result = $this->controller->index(); $this->assertEquals($expected, $result); @@ -89,7 +84,6 @@ class AppControllerTest extends \Test\TestCase { ->method('getAppOrder') ->willReturn(""); $result = $this->controller->index(); - $expected = new Http\RedirectResponse('http://localhost/index.php/apps/files/'); $this->assertEquals($expected, $result); } diff --git a/tests/unit/controller/SettingsControllerTest.php b/tests/unit/controller/SettingsControllerTest.php index 65ba926..cb3879c 100644 --- a/tests/unit/controller/SettingsControllerTest.php +++ b/tests/unit/controller/SettingsControllerTest.php @@ -1,117 +1,149 @@ <?php +/** + * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ namespace OCA\AppOrder\Tests\Unit\Controller; +use OCA\AppOrder\Controller\SettingsController; +use OCA\AppOrder\Service\ConfigService; +use OCA\AppOrder\Util; +use OCP\IConfig; +use OCP\INavigationManager; use OCP\IRequest; -use OCP\AppFramework\Http\DataResponse; -use OCP\AppFramework\Http; -use \OCA\AppOrder\Service; -use \OCA\AppOrder\AppInfo\Application; -use \OCA\AppOrder\Controller; -class SettingsControllerTest extends \Test\TestCase { +class SettingsControllerTest extends \PHPUnit_Framework_TestCase { - private $container; - private $request; - private $service; - private $navigationManager; - private $userId; - private $appName; - private $controller; - private $config; - public function setUp() { + /** @var IRequest */ + private $request; + /** @var ConfigService */ + private $service; + /** @var INavigationManager */ + private $navigationManager; + /** @var string */ + private $userId; + /** @var string */ + private $appName; + /** @var SettingsController */ + private $controller; + /** @var IConfig */ + private $config; + /** @var Util */ + private $util; - parent::setUp(); + public function setUp() { - $app = new \OCA\AppOrder\AppInfo\Application(); - $this->container = $app->getContainer(); - $this->request = $this->getMockBuilder('OCP\IRequest') - ->disableOriginalConstructor() - ->getMock(); - $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') - ->disableOriginalConstructor() - ->getMock(); - $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll', 'add', 'setActiveEntry']) - ->disableOriginalConstructor() - ->getMock(); + parent::setUp(); + $this->request = $this->getMockBuilder('OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); + $this->config = $this->getMockBuilder('OCP\IConfig') + ->disableOriginalConstructor() + ->getMock(); + $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') + ->disableOriginalConstructor() + ->getMock(); + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager') + ->setMethods(['getAll', 'add', 'setActiveEntry']) + ->disableOriginalConstructor() + ->getMock(); - $this->userId = 'admin'; - $this->appName = 'apporder'; - $this->util = new \OCA\AppOrder\Util($this->service, $this->userId); - $this->controller = new \OCA\AppOrder\Controller\SettingsController( - $this->appName, $this->request, $this->service, $this->navigationManager, $this->util, - $this->userId - ); + $this->userId = 'admin'; + $this->appName = 'apporder'; + $this->util = new Util($this->service, $this->userId); + $this->controller = new SettingsController( + $this->appName, + $this->request, + $this->service, + $this->navigationManager, + $this->util, + $this->userId + ); - } + } - public function testAdminIndex() { - $nav_custom = ['/app/calendar/', '/app/tasks/']; - $nav_oc = [ - ['href' => '/app/files/', 'name' => 'Files'], - ['href' => '/app/calendar/', 'name' => 'Calendar'], - ['href' => '/app/tasks/', 'name' => 'Tasks'], - ]; - $nav_final = [ - '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] - ]; - $this->service->expects($this->once()) - ->method('getAppValue') - ->with('order') - ->will($this->returnValue(json_encode($nav_custom))); - $this->navigationManager->expects($this->once()) - ->method('getAll') - ->will($this->returnValue($nav_oc)); + public function testAdminIndex() { + $nav_custom = ['/app/calendar/', '/app/tasks/']; + $nav_oc = [ + ['href' => '/app/files/', 'name' => 'Files'], + ['href' => '/app/calendar/', 'name' => 'Calendar'], + ['href' => '/app/tasks/', 'name' => 'Tasks'], + ]; + $nav_final = [ + '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] + ]; + $this->service->expects($this->once()) + ->method('getAppValue') + ->with('order') + ->will($this->returnValue(json_encode($nav_custom))); + $this->navigationManager->expects($this->once()) + ->method('getAll') + ->will($this->returnValue($nav_oc)); - $result = $this->controller->adminIndex(); - $expected = new \OCP\AppFramework\Http\TemplateResponse( - $this->appName, - 'admin', - ["nav" => $nav_final], - 'blank' - ); - $this->assertEquals($expected, $result); - } + $result = $this->controller->adminIndex(); + $expected = new \OCP\AppFramework\Http\TemplateResponse( + $this->appName, + 'admin', + ["nav" => $nav_final], + 'blank' + ); + $this->assertEquals($expected, $result); + } - public function testGetOrder() { - $nav_system = ['/app/calendar/', '/app/tasks/']; - $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; - $this->service->expects($this->once()) - ->method('getAppValue') - ->with('order') - ->will($this->returnValue(json_encode($nav_system))); - $this->service->expects($this->once()) - ->method('getUserValue') - ->with('order', $this->userId) - ->will($this->returnValue(json_encode($nav_user))); - $order = ['/app/files/', '/app/calendar/', '/app/tasks/']; - $result = $this->controller->getOrder(); - $expected = array('status' => 'success', 'order' => json_encode($order)); - $this->assertEquals($expected, $result); - } + public function testGetOrder() { + $nav_system = ['/app/calendar/', '/app/tasks/']; + $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; + $this->service->expects($this->once()) + ->method('getAppValue') + ->with('order') + ->will($this->returnValue(json_encode($nav_system))); + $this->service->expects($this->once()) + ->method('getUserValue') + ->with('order', $this->userId) + ->will($this->returnValue(json_encode($nav_user))); + $order = ['/app/files/', '/app/calendar/', '/app/tasks/']; + $result = $this->controller->getOrder(); + $expected = array('status' => 'success', 'order' => json_encode($order)); + $this->assertEquals($expected, $result); + } - public function testSavePersonal() { - $order = "RANDOMORDER"; - $expected = array( - 'status' => 'success', - 'data' => array('message'=> 'User order saved successfully.'), - 'order' => $order - ); - $result = $this->controller->savePersonal($order); - $this->assertEquals($expected, $result); - } + public function testSavePersonal() { + $order = "RANDOMORDER"; + $expected = array( + 'status' => 'success', + 'data' => array('message' => 'User order saved successfully.'), + 'order' => $order + ); + $result = $this->controller->savePersonal($order); + $this->assertEquals($expected, $result); + } - public function testSaveDefaultOrder() { - $order = "RANDOMORDER"; - $expected = array( - 'status' => 'success', - 'order' => $order - ); - $result = $this->controller->saveDefaultOrder($order); - $this->assertEquals($expected, $result); - } + public function testSaveDefaultOrder() { + $order = "RANDOMORDER"; + $expected = array( + 'status' => 'success', + 'order' => $order + ); + $result = $this->controller->saveDefaultOrder($order); + $this->assertEquals($expected, $result); + } } diff --git a/tests/unit/service/ConfigServiceTest.php b/tests/unit/service/ConfigServiceTest.php index 684350c..a572973 100644 --- a/tests/unit/service/ConfigServiceTest.php +++ b/tests/unit/service/ConfigServiceTest.php @@ -1,39 +1,61 @@ <?php +/** + * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ namespace OCA\AppOrder\Tests\Unit\Service; use OCA\AppOrder\Service\ConfigService; use OCP\IConfig; -class ConfigServiceTest extends \Test\TestCase { - - private $config; - private $service; - - public function setUp() { - $this->config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor()->getMock(); - $this->service = new ConfigService($this->config, 'apporder'); - } - - public function testAppValue() { - $this->config->expects($this->any()) - ->method('getAppValue') - ->with('apporder', 'foo') - ->willReturn('bar'); -// $this->service->setAppValue("foo","bar"); - $result = $this->service->getAppValue("foo"); - $this->assertEquals('bar', $result); - } - - public function testUserValue() { - $this->config->expects($this->any()) - ->method('getUserValue') - ->with('user', 'apporder', 'foo') - ->willReturn('bar'); - $this->service->setUserValue("foo", "user", "bar"); - $result = $this->service->getUserValue("foo", "user"); - $this->assertEquals('bar', $result); - } - - } +class ConfigServiceTest extends \PHPUnit_Framework_TestCase { + + /** @var IConfig */ + private $config; + /** @var ConfigService */ + private $service; + + public function setUp() { + $this->config = $this->getMockBuilder('\OCP\IConfig') + ->disableOriginalConstructor()->getMock(); + $this->service = new ConfigService($this->config, 'apporder'); + } + + public function testAppValue() { + $this->config->expects($this->any()) + ->method('getAppValue') + ->with('apporder', 'foo') + ->willReturn('bar'); + $result = $this->service->getAppValue("foo"); + $this->assertEquals('bar', $result); + } + + public function testUserValue() { + $this->config->expects($this->any()) + ->method('getUserValue') + ->with('user', 'apporder', 'foo') + ->willReturn('bar'); + $this->service->setUserValue("foo", "user", "bar"); + $result = $this->service->getUserValue("foo", "user"); + $this->assertEquals('bar', $result); + } + +} |