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

UtilTest::testMatchOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\AppOrder;
25
26
use OCA\AppOrder\Service\ConfigService;
27
use \OCA\AppOrder\Util;
28
29
class UtilTest extends \PHPUnit_Framework_TestCase {
30
31
	/**
32
	 * @var ConfigService
33
	 */
34
  private $service;
35
  private $userId;
36
  private $util;
37
  private $config;
38
  public function setUp() {
39
40
    parent::setUp();
41
42
    $this->config = $this->getMockBuilder('OCP\IConfig')
43
      ->disableOriginalConstructor()
44
      ->getMock();
45
    $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...
46
      ->disableOriginalConstructor()
47
      ->getMock();
48
    $this->userId = 'admin';
49
    $this->util = new Util($this->service, $this->userId);
50
51
  }
52
53
  public function testMatchOrder() {
54
    $nav = [
55
      ['href' => '/app/files/', 'name' => 'Files'],
56
      ['href' => '/app/calendar/', 'name' => 'Calendar'],
57
      ['href' => '/app/tasks/', 'name' => 'Tasks'],
58
    ];
59
    $order = ['/app/calendar/', '/app/tasks/'];
60
    $result = $this->util->matchOrder($nav, $order);
61
    $expected = [
62
      '/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'],
63
      '/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'],
64
      '/app/files/' => ['href' => '/app/files/', 'name' => 'Files'],
65
    ];
66
    $this->assertEquals($expected, $result);
67
  }
68
69
  public function testGetAppOrder() {
70
    $nav_system = ['/app/calendar/', '/app/tasks/'];
71
    $nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/'];
72
    $this->service->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Service\ConfigService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
      ->method('getAppValue')
74
      ->with('order')
75
      ->will($this->returnValue(json_encode($nav_system)));
76
    $this->service->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Service\ConfigService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
      ->method('getUserValue')
78
      ->with('order', $this->userId)
79
      ->will($this->returnValue(json_encode($nav_user)));
80
    $result = $this->util->getAppOrder();
81
    $this->assertEquals(json_encode($nav_user), $result);
82
  }
83
84
  public function testGetAppOrderNoUser() {
85
    $nav_system = ['/app/calendar/', '/app/tasks/'];
86
    $nav_user = '';
87
    $this->service->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Service\ConfigService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
      ->method('getAppValue')
89
      ->with('order')
90
      ->will($this->returnValue(json_encode($nav_system)));
91
    $this->service->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Service\ConfigService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
      ->method('getUserValue')
93
      ->with('order', $this->userId)
94
      ->will($this->returnValue($nav_user));
95
    $result = $this->util->getAppOrder();
96
    $this->assertEquals(json_encode($nav_system), $result);
97
  }
98
99
}
100