Completed
Push — master ( 3d91ac...a833ad )
by Julius
13s
created

SettingsControllerTest::testGetAppOrderNoUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 13
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SettingsControllerTest::testSaveDefaultOrder() 0 9 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
  public function setUp() {
23
24
    parent::setUp();
25
26
    $app = new \OCA\AppOrder\AppInfo\Application();
27
    $this->container = $app->getContainer();
28
    $this->request = $this->getMockBuilder('OCP\IRequest')
29
      ->disableOriginalConstructor()
30
      ->getMock();
31
    $this->config = $this->getMockBuilder('OCP\IConfig')
32
      ->disableOriginalConstructor()
33
      ->getMock();
34
    $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
      ->disableOriginalConstructor()
36
      ->getMock();
37
    $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
      ->disableOriginalConstructor()
39
      ->getMock();
40
41
    $this->userId = 'admin';
42
    $this->appName = 'apporder';
43
	  $this->util = new \OCA\AppOrder\Util($this->service, $this->userId);
44
    $this->controller = new \OCA\AppOrder\Controller\SettingsController(
45
      $this->appName, $this->request, $this->service, $this->navigationManager, $this->util,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 92 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...
46
      $this->userId
47
    );
48
49
  }
50
51
  public function testAdminIndex() {
52
    $nav_custom = ['/app/calendar/', '/app/tasks/'];
53
    $nav_oc = [
54
      ['href' => '/app/files/', 'name' => 'Files'],
55
      ['href' => '/app/calendar/', 'name' => 'Calendar'],
56
      ['href' => '/app/tasks/', 'name' => 'Tasks'],
57
    ];
58
    $nav_final = [
59
      '/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...
60
      ];
61
    $this->service->expects($this->once())
62
      ->method('getAppValue')
63
      ->with('order')
64
      ->will($this->returnValue(json_encode($nav_custom)));
65
    $this->navigationManager->expects($this->once())
66
      ->method('getAll')
67
      ->will($this->returnValue($nav_oc));
68
69
    $result = $this->controller->adminIndex(); 
70
    $expected = new \OCP\AppFramework\Http\TemplateResponse(
71
      $this->appName, 
72
      'admin',
73
      ["nav" => $nav_final],
74
      'blank'
75
    );
76
    $this->assertEquals($expected, $result);
77
  }
78
79
80
  public function testGetOrder() {
81
    $nav_system = ['/app/calendar/', '/app/tasks/'];
82
    $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/'];
83
    $this->service->expects($this->once())
84
      ->method('getAppValue')
85
      ->with('order')
86
      ->will($this->returnValue(json_encode($nav_system)));
87
    $this->service->expects($this->once())
88
      ->method('getUserValue')
89
      ->with('order', $this->userId)
90
      ->will($this->returnValue(json_encode($nav_user)));
91
    $order = ['/app/files/', '/app/calendar/', '/app/tasks/'];
92
    $result = $this->controller->getOrder();
93
    $expected = array('status' => 'success', 'order' => json_encode($order));
94
    $this->assertEquals($expected, $result);
95
  }
96
97
  public function testSavePersonal() {
98
    $order = "RANDOMORDER";
99
    $expected = array(
100
      'status' => 'success',
101
      'data' => array('message'=> 'User order saved successfully.'),
102
      'order' => $order
103
    );
104
    $result = $this->controller->savePersonal($order);
105
    $this->assertEquals($expected, $result);
106
  }
107
108
  public function testSaveDefaultOrder() {
109
    $order = "RANDOMORDER";
110
    $expected = array(
111
      'status' => 'success',
112
      'order' => $order
113
    );
114
    $result = $this->controller->saveDefaultOrder($order);
115
    $this->assertEquals($expected, $result);
116
  }
117
}
118