Completed
Push — master ( 5e02f7...77f747 )
by
unknown
12:01
created

PageControllerTest::testIndex()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 18
nc 2
nop 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * ownCloud - Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
use OCP\AppFramework\Http\RedirectResponse;
22
use OCP\AppFramework\Http\TemplateResponse;
23
use Test\TestCase;
24
use OCA\Mail\Controller\PageController;
25
26
class PageControllerTest extends TestCase {
27
28
	private $appName;
29
	private $request;
30
	private $userId;
31
	private $mailAccountMapper;
32
	private $urlGenerator;
33
	private $config;
34
	private $controller;
35
36
	protected function setUp() {
37
		parent::setUp();
38
39
		$this->appName = 'mail';
40
		$this->userId = 'george';
41
		$this->request = $this->getMock('\OCP\IRequest');
42
		$this->mailAccountMapper = $this->getMockBuilder('OCA\Mail\Db\MailAccountMapper')
43
			->disableOriginalConstructor()
44
			->getMock();
45
		$this->urlGenerator = $this->getMock('OCP\IURLGenerator');
46
		$this->config = $this->getMock('OCP\IConfig');
47
		$this->controller = new PageController($this->appName, $this->request, $this->mailAccountMapper, $this->urlGenerator, $this->config, $this->userId);
48
	}
49
50
	public function testIndex() {
51
		$this->config->expects($this->once())
52
			->method('getSystemValue')
53
			->with('debug', false)
54
			->will($this->returnValue(true));
55
		$this->config->expects($this->once())
56
			->method('getAppValue')
57
			->with('mail', 'installed_version')
58
			->will($this->returnValue('1.2.3'));
59
60
		$expected = new TemplateResponse($this->appName, 'index', [
61
			'debug' => true,
62
			'app-version' => '1.2.3'
63
		]);
64
		// set csp rules for ownCloud 8.1
65
		if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
66
			$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
67
			$csp->addAllowedFrameDomain('\'self\'');
68
			$expected->setContentSecurityPolicy($csp);
69
		}
70
71
		$response = $this->controller->index();
72
73
		$this->assertEquals($expected, $response);
74
	}
75
76
	public function testComposeSimple() {
77
		$address = '[email protected]';
78
		$uri = "mailto:$address";
79
80
		$expected = new RedirectResponse('#mailto?to=' . urlencode($address));
81
82
		$response = $this->controller->compose($uri);
83
84
		$this->assertEquals($expected, $response);
85
	}
86
87 View Code Duplication
	public function testComposeWithSubject() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
		$address = '[email protected]';
89
		$subject = 'hello there';
90
		$uri = "mailto:$address?subject=$subject";
91
92
		$expected = new RedirectResponse('#mailto?to=' . urlencode($address)
93
			. '&subject=' . urlencode($subject));
94
95
		$response = $this->controller->compose($uri);
96
97
		$this->assertEquals($expected, $response);
98
	}
99
100 View Code Duplication
	public function testComposeWithCc() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
		$address = '[email protected]';
102
		$cc = '[email protected]';
103
		$uri = "mailto:$address?cc=$cc";
104
105
		$expected = new RedirectResponse('#mailto?to=' . urlencode($address)
106
			. '&cc=' . urlencode($cc));
107
108
		$response = $this->controller->compose($uri);
109
110
		$this->assertEquals($expected, $response);
111
	}
112
113 View Code Duplication
	public function testComposeWithBcc() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
		$address = '[email protected]';
115
		$bcc = '[email protected]';
116
		$uri = "mailto:$address?bcc=$bcc";
117
118
		$expected = new RedirectResponse('#mailto?to=' . urlencode($address)
119
			. '&bcc=' . urlencode($bcc));
120
121
		$response = $this->controller->compose($uri);
122
123
		$this->assertEquals($expected, $response);
124
	}
125
126 View Code Duplication
	public function testComposeWithMultilineBody() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
		$address = '[email protected]';
128
		$body = 'Hi!\nWhat\'s up?\nAnother line';
129
		$uri = "mailto:$address?body=$body";
130
131
		$expected = new RedirectResponse('#mailto?to=' . urlencode($address)
132
			. '&body=' . urlencode($body));
133
134
		$response = $this->controller->compose($uri);
135
136
		$this->assertEquals($expected, $response);
137
	}
138
139
}
140