Completed
Push — master ( 38c79c...c1fbf2 )
by
unknown
23:52
created

PageControllerTest::testComposeWithCc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %
Metric Value
dl 12
loc 12
rs 9.4286
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * ownCloud - Mail
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Christoph Wurst <[email protected]>
10
 * @copyright Christoph Wurst 2015
11
 */
12
use OCP\AppFramework\Http\RedirectResponse;
13
use OCP\AppFramework\Http\TemplateResponse;
14
use Test\TestCase;
15
use OCA\Mail\Controller\PageController;
16
17
class PageControllerTest extends TestCase {
18
19
	private $appName;
20
	private $request;
21
	private $userId;
22
	private $mailAccountMapper;
23
	private $urlGenerator;
24
	private $controller;
25
26
	protected function setUp() {
27
		parent::setUp();
28
29
		$this->appName = 'mail';
30
		$this->userId = 'george';
31
		$this->request = $this->getMockBuilder('\OCP\IRequest')
32
			->disableOriginalConstructor()
33
			->getMock();
34
		$this->mailAccountMapper = $this->getMockBuilder('OCA\Mail\Db\MailAccountMapper')
35
			->disableOriginalConstructor()
36
			->getMock();
37
		$this->urlGenerator = $this->getMock('OCP\IURLGenerator');
38
		$this->controller = new PageController($this->appName, $this->request,
39
			$this->mailAccountMapper, $this->urlGenerator, $this->userId);
40
	}
41
42
	public function testIndex() {
43
		$expected = new TemplateResponse($this->appName, 'index', []);
44
		// set csp rules for ownCloud 8.1
45
		if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
46
			$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
47
			$csp->addAllowedFrameDomain('\'self\'');
48
			$expected->setContentSecurityPolicy($csp);
49
		}
50
51
		$response = $this->controller->index();
52
53
		$this->assertEquals($expected, $response);
54
	}
55
56
	public function testComposeSimple() {
57
		$address = '[email protected]';
58
		$uri = "mailto:$address";
59
60
		$expected = new RedirectResponse('#mailto=' . urlencode($address));
61
62
		$response = $this->controller->compose($uri);
63
64
		$this->assertEquals($expected, $response);
65
	}
66
67 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...
68
		$address = '[email protected]';
69
		$subject = 'hello there';
70
		$uri = "mailto:$address?subject=$subject";
71
72
		$expected = new RedirectResponse('#mailto=' . urlencode($address)
73
			. '&subject=' . urlencode($subject));
74
75
		$response = $this->controller->compose($uri);
76
77
		$this->assertEquals($expected, $response);
78
	}
79
80 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...
81
		$address = '[email protected]';
82
		$cc = '[email protected]';
83
		$uri = "mailto:$address?cc=$cc";
84
85
		$expected = new RedirectResponse('#mailto=' . urlencode($address)
86
			. '&cc=' . urlencode($cc));
87
88
		$response = $this->controller->compose($uri);
89
90
		$this->assertEquals($expected, $response);
91
	}
92
93 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...
94
		$address = '[email protected]';
95
		$bcc = '[email protected]';
96
		$uri = "mailto:$address?bcc=$bcc";
97
98
		$expected = new RedirectResponse('#mailto=' . urlencode($address)
99
			. '&bcc=' . urlencode($bcc));
100
101
		$response = $this->controller->compose($uri);
102
103
		$this->assertEquals($expected, $response);
104
	}
105
106 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...
107
		$address = '[email protected]';
108
		$body = 'Hi!\nWhat\'s up?\nAnother line';
109
		$uri = "mailto:$address?body=$body";
110
111
		$expected = new RedirectResponse('#mailto=' . urlencode($address)
112
			. '&body=' . urlencode($body));
113
114
		$response = $this->controller->compose($uri);
115
116
		$this->assertEquals($expected, $response);
117
	}
118
119
}
120