@@ -8,21 +8,21 @@ discard block |
||
| 8 | 8 | use \OCP\INavigationManager; |
| 9 | 9 | use \OCA\AppOrder\Service\ConfigService; |
| 10 | 10 | |
| 11 | -class SettingsController extends Controller{ |
|
| 11 | +class SettingsController extends Controller { |
|
| 12 | 12 | |
| 13 | 13 | private $userId; |
| 14 | 14 | private $l10n; |
| 15 | 15 | private $appConfig; |
| 16 | 16 | private $navigationManager; |
| 17 | 17 | |
| 18 | - public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $navigationManager, $userId){ |
|
| 18 | + public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $navigationManager, $userId) { |
|
| 19 | 19 | parent::__construct($appName, $request); |
| 20 | 20 | $this->userId = $userId; |
| 21 | 21 | $this->appConfig = $appConfig; |
| 22 | 22 | $this->navigationManager = $navigationManager; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function adminIndex(){ |
|
| 25 | + public function adminIndex() { |
|
| 26 | 26 | $navigation = $this->navigationManager->getAll(); |
| 27 | 27 | $order = json_decode($this->appConfig->getAppValue('order')); |
| 28 | 28 | $nav = $this->matchOrder($navigation, $order); |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | private function matchOrder($nav, $order) { |
| 48 | 48 | $nav_tmp = array(); |
| 49 | 49 | $result = array(); |
| 50 | - foreach($nav as $app) |
|
| 50 | + foreach ($nav as $app) |
|
| 51 | 51 | $nav_tmp[$app['href']] = $app; |
| 52 | - foreach($order as $app) |
|
| 52 | + foreach ($order as $app) |
|
| 53 | 53 | $result[$app] = $nav_tmp[$app]; |
| 54 | - foreach($nav as $app) |
|
| 55 | - if(!array_key_exists($app['href'], $result)) |
|
| 54 | + foreach ($nav as $app) |
|
| 55 | + if (!array_key_exists($app['href'], $result)) |
|
| 56 | 56 | $result[$app['href']] = $app; |
| 57 | 57 | return $result; |
| 58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * @NoAdminRequired |
| 62 | 62 | */ |
| 63 | - public function getOrder(){ |
|
| 63 | + public function getOrder() { |
|
| 64 | 64 | $order = $this->getAppOrder(); |
| 65 | 65 | return array('status' => 'success', 'order' => $order); |
| 66 | 66 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * @NoAdminRequired |
| 70 | 70 | */ |
| 71 | - public function savePersonal($order){ |
|
| 71 | + public function savePersonal($order) { |
|
| 72 | 72 | $this->appConfig->setUserValue('order', $this->userId, $order); |
| 73 | 73 | $response = array( |
| 74 | 74 | 'status' => 'success', |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | return $response; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function saveDefaultOrder($order){ |
|
| 82 | - if (!is_null($order)){ |
|
| 83 | - $this->appConfig->setAppValue('order',$order); |
|
| 81 | + public function saveDefaultOrder($order) { |
|
| 82 | + if (!is_null($order)) { |
|
| 83 | + $this->appConfig->setAppValue('order', $order); |
|
| 84 | 84 | } |
| 85 | 85 | return array('status' => 'success', 'order' => $order); |
| 86 | 86 | } |
@@ -37,23 +37,27 @@ |
||
| 37 | 37 | private function getAppOrder() { |
| 38 | 38 | $order_user = $this->appConfig->getUserValue('order', $this->userId); |
| 39 | 39 | $order_default = $this->appConfig->getAppValue('order'); |
| 40 | - if ($order_user !== null && $order_user !== "") |
|
| 41 | - $order = $order_user; |
|
| 42 | - else |
|
| 43 | - $order = $order_default; |
|
| 40 | + if ($order_user !== null && $order_user !== "") { |
|
| 41 | + $order = $order_user; |
|
| 42 | + } else { |
|
| 43 | + $order = $order_default; |
|
| 44 | + } |
|
| 44 | 45 | return $order; |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | private function matchOrder($nav, $order) { |
| 48 | 49 | $nav_tmp = array(); |
| 49 | 50 | $result = array(); |
| 50 | - foreach($nav as $app) |
|
| 51 | - $nav_tmp[$app['href']] = $app; |
|
| 52 | - foreach($order as $app) |
|
| 53 | - $result[$app] = $nav_tmp[$app]; |
|
| 54 | - foreach($nav as $app) |
|
| 55 | - if(!array_key_exists($app['href'], $result)) |
|
| 51 | + foreach($nav as $app) { |
|
| 52 | + $nav_tmp[$app['href']] = $app; |
|
| 53 | + } |
|
| 54 | + foreach($order as $app) { |
|
| 55 | + $result[$app] = $nav_tmp[$app]; |
|
| 56 | + } |
|
| 57 | + foreach($nav as $app) { |
|
| 58 | + if(!array_key_exists($app['href'], $result)) |
|
| 56 | 59 | $result[$app['href']] = $app; |
| 60 | + } |
|
| 57 | 61 | return $result; |
| 58 | 62 | } |
| 59 | 63 | |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Application extends App { |
| 9 | 9 | |
| 10 | - public function __construct(array $urlParams=array()){ |
|
| 10 | + public function __construct(array $urlParams = array()) { |
|
| 11 | 11 | parent::__construct('apporder', $urlParams); |
| 12 | 12 | $container = $this->getContainer(); |
| 13 | 13 | $container->registerService('ConfigService', function($c) { |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | private $config; |
| 10 | 10 | private $appName; |
| 11 | 11 | |
| 12 | - public function __construct(IConfig $config, $appName){ |
|
| 12 | + public function __construct(IConfig $config, $appName) { |
|
| 13 | 13 | $this->config = $config; |
| 14 | 14 | $this->appName = $appName; |
| 15 | 15 | } |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | * @copyright jus 2016 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -require_once __DIR__ . '/../../../tests/bootstrap.php'; |
|
| 13 | -require_once __DIR__ . '/../appinfo/autoload.php'; |
|
| 12 | +require_once __DIR__.'/../../../tests/bootstrap.php'; |
|
| 13 | +require_once __DIR__.'/../appinfo/autoload.php'; |
|
| 14 | 14 | |
| 15 | -\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 15 | +\OC::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
| 16 | 16 | \OC_App::loadApp('apporder'); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | private $appName; |
| 20 | 20 | private $controller; |
| 21 | 21 | private $config; |
| 22 | - public function setUp (){ |
|
| 22 | + public function setUp() { |
|
| 23 | 23 | |
| 24 | 24 | parent::setUp(); |
| 25 | 25 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
| 35 | 35 | ->disableOriginalConstructor() |
| 36 | 36 | ->getMock(); |
| 37 | - $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll','add','setActiveEntry']) |
|
| 37 | + $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll', 'add', 'setActiveEntry']) |
|
| 38 | 38 | ->disableOriginalConstructor() |
| 39 | 39 | ->getMock(); |
| 40 | 40 | $this->userId = 'admin'; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public function testGetAppOrder() { |
| 104 | - $nav_system= ['/app/calendar/', '/app/tasks/']; |
|
| 104 | + $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 105 | 105 | $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
| 106 | 106 | $this->service->expects($this->once()) |
| 107 | 107 | ->method('getAppValue') |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $this->assertEquals(json_encode($nav_user), $result); |
| 116 | 116 | } |
| 117 | 117 | public function testGetAppOrderNoUser() { |
| 118 | - $nav_system= ['/app/calendar/', '/app/tasks/']; |
|
| 118 | + $nav_system = ['/app/calendar/', '/app/tasks/']; |
|
| 119 | 119 | $nav_user = ''; |
| 120 | 120 | $this->service->expects($this->once()) |
| 121 | 121 | ->method('getAppValue') |
@@ -11,111 +11,111 @@ |
||
| 11 | 11 | |
| 12 | 12 | class SettingsControllerTest extends \Test\TestCase { |
| 13 | 13 | |
| 14 | - private $container; |
|
| 15 | - private $request; |
|
| 16 | - private $service; |
|
| 17 | - private $navigationManager; |
|
| 18 | - private $userId; |
|
| 19 | - private $appName; |
|
| 20 | - private $controller; |
|
| 21 | - private $config; |
|
| 22 | - public function setUp (){ |
|
| 14 | + private $container; |
|
| 15 | + private $request; |
|
| 16 | + private $service; |
|
| 17 | + private $navigationManager; |
|
| 18 | + private $userId; |
|
| 19 | + private $appName; |
|
| 20 | + private $controller; |
|
| 21 | + private $config; |
|
| 22 | + public function setUp (){ |
|
| 23 | 23 | |
| 24 | 24 | parent::setUp(); |
| 25 | 25 | |
| 26 | 26 | $app = new Application(); |
| 27 | 27 | $this->container = $app->getContainer(); |
| 28 | 28 | $this->request = $this->getMockBuilder('OCP\IRequest') |
| 29 | - ->disableOriginalConstructor() |
|
| 30 | - ->getMock(); |
|
| 29 | + ->disableOriginalConstructor() |
|
| 30 | + ->getMock(); |
|
| 31 | 31 | $this->config = $this->getMockBuilder('OCP\IConfig') |
| 32 | - ->disableOriginalConstructor() |
|
| 33 | - ->getMock(); |
|
| 32 | + ->disableOriginalConstructor() |
|
| 33 | + ->getMock(); |
|
| 34 | 34 | $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
| 35 | - ->disableOriginalConstructor() |
|
| 36 | - ->getMock(); |
|
| 35 | + ->disableOriginalConstructor() |
|
| 36 | + ->getMock(); |
|
| 37 | 37 | $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll','add','setActiveEntry']) |
| 38 | - ->disableOriginalConstructor() |
|
| 39 | - ->getMock(); |
|
| 38 | + ->disableOriginalConstructor() |
|
| 39 | + ->getMock(); |
|
| 40 | 40 | $this->userId = 'admin'; |
| 41 | 41 | $this->appName = 'apporder'; |
| 42 | 42 | $this->controller = new \OCA\AppOrder\Controller\SettingsController( |
| 43 | - $this->appName, $this->request, $this->service, $this->navigationManager, |
|
| 44 | - $this->userId |
|
| 43 | + $this->appName, $this->request, $this->service, $this->navigationManager, |
|
| 44 | + $this->userId |
|
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function testAdminIndex() { |
|
| 49 | + public function testAdminIndex() { |
|
| 50 | 50 | $nav_custom = ['/app/calendar/', '/app/tasks/']; |
| 51 | 51 | $nav_oc = [ |
| 52 | - ['href' => '/app/files/', 'name' => 'Files'], |
|
| 53 | - ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 54 | - ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 52 | + ['href' => '/app/files/', 'name' => 'Files'], |
|
| 53 | + ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 54 | + ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 55 | 55 | ]; |
| 56 | 56 | $nav_final = [ |
| 57 | - '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] |
|
| 58 | - ]; |
|
| 57 | + '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] |
|
| 58 | + ]; |
|
| 59 | 59 | $this->service->expects($this->once()) |
| 60 | - ->method('getAppValue') |
|
| 61 | - ->with('order') |
|
| 62 | - ->will($this->returnValue(json_encode($nav_custom))); |
|
| 60 | + ->method('getAppValue') |
|
| 61 | + ->with('order') |
|
| 62 | + ->will($this->returnValue(json_encode($nav_custom))); |
|
| 63 | 63 | $this->navigationManager->expects($this->once()) |
| 64 | - ->method('getAll') |
|
| 65 | - ->will($this->returnValue($nav_oc)); |
|
| 64 | + ->method('getAll') |
|
| 65 | + ->will($this->returnValue($nav_oc)); |
|
| 66 | 66 | |
| 67 | 67 | $result = $this->controller->adminIndex(); |
| 68 | 68 | $expected = new \OCP\AppFramework\Http\TemplateResponse( |
| 69 | - $this->appName, |
|
| 70 | - 'admin', |
|
| 71 | - ["nav" => $nav_final], |
|
| 72 | - 'blank' |
|
| 69 | + $this->appName, |
|
| 70 | + 'admin', |
|
| 71 | + ["nav" => $nav_final], |
|
| 72 | + 'blank' |
|
| 73 | 73 | ); |
| 74 | 74 | $this->assertEquals($expected, $result); |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function testMatchOrder() { |
|
| 77 | + public function testMatchOrder() { |
|
| 78 | 78 | $nav = [ |
| 79 | - ['href' => '/app/files/', 'name' => 'Files'], |
|
| 80 | - ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 81 | - ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 79 | + ['href' => '/app/files/', 'name' => 'Files'], |
|
| 80 | + ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 81 | + ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 82 | 82 | ]; |
| 83 | 83 | $order = ['/app/calendar/', '/app/tasks/']; |
| 84 | 84 | $result = $this->controller->matchOrder($nav, $order); |
| 85 | 85 | $expected = [ |
| 86 | - '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 87 | - '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 88 | - '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
| 86 | + '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
| 87 | + '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
| 88 | + '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
| 89 | 89 | ]; |
| 90 | 90 | $this->assertEquals($expected, $result); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function testGetAppOrder() { |
|
| 93 | + public function testGetAppOrder() { |
|
| 94 | 94 | $nav_system= ['/app/calendar/', '/app/tasks/']; |
| 95 | 95 | $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
| 96 | 96 | $this->service->expects($this->once()) |
| 97 | - ->method('getAppValue') |
|
| 98 | - ->with('order') |
|
| 99 | - ->will($this->returnValue(json_encode($nav_system))); |
|
| 97 | + ->method('getAppValue') |
|
| 98 | + ->with('order') |
|
| 99 | + ->will($this->returnValue(json_encode($nav_system))); |
|
| 100 | 100 | $this->service->expects($this->once()) |
| 101 | - ->method('getUserValue') |
|
| 102 | - ->with('order', $this->userId) |
|
| 103 | - ->will($this->returnValue(json_encode($nav_user))); |
|
| 101 | + ->method('getUserValue') |
|
| 102 | + ->with('order', $this->userId) |
|
| 103 | + ->will($this->returnValue(json_encode($nav_user))); |
|
| 104 | 104 | $result = $this->controller->getAppOrder(); |
| 105 | 105 | $this->assertEquals(json_encode($nav_user), $result); |
| 106 | - } |
|
| 107 | - public function testGetAppOrderNoUser() { |
|
| 106 | + } |
|
| 107 | + public function testGetAppOrderNoUser() { |
|
| 108 | 108 | $nav_system= ['/app/calendar/', '/app/tasks/']; |
| 109 | 109 | $nav_user = ''; |
| 110 | 110 | $this->service->expects($this->once()) |
| 111 | - ->method('getAppValue') |
|
| 112 | - ->with('order') |
|
| 113 | - ->will($this->returnValue(json_encode($nav_system))); |
|
| 111 | + ->method('getAppValue') |
|
| 112 | + ->with('order') |
|
| 113 | + ->will($this->returnValue(json_encode($nav_system))); |
|
| 114 | 114 | $this->service->expects($this->once()) |
| 115 | - ->method('getUserValue') |
|
| 116 | - ->with('order', $this->userId) |
|
| 117 | - ->will($this->returnValue($nav_user)); |
|
| 115 | + ->method('getUserValue') |
|
| 116 | + ->with('order', $this->userId) |
|
| 117 | + ->will($this->returnValue($nav_user)); |
|
| 118 | 118 | $result = $this->controller->getAppOrder(); |
| 119 | 119 | $this->assertEquals(json_encode($nav_system), $result); |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | } |