Completed
Pull Request — master (#1638)
by Thomas
06:26
created

HtmlTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 *
7
 * Mail
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Mail\Tests\Service;
24
25
use OCA\Mail\Service\Html;
26
27
class HtmlTest extends \PHPUnit_Framework_TestCase {
28
29
	/**
30
	 * @dataProvider linkDetectionProvider
31
	 * @param $expected
32
	 * @param $text
33
	 */
34
	public function testLinkDetection($expected, $text){
35
		$urlGenerator = \OC::$server->getURLGenerator();
36
		$request = \OC::$server->getRequest();
37
		$html = new Html($urlGenerator, $request);
38
		$withLinks = $html->convertLinks($text);
39
		$this->assertSame($expected, $withLinks);
40
    }
41
42
	public function linkDetectionProvider() {
43
		return [
44
			['abc', 'abc'],
45
			['&lt;&gt;', '&lt;&gt;'],
46
			['<a href="http://google.com" rel="noreferrer" target="_blank">google.com</a>', 'http://google.com'],
47
			['<a href="https://google.com" rel="noreferrer" target="_blank">google.com</a>', 'https://google.com'],
48
			['<a href="ftp://google.com" rel="noreferrer" target="_blank">google.com</a>', 'ftp://google.com'],
49
			['<a href="http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/" rel="noreferrer" target="_blank">www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/</a>', 'http://www.themukt.com/2014/07/23/take-control-cloud-owncloud-7/'],
50
			['<a href="https://travis-ci.org/owncloud/music/builds/22037091" rel="noreferrer" target="_blank">travis-ci.org/owncloud/music/builds/22037091</a>', 'https://travis-ci.org/owncloud/music/builds/22037091'],
51
			['(<a href="ftp://google.com" rel="noreferrer" target="_blank">google.com</a>)', '(ftp://google.com)'],
52
			['<a href="https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1" rel="noreferrer" target="_blank">build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog</a>', 'https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1'],
53
			['(<a href="https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1" rel="noreferrer" target="_blank">build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog</a>)', '(https://build.opensuse.org/package/view_file/isv:ownCloud:community:7.0/owncloud/debian.changelog?expand=1)'],
54
			['<a href="http://apps.owncloud.com/content/show.php/Music?content=160485" rel="noreferrer" target="_blank">apps.owncloud.com/content/show.php/Music</a>', 'http://apps.owncloud.com/content/show.php/Music?content=160485'],
55
			['<a href="https://groups.google.com/forum/#!forum/ctpug" rel="noreferrer" target="_blank">groups.google.com/forum/</a>', 'https://groups.google.com/forum/#!forum/ctpug'],
56
//			array('<a href="http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Da/ps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser">www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser</a>', 'http://www.amazon.de/s/ref=nb_sb_noss?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Daps&field-keywords=Fax%2C+Kopierer+scanner+Laser&rh=i%3Aaps%2Ck%3AFax%5Cc+Kopierer+scanner+Laser'),
57
			['<a href="https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes" rel="noreferrer" target="_blank">ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes</a>', 'https://ci.owncloud.org/job/ownCloud-Documentation(7.0)/504/changes'],
58
			['<a href="https://communities.coverity.com/community/scan-(open-source)/content" rel="noreferrer" target="_blank">communities.coverity.com/community/scan-(open-source)/content</a>', 'https://communities.coverity.com/community/scan-(open-source)/content'],
59
			['<a href="https://ma.ellak.gr/events/5%CE%BF%CF%82-%CE%B5%CE%BA%CF%80%CE%B1%CE%B9%CE%B4%CE%B5%CF%85%CF%84%CE%B9%CE%BA%CF%8C%CF%82-%CE%BA%CF%8D%CE%BA%CE%BB%CE%BF%CF%82-%CF%83%CE%B5%CE%BC%CE%B9%CE%BD%CE%B1%CF%81%CE%AF%CF%89%CE%BD-%CE%B5-5/" rel="noreferrer" target="_blank">ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/</a>', 'https://ma.ellak.gr/events/5ος-εκπαιδευτικός-κύκλος-σεμιναρίων-ε-5/'],
60
		];
61
	}
62
63
	/**
64
	 * @dataProvider parseMailBodyProvider
65
	 * @param $expected
66
	 * @param $text
67
	 */
68
	public function testParseMailBody($expectedBody, $expectedSignature, $text){
69
		$urlGenerator = \OC::$server->getURLGenerator();
70
		$request = \OC::$server->getRequest();
71
		$html = new Html($urlGenerator, $request);
72
		list($b, $s) = $html->parseMailBody($text);
73
		$this->assertSame($expectedBody, $b);
74
		$this->assertSame($expectedSignature, $s);
75
	}
76
77
	public function parseMailBodyProvider() {
78
		return [
79
			['abc', null, 'abc'],
80
			['abc', 'def', "abc-- \r\ndef"],
81
			["abc-- \r\ndef", 'ghi', "abc-- \r\ndef-- \r\nghi"],
82
		];
83
	}
84
}
85