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

AppControllerTest::testIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
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\Tests\Unit\Controller;
25
26
use OCP\IRequest;
27
use OCP\AppFramework\Http\DataResponse;
28
use OCP\AppFramework\Http;
29
use \OCA\AppOrder\Service;
30
use \OCA\AppOrder\AppInfo\Application;
31
use \OCA\AppOrder\Controller;
32
use OCA\AppOrder\Controller\AppController;
33
34
class AppControllerTest extends \Test\TestCase {
35
36
	private $container;
37
	private $request;
38
	private $service;
39
	private $urlGenerator;
40
	private $userId;
41
	private $appName;
42
	/**
43
	 * @var AppController
44
	 */
45
	private $controller;
46
	private $config;
47
	private $util;
48
49
	public function setUp() {
50
51
		parent::setUp();
52
53
		$app = new \OCA\AppOrder\AppInfo\Application();
54
		$this->container = $app->getContainer();
55
		$this->request = $this->getMockBuilder('OCP\IRequest')
56
			->disableOriginalConstructor()
57
			->getMock();
58
		$this->config = $this->getMockBuilder('OCP\IConfig')
59
			->disableOriginalConstructor()
60
			->getMock();
61
		$this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService')
62
			->disableOriginalConstructor()
63
			->getMock();
64
		$this->urlGenerator = \OC::$server->getURLGenerator();
65
		$this->util = $this->getMockBuilder('\OCA\AppOrder\Util')->disableOriginalConstructor()->getMock();
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 101 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...
66
67
		$this->userId = 'admin';
68
		$this->appName = 'apporder';
69
		$this->controller = new AppController(
70
			$this->appName, $this->request, $this->service, $this->urlGenerator, $this->util,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 84 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...
71
			$this->userId
72
		);
73
74
	}
75
76
	public function testIndex() {
77
  		$this->util->expects($this->once())
78
			->method('getAppOrder')
79
			->willReturn(
80
				json_encode(['/index.php/foo/bar', '/index.php/bar/foo'])
81
			);
82
		$expected = new Http\RedirectResponse('/index.php/foo/bar');
83
		$result = $this->controller->index();
84
		$this->assertEquals($expected, $result);
85
	}
86
87
	public function testIndexEmpty() {
88
		$this->util->expects($this->once())
89
			->method('getAppOrder')
90
			->willReturn("");
91
		$result = $this->controller->index();
92
93
		$expected = new Http\RedirectResponse('http://localhost/index.php/apps/files/');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 82 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...
94
		$this->assertEquals($expected, $result);
95
	}
96
97
98
}
99