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\AppInfo\Application; |
25
|
|
|
use OCA\Mail\Service\AutoConfig\IspDb; |
26
|
|
|
use PHPUnit_Framework_TestCase; |
27
|
|
|
|
28
|
|
|
class IspDbtest extends PHPUnit_Framework_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, Application::$ispUrls); |
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 = new IspDb($this->logger, $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 assertContainsIspData($data) { |
84
|
|
|
$this->assertArrayHasKey('imap', $data); |
85
|
|
|
$this->assertTrue(count($data['imap']) >= 1, 'no isp imap data returned'); |
86
|
|
|
$this->assertArrayHasKey('smtp', $data); |
87
|
|
|
$this->assertTrue(count($data['smtp']) >= 1, 'no isp smtp data returned'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|