Completed
Push — master ( 6a7f6a...2d18f0 )
by Julius
04:59 queued 02:43
created

SettingsControllerTest::testGetAppOrderNoUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 14
cts 14
cp 1
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
crap 1
1
<?php
2
3
namespace OCA\AppOrder\Tests\Unit\Controller;
4
5
use OCP\IRequest;
6
use OCP\AppFramework\Http\DataResponse;
7
use OCP\AppFramework\Http;
8
use \OCA\AppOrder\Service;
9
use \OCA\AppOrder\AppInfo\Application;
10
use \OCA\AppOrder\Controller;
11
12
class SettingsControllerTest extends \Test\TestCase {
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 7
  public function setUp() {
23
24 7
    parent::setUp();
25
26 7
    $app = new Application();
27 7
    $this->container = $app->getContainer();
28 7
    $this->request = $this->getMockBuilder('OCP\IRequest')
29 7
      ->disableOriginalConstructor()
30 7
      ->getMock();
31 7
    $this->config = $this->getMockBuilder('OCP\IConfig')
32 7
      ->disableOriginalConstructor()
33 7
      ->getMock();
34 7
    $this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 81 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
35 7
      ->disableOriginalConstructor()
36 7
      ->getMock();
37 7
    $this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll', 'add', 'setActiveEntry'])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
38 7
      ->disableOriginalConstructor()
39 7
      ->getMock();
40 7
    $this->userId = 'admin';
41 7
    $this->appName = 'apporder';
42 7
    $this->controller = new \OCA\AppOrder\Controller\SettingsController(
43 7
      $this->appName, $this->request, $this->service, $this->navigationManager,
44 7
      $this->userId
45
    );
46
47 7
  }
48
49 1
  public function testAdminIndex() {
50 1
    $nav_custom = ['/app/calendar/', '/app/tasks/'];
51
    $nav_oc = [
52 1
      ['href' => '/app/files/', 'name' => 'Files'],
53
      ['href' => '/app/calendar/', 'name' => 'Calendar'],
54
      ['href' => '/app/tasks/', 'name' => 'Tasks'],
55
    ];
56
    $nav_final = [
57 1
      '/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0]
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 94 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
      ];
59 1
    $this->service->expects($this->once())
60 1
      ->method('getAppValue')
61 1
      ->with('order')
62 1
      ->will($this->returnValue(json_encode($nav_custom)));
63 1
    $this->navigationManager->expects($this->once())
64 1
      ->method('getAll')
65 1
      ->will($this->returnValue($nav_oc));
66
67 1
    $result = $this->controller->adminIndex(); 
68 1
    $expected = new \OCP\AppFramework\Http\TemplateResponse(
69 1
      $this->appName, 
70 1
      'admin',
71 1
      ["nav" => $nav_final],
72 1
      'blank'
73
    );
74 1
    $this->assertEquals($expected, $result);
75 1
  }
76
77 1
  public function testMatchOrder() {
78
    $nav = [
79 1
      ['href' => '/app/files/', 'name' => 'Files'],
80
      ['href' => '/app/calendar/', 'name' => 'Calendar'],
81
      ['href' => '/app/tasks/', 'name' => 'Tasks'],
82
    ];
83 1
    $order = ['/app/calendar/', '/app/tasks/'];
84 1
    $result = $this->controller->matchOrder($nav, $order);
85
    $expected = [
86 1
      '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'],
87
      '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'],
88
      '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'],
89
    ];
90 1
    $this->assertEquals($expected, $result);
91 1
  }
92
93 1
  public function testGetAppOrder() {
94 1
    $nav_system = ['/app/calendar/', '/app/tasks/'];
95 1
    $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/'];
96 1
    $this->service->expects($this->once())
97 1
      ->method('getAppValue')
98 1
      ->with('order')
99 1
      ->will($this->returnValue(json_encode($nav_system)));
100 1
    $this->service->expects($this->once())
101 1
      ->method('getUserValue')
102 1
      ->with('order', $this->userId)
103 1
      ->will($this->returnValue(json_encode($nav_user)));
104 1
    $result = $this->controller->getAppOrder();
105 1
    $this->assertEquals(json_encode($nav_user), $result);
106 1
  }
107 1
  public function testGetAppOrderNoUser() {
108 1
    $nav_system = ['/app/calendar/', '/app/tasks/'];
109 1
    $nav_user = '';
110 1
    $this->service->expects($this->once())
111 1
      ->method('getAppValue')
112 1
      ->with('order')
113 1
      ->will($this->returnValue(json_encode($nav_system)));
114 1
    $this->service->expects($this->once())
115 1
      ->method('getUserValue')
116 1
      ->with('order', $this->userId)
117 1
      ->will($this->returnValue($nav_user));
118 1
    $result = $this->controller->getAppOrder();
119 1
    $this->assertEquals(json_encode($nav_system), $result);
120 1
  }
121
122 1
  public function testGetOrder() {
123 1
    $nav_system = ['/app/calendar/', '/app/tasks/'];
124 1
    $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/'];
125 1
    $this->service->expects($this->once())
126 1
      ->method('getAppValue')
127 1
      ->with('order')
128 1
      ->will($this->returnValue(json_encode($nav_system)));
129 1
    $this->service->expects($this->once())
130 1
      ->method('getUserValue')
131 1
      ->with('order', $this->userId)
132 1
      ->will($this->returnValue(json_encode($nav_user)));
133 1
    $order = ['/app/files/', '/app/calendar/', '/app/tasks/'];
134 1
    $result = $this->controller->getOrder();
135 1
    $expected = array('status' => 'success', 'order' => json_encode($order));
136 1
    $this->assertEquals($expected, $result);
137 1
  }
138
139 1
  public function testSavePersonal() {
140 1
    $order = "RANDOMORDER";
141
    $expected = array(
142 1
      'status' => 'success',
143
      'data' => array('message'=> 'User order saved successfully.'),
144 1
      'order' => $order
145
    );
146 1
    $result = $this->controller->savePersonal($order);
147 1
    $this->assertEquals($expected, $result);
148 1
  }
149
150 1
  public function testSaveDefaultOrder() {
151 1
    $order = "RANDOMORDER";
152
    $expected = array(
153 1
      'status' => 'success',
154 1
      'order' => $order
155
    );
156 1
    $result = $this->controller->saveDefaultOrder($order);
157 1
    $this->assertEquals($expected, $result);
158 1
  }
159
}
160