|
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 Exception; |
|
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
|
|
|
private $clientService; |
|
32
|
|
|
private $client; |
|
33
|
|
|
private $ispDb; |
|
34
|
|
|
private $config; |
|
35
|
|
|
|
|
36
|
|
|
protected function setUp() { |
|
37
|
|
|
parent::setUp(); |
|
38
|
|
|
|
|
39
|
|
|
$this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger') |
|
40
|
|
|
->disableOriginalConstructor() |
|
41
|
|
|
->getMock(); |
|
42
|
|
|
$this->client = $this->getMock('\OCP\Http\Client\IClient'); |
|
43
|
|
|
$this->clientService = $this->getMock('\OCP\Http\Client\IClientService'); |
|
44
|
|
|
$this->clientService->expects($this->any()) |
|
45
|
|
|
->method('newClient') |
|
46
|
|
|
->will($this->returnValue($this->client)); |
|
47
|
|
|
$this->config = file_get_contents(dirname(__FILE__) . '/../../resources/autoconfig-freenet.xml'); |
|
48
|
|
|
|
|
49
|
|
|
$this->ispDb = new IspDb($this->logger, $this->clientService); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testQuerySimple() { |
|
53
|
|
|
$domain = 'freenet.de'; |
|
54
|
|
|
|
|
55
|
|
|
$this->client->expects($this->any()) |
|
56
|
|
|
->method('get') |
|
57
|
|
|
->with('https://autoconfig.freenet.de/mail/config-v1.1.xml') |
|
58
|
|
|
->will($this->returnValue($this->config)); |
|
59
|
|
|
|
|
60
|
|
|
$result = $this->ispDb->query($domain); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertContainsIspData($result); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testQueryAutoconfigNotFound() { |
|
66
|
|
|
$domain = 'freenet.de'; |
|
67
|
|
|
|
|
68
|
|
|
$this->client->expects($this->any()) |
|
69
|
|
|
->method('get') |
|
70
|
|
|
->with('https://autoconfig.freenet.de/mail/config-v1.1.xml') |
|
71
|
|
|
->will($this->throwException(new Exception())); |
|
72
|
|
|
|
|
73
|
|
|
$result = $this->ispDb->query($domain); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEmpty($result); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private function assertContainsIspData($data) { |
|
79
|
|
|
$this->assertArrayHasKey('imap', $data); |
|
80
|
|
|
$this->assertTrue(count($data['imap']) >= 1, 'no isp imap data returned'); |
|
81
|
|
|
$this->assertArrayHasKey('smtp', $data); |
|
82
|
|
|
$this->assertTrue(count($data['smtp']) >= 1, 'no isp smtp data returned'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|