Completed
Push — test-environment ( 1806a4...345bd9 )
by Julius
05:55
created

SettingsControllerTest::test()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 2
cts 2
cp 1
rs 9.6666
cc 1
eloc 1
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 4
  public function setUp (){
23
24 4
    parent::setUp();
25
26 4
    $app = new Application();
27 4
    $this->container = $app->getContainer();
28 4
    $this->request = $this->getMockBuilder('OCP\IRequest')
29 4
      ->disableOriginalConstructor()
30 4
      ->getMock();
31 4
    $this->config = $this->getMockBuilder('OCP\IConfig')
32 4
      ->disableOriginalConstructor()
33 4
      ->getMock();
34 4
    $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 4
      ->disableOriginalConstructor()
36 4
      ->getMock();
37 4
    $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 126 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 4
      ->disableOriginalConstructor()
39 4
      ->getMock();
40 4
    $this->userId = 'admin';
41 4
    $this->appName = 'apporder';
42 4
    $this->controller = new \OCA\AppOrder\Controller\SettingsController(
43 4
      $this->appName, $this->request, $this->service, $this->navigationManager,
44 4
      $this->userId
45
    );
46
47 4
  }
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