@@ -47,7 +47,7 @@ |
||
| 47 | 47 | foreach ($nav as $app) |
| 48 | 48 | $nav_tmp[$app['href']] = $app; |
| 49 | 49 | foreach ($order as $app) |
| 50 | - if(array_key_exists($app, $nav_tmp)) |
|
| 50 | + if (array_key_exists($app, $nav_tmp)) |
|
| 51 | 51 | $result[$app] = $nav_tmp[$app]; |
| 52 | 52 | foreach ($nav as $app) |
| 53 | 53 | if (!array_key_exists($app['href'], $result)) |
@@ -34,24 +34,28 @@ |
||
| 34 | 34 | public function getAppOrder() { |
| 35 | 35 | $order_user = $this->appConfig->getUserValue('order', $this->userId); |
| 36 | 36 | $order_default = $this->appConfig->getAppValue('order'); |
| 37 | - if ($order_user !== null && $order_user !== "") |
|
| 38 | - $order = $order_user; |
|
| 39 | - else |
|
| 40 | - $order = $order_default; |
|
| 37 | + if ($order_user !== null && $order_user !== "") { |
|
| 38 | + $order = $order_user; |
|
| 39 | + } else { |
|
| 40 | + $order = $order_default; |
|
| 41 | + } |
|
| 41 | 42 | return $order; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | public function matchOrder($nav, $order) { |
| 45 | 46 | $nav_tmp = array(); |
| 46 | 47 | $result = array(); |
| 47 | - foreach ($nav as $app) |
|
| 48 | - $nav_tmp[$app['href']] = $app; |
|
| 49 | - foreach ($order as $app) |
|
| 50 | - if(array_key_exists($app, $nav_tmp)) |
|
| 48 | + foreach ($nav as $app) { |
|
| 49 | + $nav_tmp[$app['href']] = $app; |
|
| 50 | + } |
|
| 51 | + foreach ($order as $app) { |
|
| 52 | + if(array_key_exists($app, $nav_tmp)) |
|
| 51 | 53 | $result[$app] = $nav_tmp[$app]; |
| 52 | - foreach ($nav as $app) |
|
| 53 | - if (!array_key_exists($app['href'], $result)) |
|
| 54 | + } |
|
| 55 | + foreach ($nav as $app) { |
|
| 56 | + if (!array_key_exists($app['href'], $result)) |
|
| 54 | 57 | $result[$app['href']] = $app; |
| 58 | + } |
|
| 55 | 59 | return $result; |
| 56 | 60 | } |
| 57 | 61 | |
@@ -27,36 +27,36 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Util { |
| 29 | 29 | |
| 30 | - private $userId; |
|
| 31 | - private $appConfig; |
|
| 32 | - |
|
| 33 | - public function __construct(ConfigService $appConfig, $userId) { |
|
| 34 | - $this->userId = $userId; |
|
| 35 | - $this->appConfig = $appConfig; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function getAppOrder() { |
|
| 39 | - $order_user = $this->appConfig->getUserValue('order', $this->userId); |
|
| 40 | - $order_default = $this->appConfig->getAppValue('order'); |
|
| 41 | - if ($order_user !== null && $order_user !== "") |
|
| 42 | - $order = $order_user; |
|
| 43 | - else |
|
| 44 | - $order = $order_default; |
|
| 45 | - return $order; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function matchOrder($nav, $order) { |
|
| 49 | - $nav_tmp = array(); |
|
| 50 | - $result = array(); |
|
| 51 | - foreach ($nav as $app) |
|
| 52 | - $nav_tmp[$app['href']] = $app; |
|
| 53 | - foreach ($order as $app) |
|
| 54 | - if(array_key_exists($app, $nav_tmp)) |
|
| 55 | - $result[$app] = $nav_tmp[$app]; |
|
| 56 | - foreach ($nav as $app) |
|
| 57 | - if (!array_key_exists($app['href'], $result)) |
|
| 58 | - $result[$app['href']] = $app; |
|
| 59 | - return $result; |
|
| 60 | - } |
|
| 30 | + private $userId; |
|
| 31 | + private $appConfig; |
|
| 32 | + |
|
| 33 | + public function __construct(ConfigService $appConfig, $userId) { |
|
| 34 | + $this->userId = $userId; |
|
| 35 | + $this->appConfig = $appConfig; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function getAppOrder() { |
|
| 39 | + $order_user = $this->appConfig->getUserValue('order', $this->userId); |
|
| 40 | + $order_default = $this->appConfig->getAppValue('order'); |
|
| 41 | + if ($order_user !== null && $order_user !== "") |
|
| 42 | + $order = $order_user; |
|
| 43 | + else |
|
| 44 | + $order = $order_default; |
|
| 45 | + return $order; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function matchOrder($nav, $order) { |
|
| 49 | + $nav_tmp = array(); |
|
| 50 | + $result = array(); |
|
| 51 | + foreach ($nav as $app) |
|
| 52 | + $nav_tmp[$app['href']] = $app; |
|
| 53 | + foreach ($order as $app) |
|
| 54 | + if(array_key_exists($app, $nav_tmp)) |
|
| 55 | + $result[$app] = $nav_tmp[$app]; |
|
| 56 | + foreach ($nav as $app) |
|
| 57 | + if (!array_key_exists($app['href'], $result)) |
|
| 58 | + $result[$app['href']] = $app; |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | require_once __DIR__.'/../../../lib/base.php'; |
| 29 | 29 | if(!class_exists('PHPUnit_Framework_TestCase')) { |
| 30 | - require_once('PHPUnit/Autoload.php'); |
|
| 30 | + require_once('PHPUnit/Autoload.php'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | \OC_App::loadApp('apporder'); |
@@ -21,11 +21,11 @@ |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | -require_once __DIR__ . '/../../../tests/bootstrap.php'; |
|
| 25 | -require_once __DIR__ . '/../appinfo/autoload.php'; |
|
| 24 | +require_once __DIR__.'/../../../tests/bootstrap.php'; |
|
| 25 | +require_once __DIR__.'/../appinfo/autoload.php'; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | -require_once __DIR__ . '/../../../lib/base.php'; |
|
| 28 | +require_once __DIR__.'/../../../lib/base.php'; |
|
| 29 | 29 | if (!class_exists('PHPUnit_Framework_TestCase')) { |
| 30 | 30 | require_once('PHPUnit/Autoload.php'); |
| 31 | 31 | } |
@@ -52,14 +52,14 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | public function index() { |
| 54 | 54 | $order = json_decode($this->util->getAppOrder()); |
| 55 | - if($order !== null && sizeof($order)>0) { |
|
| 55 | + if ($order !== null && sizeof($order) > 0) { |
|
| 56 | 56 | $firstPage = $order[0]; |
| 57 | 57 | } else { |
| 58 | 58 | $appId = 'files'; |
| 59 | - if(getenv('front_controller_active') === 'true') { |
|
| 60 | - $firstPage = $this->urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 59 | + if (getenv('front_controller_active') === 'true') { |
|
| 60 | + $firstPage = $this->urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
| 61 | 61 | } else { |
| 62 | - $firstPage = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 62 | + $firstPage = $this->urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | return new RedirectResponse($firstPage); |
@@ -36,33 +36,33 @@ |
||
| 36 | 36 | private $userId; |
| 37 | 37 | private $appConfig; |
| 38 | 38 | private $urlGenerator; |
| 39 | - private $util; |
|
| 39 | + private $util; |
|
| 40 | 40 | |
| 41 | 41 | public function __construct($appName, IRequest $request, ConfigService $appConfig, IURLGenerator $urlGenerator, Util $util, $userId) { |
| 42 | 42 | parent::__construct($appName, $request); |
| 43 | 43 | $this->userId = $userId; |
| 44 | 44 | $this->appConfig = $appConfig; |
| 45 | 45 | $this->urlGenerator = $urlGenerator; |
| 46 | - $this->util = $util; |
|
| 46 | + $this->util = $util; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @NoCSRFRequired |
|
| 51 | - * @NoAdminRequired |
|
| 52 | - * @return RedirectResponse |
|
| 53 | - */ |
|
| 49 | + /** |
|
| 50 | + * @NoCSRFRequired |
|
| 51 | + * @NoAdminRequired |
|
| 52 | + * @return RedirectResponse |
|
| 53 | + */ |
|
| 54 | 54 | public function index() { |
| 55 | - $order = json_decode($this->util->getAppOrder()); |
|
| 56 | - if($order !== null && sizeof($order)>0) { |
|
| 57 | - $firstPage = $order[0]; |
|
| 58 | - } else { |
|
| 59 | - $appId = 'files'; |
|
| 60 | - if(getenv('front_controller_active') === 'true') { |
|
| 61 | - $firstPage = $this->urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 62 | - } else { |
|
| 63 | - $firstPage = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 64 | - } |
|
| 65 | - } |
|
| 55 | + $order = json_decode($this->util->getAppOrder()); |
|
| 56 | + if($order !== null && sizeof($order)>0) { |
|
| 57 | + $firstPage = $order[0]; |
|
| 58 | + } else { |
|
| 59 | + $appId = 'files'; |
|
| 60 | + if(getenv('front_controller_active') === 'true') { |
|
| 61 | + $firstPage = $this->urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 62 | + } else { |
|
| 63 | + $firstPage = $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | return new RedirectResponse($firstPage); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -28,74 +28,74 @@ |
||
| 28 | 28 | |
| 29 | 29 | class UtilTest extends \PHPUnit_Framework_TestCase { |
| 30 | 30 | |
| 31 | - /** @var ConfigService */ |
|
| 32 | - private $service; |
|
| 33 | - /** @var string */ |
|
| 34 | - private $userId; |
|
| 35 | - /** @var Util */ |
|
| 36 | - private $util; |
|
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 31 | + /** @var ConfigService */ |
|
| 32 | + private $service; |
|
| 33 | + /** @var string */ |
|
| 34 | + private $userId; |
|
| 35 | + /** @var Util */ |
|
| 36 | + private $util; |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | 39 | |
| 40 | - public function setUp() { |
|
| 40 | + public function setUp() { |
|
| 41 | 41 | |
| 42 | - parent::setUp(); |
|
| 42 | + parent::setUp(); |
|
| 43 | 43 | |
| 44 | - $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 45 | - ->disableOriginalConstructor() |
|
| 46 | - ->getMock(); |
|
| 47 | - $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
| 48 | - ->disableOriginalConstructor() |
|
| 49 | - ->getMock(); |
|
| 50 | - $this->userId = 'admin'; |
|
| 51 | - $this->util = new Util($this->service, $this->userId); |
|
| 44 | + $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 45 | + ->disableOriginalConstructor() |
|
| 46 | + ->getMock(); |
|
| 47 | + $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
| 48 | + ->disableOriginalConstructor() |
|
| 49 | + ->getMock(); |
|
| 50 | + $this->userId = 'admin'; |
|
| 51 | + $this->util = new Util($this->service, $this->userId); |
|
| 52 | 52 | |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function testMatchOrder() { |
|
| 56 | - $nav = [ |
|
| 57 | - ['href' => '/app/files/', 'name' => 'Files'], |
|
| 58 | - ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 59 | - ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 60 | - ]; |
|
| 61 | - $order = ['/app/calendar/', '/app/tasks/']; |
|
| 62 | - $result = $this->util->matchOrder($nav, $order); |
|
| 63 | - $expected = [ |
|
| 64 | - '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 65 | - '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 66 | - '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
| 67 | - ]; |
|
| 68 | - $this->assertEquals($expected, $result); |
|
| 69 | - } |
|
| 55 | + public function testMatchOrder() { |
|
| 56 | + $nav = [ |
|
| 57 | + ['href' => '/app/files/', 'name' => 'Files'], |
|
| 58 | + ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 59 | + ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 60 | + ]; |
|
| 61 | + $order = ['/app/calendar/', '/app/tasks/']; |
|
| 62 | + $result = $this->util->matchOrder($nav, $order); |
|
| 63 | + $expected = [ |
|
| 64 | + '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 65 | + '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 66 | + '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
| 67 | + ]; |
|
| 68 | + $this->assertEquals($expected, $result); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function testGetAppOrder() { |
|
| 72 | - $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 73 | - $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 74 | - $this->service->expects($this->once()) |
|
| 75 | - ->method('getAppValue') |
|
| 76 | - ->with('order') |
|
| 77 | - ->will($this->returnValue(json_encode($nav_system))); |
|
| 78 | - $this->service->expects($this->once()) |
|
| 79 | - ->method('getUserValue') |
|
| 80 | - ->with('order', $this->userId) |
|
| 81 | - ->will($this->returnValue(json_encode($nav_user))); |
|
| 82 | - $result = $this->util->getAppOrder(); |
|
| 83 | - $this->assertEquals(json_encode($nav_user), $result); |
|
| 84 | - } |
|
| 71 | + public function testGetAppOrder() { |
|
| 72 | + $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 73 | + $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 74 | + $this->service->expects($this->once()) |
|
| 75 | + ->method('getAppValue') |
|
| 76 | + ->with('order') |
|
| 77 | + ->will($this->returnValue(json_encode($nav_system))); |
|
| 78 | + $this->service->expects($this->once()) |
|
| 79 | + ->method('getUserValue') |
|
| 80 | + ->with('order', $this->userId) |
|
| 81 | + ->will($this->returnValue(json_encode($nav_user))); |
|
| 82 | + $result = $this->util->getAppOrder(); |
|
| 83 | + $this->assertEquals(json_encode($nav_user), $result); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function testGetAppOrderNoUser() { |
|
| 87 | - $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 88 | - $nav_user = ''; |
|
| 89 | - $this->service->expects($this->once()) |
|
| 90 | - ->method('getAppValue') |
|
| 91 | - ->with('order') |
|
| 92 | - ->will($this->returnValue(json_encode($nav_system))); |
|
| 93 | - $this->service->expects($this->once()) |
|
| 94 | - ->method('getUserValue') |
|
| 95 | - ->with('order', $this->userId) |
|
| 96 | - ->will($this->returnValue($nav_user)); |
|
| 97 | - $result = $this->util->getAppOrder(); |
|
| 98 | - $this->assertEquals(json_encode($nav_system), $result); |
|
| 99 | - } |
|
| 86 | + public function testGetAppOrderNoUser() { |
|
| 87 | + $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 88 | + $nav_user = ''; |
|
| 89 | + $this->service->expects($this->once()) |
|
| 90 | + ->method('getAppValue') |
|
| 91 | + ->with('order') |
|
| 92 | + ->will($this->returnValue(json_encode($nav_system))); |
|
| 93 | + $this->service->expects($this->once()) |
|
| 94 | + ->method('getUserValue') |
|
| 95 | + ->with('order', $this->userId) |
|
| 96 | + ->will($this->returnValue($nav_user)); |
|
| 97 | + $result = $this->util->getAppOrder(); |
|
| 98 | + $this->assertEquals(json_encode($nav_system), $result); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | } |
@@ -28,34 +28,34 @@ |
||
| 28 | 28 | |
| 29 | 29 | class ConfigServiceTest extends \PHPUnit_Framework_TestCase { |
| 30 | 30 | |
| 31 | - /** @var IConfig */ |
|
| 32 | - private $config; |
|
| 33 | - /** @var ConfigService */ |
|
| 34 | - private $service; |
|
| 35 | - |
|
| 36 | - public function setUp() { |
|
| 37 | - $this->config = $this->getMockBuilder('\OCP\IConfig') |
|
| 38 | - ->disableOriginalConstructor()->getMock(); |
|
| 39 | - $this->service = new ConfigService($this->config, 'apporder'); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function testAppValue() { |
|
| 43 | - $this->config->expects($this->any()) |
|
| 44 | - ->method('getAppValue') |
|
| 45 | - ->with('apporder', 'foo') |
|
| 46 | - ->willReturn('bar'); |
|
| 47 | - $result = $this->service->getAppValue("foo"); |
|
| 48 | - $this->assertEquals('bar', $result); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function testUserValue() { |
|
| 52 | - $this->config->expects($this->any()) |
|
| 53 | - ->method('getUserValue') |
|
| 54 | - ->with('user', 'apporder', 'foo') |
|
| 55 | - ->willReturn('bar'); |
|
| 56 | - $this->service->setUserValue("foo", "user", "bar"); |
|
| 57 | - $result = $this->service->getUserValue("foo", "user"); |
|
| 58 | - $this->assertEquals('bar', $result); |
|
| 59 | - } |
|
| 31 | + /** @var IConfig */ |
|
| 32 | + private $config; |
|
| 33 | + /** @var ConfigService */ |
|
| 34 | + private $service; |
|
| 35 | + |
|
| 36 | + public function setUp() { |
|
| 37 | + $this->config = $this->getMockBuilder('\OCP\IConfig') |
|
| 38 | + ->disableOriginalConstructor()->getMock(); |
|
| 39 | + $this->service = new ConfigService($this->config, 'apporder'); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function testAppValue() { |
|
| 43 | + $this->config->expects($this->any()) |
|
| 44 | + ->method('getAppValue') |
|
| 45 | + ->with('apporder', 'foo') |
|
| 46 | + ->willReturn('bar'); |
|
| 47 | + $result = $this->service->getAppValue("foo"); |
|
| 48 | + $this->assertEquals('bar', $result); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function testUserValue() { |
|
| 52 | + $this->config->expects($this->any()) |
|
| 53 | + ->method('getUserValue') |
|
| 54 | + ->with('user', 'apporder', 'foo') |
|
| 55 | + ->willReturn('bar'); |
|
| 56 | + $this->service->setUserValue("foo", "user", "bar"); |
|
| 57 | + $result = $this->service->getUserValue("foo", "user"); |
|
| 58 | + $this->assertEquals('bar', $result); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | } |
@@ -32,61 +32,61 @@ |
||
| 32 | 32 | |
| 33 | 33 | class AppControllerTest extends \PHPUnit_Framework_TestCase { |
| 34 | 34 | |
| 35 | - /** @var IRequest */ |
|
| 36 | - private $request; |
|
| 37 | - /** @var IURLGenerator */ |
|
| 38 | - private $urlGenerator; |
|
| 39 | - /** @var string */ |
|
| 40 | - private $userId; |
|
| 41 | - /** @var string */ |
|
| 42 | - private $appName; |
|
| 43 | - /** @var AppController */ |
|
| 44 | - private $controller; |
|
| 45 | - /** @var IConfig */ |
|
| 46 | - private $config; |
|
| 47 | - /** @var Util */ |
|
| 48 | - private $util; |
|
| 35 | + /** @var IRequest */ |
|
| 36 | + private $request; |
|
| 37 | + /** @var IURLGenerator */ |
|
| 38 | + private $urlGenerator; |
|
| 39 | + /** @var string */ |
|
| 40 | + private $userId; |
|
| 41 | + /** @var string */ |
|
| 42 | + private $appName; |
|
| 43 | + /** @var AppController */ |
|
| 44 | + private $controller; |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + private $config; |
|
| 47 | + /** @var Util */ |
|
| 48 | + private $util; |
|
| 49 | 49 | |
| 50 | - public function setUp() { |
|
| 51 | - parent::setUp(); |
|
| 52 | - $this->request = $this->getMockBuilder('OCP\IRequest') |
|
| 53 | - ->disableOriginalConstructor() |
|
| 54 | - ->getMock(); |
|
| 55 | - $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 56 | - ->disableOriginalConstructor() |
|
| 57 | - ->getMock(); |
|
| 58 | - $this->util = $this->getMockBuilder('\OCA\AppOrder\Util') |
|
| 59 | - ->disableOriginalConstructor() |
|
| 60 | - ->getMock(); |
|
| 61 | - $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 62 | - $this->userId = 'admin'; |
|
| 63 | - $this->appName = 'apporder'; |
|
| 64 | - $this->controller = new AppController( |
|
| 65 | - $this->appName, |
|
| 66 | - $this->request, |
|
| 67 | - $this->urlGenerator, |
|
| 68 | - $this->util, |
|
| 69 | - $this->userId |
|
| 70 | - ); |
|
| 71 | - } |
|
| 50 | + public function setUp() { |
|
| 51 | + parent::setUp(); |
|
| 52 | + $this->request = $this->getMockBuilder('OCP\IRequest') |
|
| 53 | + ->disableOriginalConstructor() |
|
| 54 | + ->getMock(); |
|
| 55 | + $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 56 | + ->disableOriginalConstructor() |
|
| 57 | + ->getMock(); |
|
| 58 | + $this->util = $this->getMockBuilder('\OCA\AppOrder\Util') |
|
| 59 | + ->disableOriginalConstructor() |
|
| 60 | + ->getMock(); |
|
| 61 | + $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 62 | + $this->userId = 'admin'; |
|
| 63 | + $this->appName = 'apporder'; |
|
| 64 | + $this->controller = new AppController( |
|
| 65 | + $this->appName, |
|
| 66 | + $this->request, |
|
| 67 | + $this->urlGenerator, |
|
| 68 | + $this->util, |
|
| 69 | + $this->userId |
|
| 70 | + ); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function testIndex() { |
|
| 74 | - $this->util->expects($this->once()) |
|
| 75 | - ->method('getAppOrder') |
|
| 76 | - ->willReturn(json_encode(['/index.php/foo/bar', '/index.php/bar/foo'])); |
|
| 77 | - $expected = new Http\RedirectResponse('/index.php/foo/bar'); |
|
| 78 | - $result = $this->controller->index(); |
|
| 79 | - $this->assertEquals($expected, $result); |
|
| 80 | - } |
|
| 73 | + public function testIndex() { |
|
| 74 | + $this->util->expects($this->once()) |
|
| 75 | + ->method('getAppOrder') |
|
| 76 | + ->willReturn(json_encode(['/index.php/foo/bar', '/index.php/bar/foo'])); |
|
| 77 | + $expected = new Http\RedirectResponse('/index.php/foo/bar'); |
|
| 78 | + $result = $this->controller->index(); |
|
| 79 | + $this->assertEquals($expected, $result); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function testIndexEmpty() { |
|
| 83 | - $this->util->expects($this->once()) |
|
| 84 | - ->method('getAppOrder') |
|
| 85 | - ->willReturn(""); |
|
| 86 | - $result = $this->controller->index(); |
|
| 87 | - $expected = new Http\RedirectResponse('http://localhost/index.php/apps/files/'); |
|
| 88 | - $this->assertEquals($expected, $result); |
|
| 89 | - } |
|
| 82 | + public function testIndexEmpty() { |
|
| 83 | + $this->util->expects($this->once()) |
|
| 84 | + ->method('getAppOrder') |
|
| 85 | + ->willReturn(""); |
|
| 86 | + $result = $this->controller->index(); |
|
| 87 | + $expected = new Http\RedirectResponse('http://localhost/index.php/apps/files/'); |
|
| 88 | + $this->assertEquals($expected, $result); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | } |
@@ -32,118 +32,118 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SettingsControllerTest extends \PHPUnit_Framework_TestCase { |
| 34 | 34 | |
| 35 | - /** @var IRequest */ |
|
| 36 | - private $request; |
|
| 37 | - /** @var ConfigService */ |
|
| 38 | - private $service; |
|
| 39 | - /** @var INavigationManager */ |
|
| 40 | - private $navigationManager; |
|
| 41 | - /** @var string */ |
|
| 42 | - private $userId; |
|
| 43 | - /** @var string */ |
|
| 44 | - private $appName; |
|
| 45 | - /** @var SettingsController */ |
|
| 46 | - private $controller; |
|
| 47 | - /** @var IConfig */ |
|
| 48 | - private $config; |
|
| 49 | - /** @var Util */ |
|
| 50 | - private $util; |
|
| 35 | + /** @var IRequest */ |
|
| 36 | + private $request; |
|
| 37 | + /** @var ConfigService */ |
|
| 38 | + private $service; |
|
| 39 | + /** @var INavigationManager */ |
|
| 40 | + private $navigationManager; |
|
| 41 | + /** @var string */ |
|
| 42 | + private $userId; |
|
| 43 | + /** @var string */ |
|
| 44 | + private $appName; |
|
| 45 | + /** @var SettingsController */ |
|
| 46 | + private $controller; |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + private $config; |
|
| 49 | + /** @var Util */ |
|
| 50 | + private $util; |
|
| 51 | 51 | |
| 52 | - public function setUp() { |
|
| 52 | + public function setUp() { |
|
| 53 | 53 | |
| 54 | - parent::setUp(); |
|
| 55 | - $this->request = $this->getMockBuilder('OCP\IRequest') |
|
| 56 | - ->disableOriginalConstructor() |
|
| 57 | - ->getMock(); |
|
| 58 | - $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 59 | - ->disableOriginalConstructor() |
|
| 60 | - ->getMock(); |
|
| 61 | - $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
| 62 | - ->disableOriginalConstructor() |
|
| 63 | - ->getMock(); |
|
| 64 | - $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager') |
|
| 65 | - ->setMethods(['getAll', 'add', 'setActiveEntry']) |
|
| 66 | - ->disableOriginalConstructor() |
|
| 67 | - ->getMock(); |
|
| 54 | + parent::setUp(); |
|
| 55 | + $this->request = $this->getMockBuilder('OCP\IRequest') |
|
| 56 | + ->disableOriginalConstructor() |
|
| 57 | + ->getMock(); |
|
| 58 | + $this->config = $this->getMockBuilder('OCP\IConfig') |
|
| 59 | + ->disableOriginalConstructor() |
|
| 60 | + ->getMock(); |
|
| 61 | + $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
| 62 | + ->disableOriginalConstructor() |
|
| 63 | + ->getMock(); |
|
| 64 | + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager') |
|
| 65 | + ->setMethods(['getAll', 'add', 'setActiveEntry']) |
|
| 66 | + ->disableOriginalConstructor() |
|
| 67 | + ->getMock(); |
|
| 68 | 68 | |
| 69 | - $this->userId = 'admin'; |
|
| 70 | - $this->appName = 'apporder'; |
|
| 71 | - $this->util = new Util($this->service, $this->userId); |
|
| 72 | - $this->controller = new SettingsController( |
|
| 73 | - $this->appName, |
|
| 74 | - $this->request, |
|
| 75 | - $this->service, |
|
| 76 | - $this->navigationManager, |
|
| 77 | - $this->util, |
|
| 78 | - $this->userId |
|
| 79 | - ); |
|
| 69 | + $this->userId = 'admin'; |
|
| 70 | + $this->appName = 'apporder'; |
|
| 71 | + $this->util = new Util($this->service, $this->userId); |
|
| 72 | + $this->controller = new SettingsController( |
|
| 73 | + $this->appName, |
|
| 74 | + $this->request, |
|
| 75 | + $this->service, |
|
| 76 | + $this->navigationManager, |
|
| 77 | + $this->util, |
|
| 78 | + $this->userId |
|
| 79 | + ); |
|
| 80 | 80 | |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function testAdminIndex() { |
|
| 84 | - $nav_custom = ['/app/calendar/', '/app/tasks/']; |
|
| 85 | - $nav_oc = [ |
|
| 86 | - ['href' => '/app/files/', 'name' => 'Files'], |
|
| 87 | - ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 88 | - ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 89 | - ]; |
|
| 90 | - $nav_final = [ |
|
| 91 | - '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] |
|
| 92 | - ]; |
|
| 93 | - $this->service->expects($this->once()) |
|
| 94 | - ->method('getAppValue') |
|
| 95 | - ->with('order') |
|
| 96 | - ->will($this->returnValue(json_encode($nav_custom))); |
|
| 97 | - $this->navigationManager->expects($this->once()) |
|
| 98 | - ->method('getAll') |
|
| 99 | - ->will($this->returnValue($nav_oc)); |
|
| 83 | + public function testAdminIndex() { |
|
| 84 | + $nav_custom = ['/app/calendar/', '/app/tasks/']; |
|
| 85 | + $nav_oc = [ |
|
| 86 | + ['href' => '/app/files/', 'name' => 'Files'], |
|
| 87 | + ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 88 | + ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 89 | + ]; |
|
| 90 | + $nav_final = [ |
|
| 91 | + '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] |
|
| 92 | + ]; |
|
| 93 | + $this->service->expects($this->once()) |
|
| 94 | + ->method('getAppValue') |
|
| 95 | + ->with('order') |
|
| 96 | + ->will($this->returnValue(json_encode($nav_custom))); |
|
| 97 | + $this->navigationManager->expects($this->once()) |
|
| 98 | + ->method('getAll') |
|
| 99 | + ->will($this->returnValue($nav_oc)); |
|
| 100 | 100 | |
| 101 | - $result = $this->controller->adminIndex(); |
|
| 102 | - $expected = new \OCP\AppFramework\Http\TemplateResponse( |
|
| 103 | - $this->appName, |
|
| 104 | - 'admin', |
|
| 105 | - ["nav" => $nav_final], |
|
| 106 | - 'blank' |
|
| 107 | - ); |
|
| 108 | - $this->assertEquals($expected, $result); |
|
| 109 | - } |
|
| 101 | + $result = $this->controller->adminIndex(); |
|
| 102 | + $expected = new \OCP\AppFramework\Http\TemplateResponse( |
|
| 103 | + $this->appName, |
|
| 104 | + 'admin', |
|
| 105 | + ["nav" => $nav_final], |
|
| 106 | + 'blank' |
|
| 107 | + ); |
|
| 108 | + $this->assertEquals($expected, $result); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - public function testGetOrder() { |
|
| 113 | - $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 114 | - $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 115 | - $this->service->expects($this->once()) |
|
| 116 | - ->method('getAppValue') |
|
| 117 | - ->with('order') |
|
| 118 | - ->will($this->returnValue(json_encode($nav_system))); |
|
| 119 | - $this->service->expects($this->once()) |
|
| 120 | - ->method('getUserValue') |
|
| 121 | - ->with('order', $this->userId) |
|
| 122 | - ->will($this->returnValue(json_encode($nav_user))); |
|
| 123 | - $order = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 124 | - $result = $this->controller->getOrder(); |
|
| 125 | - $expected = array('status' => 'success', 'order' => json_encode($order)); |
|
| 126 | - $this->assertEquals($expected, $result); |
|
| 127 | - } |
|
| 112 | + public function testGetOrder() { |
|
| 113 | + $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 114 | + $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 115 | + $this->service->expects($this->once()) |
|
| 116 | + ->method('getAppValue') |
|
| 117 | + ->with('order') |
|
| 118 | + ->will($this->returnValue(json_encode($nav_system))); |
|
| 119 | + $this->service->expects($this->once()) |
|
| 120 | + ->method('getUserValue') |
|
| 121 | + ->with('order', $this->userId) |
|
| 122 | + ->will($this->returnValue(json_encode($nav_user))); |
|
| 123 | + $order = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
| 124 | + $result = $this->controller->getOrder(); |
|
| 125 | + $expected = array('status' => 'success', 'order' => json_encode($order)); |
|
| 126 | + $this->assertEquals($expected, $result); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public function testSavePersonal() { |
|
| 130 | - $order = "RANDOMORDER"; |
|
| 131 | - $expected = array( |
|
| 132 | - 'status' => 'success', |
|
| 133 | - 'data' => array('message' => 'User order saved successfully.'), |
|
| 134 | - 'order' => $order |
|
| 135 | - ); |
|
| 136 | - $result = $this->controller->savePersonal($order); |
|
| 137 | - $this->assertEquals($expected, $result); |
|
| 138 | - } |
|
| 129 | + public function testSavePersonal() { |
|
| 130 | + $order = "RANDOMORDER"; |
|
| 131 | + $expected = array( |
|
| 132 | + 'status' => 'success', |
|
| 133 | + 'data' => array('message' => 'User order saved successfully.'), |
|
| 134 | + 'order' => $order |
|
| 135 | + ); |
|
| 136 | + $result = $this->controller->savePersonal($order); |
|
| 137 | + $this->assertEquals($expected, $result); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public function testSaveDefaultOrder() { |
|
| 141 | - $order = "RANDOMORDER"; |
|
| 142 | - $expected = array( |
|
| 143 | - 'status' => 'success', |
|
| 144 | - 'order' => $order |
|
| 145 | - ); |
|
| 146 | - $result = $this->controller->saveDefaultOrder($order); |
|
| 147 | - $this->assertEquals($expected, $result); |
|
| 148 | - } |
|
| 140 | + public function testSaveDefaultOrder() { |
|
| 141 | + $order = "RANDOMORDER"; |
|
| 142 | + $expected = array( |
|
| 143 | + 'status' => 'success', |
|
| 144 | + 'order' => $order |
|
| 145 | + ); |
|
| 146 | + $result = $this->controller->saveDefaultOrder($order); |
|
| 147 | + $this->assertEquals($expected, $result); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | use OCP\INavigationManager; |
| 31 | 31 | use OCP\IRequest; |
| 32 | 32 | |
| 33 | -class SettingsControllerTest extends \PHPUnit_Framework_TestCase { |
|
| 33 | +class SettingsControllerTest extends \PHPUnit_Framework_TestCase { |
|
| 34 | 34 | |
| 35 | 35 | /** @var IRequest */ |
| 36 | 36 | private $request; |
@@ -22,10 +22,10 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | return [ |
| 25 | - 'routes' => [ |
|
| 26 | - ['name' => 'app#index', 'url' => '/', 'verb' => 'GET'], |
|
| 27 | - ['name' => 'settings#getOrder', 'url' => 'ajax/order.php', 'verb' => 'GET'], |
|
| 28 | - ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'GET'], |
|
| 29 | - ['name' => 'settings#saveDefaultOrder', 'url' => 'ajax/admin.php', 'verb' => 'GET'], |
|
| 30 | - ] |
|
| 25 | + 'routes' => [ |
|
| 26 | + ['name' => 'app#index', 'url' => '/', 'verb' => 'GET'], |
|
| 27 | + ['name' => 'settings#getOrder', 'url' => 'ajax/order.php', 'verb' => 'GET'], |
|
| 28 | + ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'GET'], |
|
| 29 | + ['name' => 'settings#saveDefaultOrder', 'url' => 'ajax/admin.php', 'verb' => 'GET'], |
|
| 30 | + ] |
|
| 31 | 31 | ]; |
@@ -28,14 +28,14 @@ |
||
| 28 | 28 | |
| 29 | 29 | class Application extends App { |
| 30 | 30 | |
| 31 | - public function __construct(array $urlParams = array()) { |
|
| 32 | - parent::__construct('apporder', $urlParams); |
|
| 33 | - $container = $this->getContainer(); |
|
| 34 | - $container->registerService('ConfigService', function ($c) { |
|
| 35 | - return new ConfigService( |
|
| 36 | - $c->query('Config'), |
|
| 37 | - $c->query('AppName') |
|
| 38 | - ); |
|
| 39 | - }); |
|
| 40 | - } |
|
| 31 | + public function __construct(array $urlParams = array()) { |
|
| 32 | + parent::__construct('apporder', $urlParams); |
|
| 33 | + $container = $this->getContainer(); |
|
| 34 | + $container->registerService('ConfigService', function ($c) { |
|
| 35 | + return new ConfigService( |
|
| 36 | + $c->query('Config'), |
|
| 37 | + $c->query('AppName') |
|
| 38 | + ); |
|
| 39 | + }); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | public function __construct(array $urlParams = array()) { |
| 32 | 32 | parent::__construct('apporder', $urlParams); |
| 33 | 33 | $container = $this->getContainer(); |
| 34 | - $container->registerService('ConfigService', function ($c) { |
|
| 34 | + $container->registerService('ConfigService', function($c) { |
|
| 35 | 35 | return new ConfigService( |
| 36 | 36 | $c->query('Config'), |
| 37 | 37 | $c->query('AppName') |