Completed
Push — master ( 4d4ad3...59ae2c )
by Christoph
19:02
created

IspDbtest::getIspDbMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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