@@ -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 | } |
@@ -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 | } |
@@ -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,28 +27,28 @@ |
||
| 27 | 27 | |
| 28 | 28 | class ConfigService { |
| 29 | 29 | |
| 30 | - private $config; |
|
| 31 | - private $appName; |
|
| 30 | + private $config; |
|
| 31 | + private $appName; |
|
| 32 | 32 | |
| 33 | - public function __construct(IConfig $config, $appName) { |
|
| 34 | - $this->config = $config; |
|
| 35 | - $this->appName = $appName; |
|
| 36 | - } |
|
| 33 | + public function __construct(IConfig $config, $appName) { |
|
| 34 | + $this->config = $config; |
|
| 35 | + $this->appName = $appName; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function getAppValue($key) { |
|
| 39 | - return $this->config->getAppValue($this->appName, $key); |
|
| 40 | - } |
|
| 38 | + public function getAppValue($key) { |
|
| 39 | + return $this->config->getAppValue($this->appName, $key); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function setAppValue($key, $value) { |
|
| 43 | - $this->config->setAppValue($this->appName, $key, $value); |
|
| 44 | - } |
|
| 42 | + public function setAppValue($key, $value) { |
|
| 43 | + $this->config->setAppValue($this->appName, $key, $value); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getUserValue($key, $userId) { |
|
| 47 | - return $this->config->getUserValue($userId, $this->appName, $key); |
|
| 48 | - } |
|
| 46 | + public function getUserValue($key, $userId) { |
|
| 47 | + return $this->config->getUserValue($userId, $this->appName, $key); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function setUserValue($key, $userId, $value) { |
|
| 51 | - $this->config->setUserValue($userId, $this->appName, $key, $value); |
|
| 52 | - } |
|
| 50 | + public function setUserValue($key, $userId, $value) { |
|
| 51 | + $this->config->setUserValue($userId, $this->appName, $key, $value); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
@@ -32,78 +32,78 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SettingsController extends Controller { |
| 34 | 34 | |
| 35 | - private $userId; |
|
| 36 | - private $appConfig; |
|
| 37 | - private $navigationManager; |
|
| 38 | - private $util; |
|
| 35 | + private $userId; |
|
| 36 | + private $appConfig; |
|
| 37 | + private $navigationManager; |
|
| 38 | + private $util; |
|
| 39 | 39 | |
| 40 | - public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) { |
|
| 41 | - parent::__construct($appName, $request); |
|
| 42 | - $this->userId = $userId; |
|
| 43 | - $this->appConfig = $appConfig; |
|
| 44 | - $this->navigationManager = $urlGenerator; |
|
| 45 | - $this->util = $util; |
|
| 46 | - } |
|
| 40 | + public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) { |
|
| 41 | + parent::__construct($appName, $request); |
|
| 42 | + $this->userId = $userId; |
|
| 43 | + $this->appConfig = $appConfig; |
|
| 44 | + $this->navigationManager = $urlGenerator; |
|
| 45 | + $this->util = $util; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Admin: render admin page |
|
| 50 | - * FIXME: Move to dedicated class |
|
| 51 | - * |
|
| 52 | - * @return TemplateResponse |
|
| 53 | - */ |
|
| 54 | - public function adminIndex() { |
|
| 55 | - // Private API call |
|
| 56 | - $navigation = $this->navigationManager->getAll(); |
|
| 57 | - $order = json_decode($this->appConfig->getAppValue('order')); |
|
| 58 | - $nav = $this->util->matchOrder($navigation, $order); |
|
| 59 | - return new TemplateResponse( |
|
| 60 | - $this->appName, |
|
| 61 | - 'admin', |
|
| 62 | - ["nav" => $nav], |
|
| 63 | - 'blank' |
|
| 64 | - ); |
|
| 65 | - } |
|
| 48 | + /** |
|
| 49 | + * Admin: render admin page |
|
| 50 | + * FIXME: Move to dedicated class |
|
| 51 | + * |
|
| 52 | + * @return TemplateResponse |
|
| 53 | + */ |
|
| 54 | + public function adminIndex() { |
|
| 55 | + // Private API call |
|
| 56 | + $navigation = $this->navigationManager->getAll(); |
|
| 57 | + $order = json_decode($this->appConfig->getAppValue('order')); |
|
| 58 | + $nav = $this->util->matchOrder($navigation, $order); |
|
| 59 | + return new TemplateResponse( |
|
| 60 | + $this->appName, |
|
| 61 | + 'admin', |
|
| 62 | + ["nav" => $nav], |
|
| 63 | + 'blank' |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Admin: save default order |
|
| 69 | - * |
|
| 70 | - * @param $order |
|
| 71 | - * @return array response |
|
| 72 | - */ |
|
| 73 | - public function saveDefaultOrder($order) { |
|
| 74 | - if (!is_null($order)) { |
|
| 75 | - $this->appConfig->setAppValue('order', $order); |
|
| 76 | - } |
|
| 77 | - return array('status' => 'success', 'order' => $order); |
|
| 78 | - } |
|
| 67 | + /** |
|
| 68 | + * Admin: save default order |
|
| 69 | + * |
|
| 70 | + * @param $order |
|
| 71 | + * @return array response |
|
| 72 | + */ |
|
| 73 | + public function saveDefaultOrder($order) { |
|
| 74 | + if (!is_null($order)) { |
|
| 75 | + $this->appConfig->setAppValue('order', $order); |
|
| 76 | + } |
|
| 77 | + return array('status' => 'success', 'order' => $order); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Return order for current user |
|
| 82 | - * |
|
| 83 | - * @NoAdminRequired |
|
| 84 | - * @return array response |
|
| 85 | - */ |
|
| 86 | - public function getOrder() { |
|
| 87 | - $order = $this->util->getAppOrder(); |
|
| 88 | - return array('status' => 'success', 'order' => $order); |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * Return order for current user |
|
| 82 | + * |
|
| 83 | + * @NoAdminRequired |
|
| 84 | + * @return array response |
|
| 85 | + */ |
|
| 86 | + public function getOrder() { |
|
| 87 | + $order = $this->util->getAppOrder(); |
|
| 88 | + return array('status' => 'success', 'order' => $order); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Save order for current user |
|
| 93 | - * |
|
| 94 | - * @NoAdminRequired |
|
| 95 | - * @param $order string |
|
| 96 | - * @return array response |
|
| 97 | - */ |
|
| 98 | - public function savePersonal($order) { |
|
| 99 | - $this->appConfig->setUserValue('order', $this->userId, $order); |
|
| 100 | - $response = array( |
|
| 101 | - 'status' => 'success', |
|
| 102 | - 'data' => array('message' => 'User order saved successfully.'), |
|
| 103 | - 'order' => $order |
|
| 104 | - ); |
|
| 105 | - return $response; |
|
| 106 | - } |
|
| 91 | + /** |
|
| 92 | + * Save order for current user |
|
| 93 | + * |
|
| 94 | + * @NoAdminRequired |
|
| 95 | + * @param $order string |
|
| 96 | + * @return array response |
|
| 97 | + */ |
|
| 98 | + public function savePersonal($order) { |
|
| 99 | + $this->appConfig->setUserValue('order', $this->userId, $order); |
|
| 100 | + $response = array( |
|
| 101 | + 'status' => 'success', |
|
| 102 | + 'data' => array('message' => 'User order saved successfully.'), |
|
| 103 | + 'order' => $order |
|
| 104 | + ); |
|
| 105 | + return $response; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | } |