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

IspDbtest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 77
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Bernhard Scheirle <[email protected]>
5
 * @author Christoph Wurst <[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\Autoconfig;
24
25
use OCA\Mail\Service\AutoConfig\IspDb;
26
use Test\TestCase;
27
28
class IspDbtest extends TestCase {
29
30
	private $logger;
31
32
	protected function setUp() {
33
		parent::setUp();
34
35
		$this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger')
36
			->disableOriginalConstructor()
37
			->getMock();
38
	}
39
40
	public function queryData() {
41
		return [
42
			['gmail.com'],
43
			['outlook.com'],
44
		];
45
	}
46
47
	/**
48
	 * @dataProvider queryData
49
	 *
50
	 * @param string $domain
51
	 */
52
	public function testQueryRealServers($domain) {
53
		$ispDb = new IspDb($this->logger);
54
		$result = $ispDb->query($domain);
55
		$this->assertContainsIspData($result);
56
	}
57
58
	public function fakeAutoconfigData() {
59
		return [
60
			['freenet.de', true],
61
			//['example.com', false], //should it fail?
62
		];
63
	}
64
65
	/**
66
	 * @dataProvider fakeAutoconfigData
67
	 */
68
	public function testQueryFakeAutoconfig($domain, $shouldSucceed) {
69
		$urls = [
70
			dirname(__FILE__) . '/../../resources/autoconfig-freenet.xml',
71
		];
72
		$ispDb = $this->getIspDbMock($urls);
73
74
		$result = $ispDb->query($domain);
75
76
		if ($shouldSucceed) {
77
			$this->assertContainsIspData($result);
78
		} else {
79
			$this->assertEmpty($result);
80
		}
81
	}
82
83
	private function getIspDbMock($urls) {
84
		$mock = $this->getMockBuilder('\OCA\Mail\Service\AutoConfig\IspDb')
85
			->setMethods(['getUrls'])
86
			->setConstructorArgs([$this->logger])
87
			->getMock();
88
		$mock->expects($this->once())
89
			->method('getUrls')
90
			->will($this->returnValue($urls));
91
		return $mock;
92
	}
93
94
	/**
95
	 * @todo check actual values
96
	 */
97
	private function assertContainsIspData($data) {
98
		$this->assertArrayHasKey('imap', $data);
99
		$this->assertTrue(count($data['imap']) >= 1, 'no isp imap data returned');
100
		$this->assertArrayHasKey('smtp', $data);
101
		$this->assertTrue(count($data['smtp']) >= 1, 'no isp smtp data returned');
102
	}
103
104
}
105