diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2016-04-21 22:16:17 +0300 |
---|---|---|
committer | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2016-04-21 22:16:17 +0300 |
commit | 59ae2ce8ce87b33da3a385c900c042823225dbb3 (patch) | |
tree | 2af1294c56a0b7f53767662894ee63e76137d728 | |
parent | 4d4ad3df91b91e3f1d7494d579e012e4e1469ef2 (diff) | |
parent | efd6f9017a5a48ea29c2b3b199a614a3b4c95ec3 (diff) |
Merge pull request #1416 from owncloud/test-isbdb-xml-config
test IspDb with real xml data
-rw-r--r-- | appinfo/application.php | 8 | ||||
-rw-r--r-- | lib/service/autoconfig/ispdb.php | 24 | ||||
-rw-r--r-- | tests/resources/autoconfig-freenet.xml | 36 | ||||
-rw-r--r-- | tests/service/autoconfig/ispdbtest.php | 59 |
4 files changed, 107 insertions, 20 deletions
diff --git a/appinfo/application.php b/appinfo/application.php index b0cd5d555..bec80691c 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -1,4 +1,5 @@ <?php + /** * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Thomas Müller <thomas.mueller@tmit.eu> @@ -21,11 +22,12 @@ namespace OCA\Mail\AppInfo; -use \OCP\AppFramework\App; +use OCP\AppFramework\App; +use OCP\Util; class Application extends App { - public function __construct (array $urlParams=array()) { + public function __construct(array $urlParams = []) { parent::__construct('mail', $urlParams); $container = $this->getContainer(); @@ -42,7 +44,7 @@ class Application extends App { $container->registerParameter("userFolder", $container->getServer()->getUserFolder($user)); $container->registerParameter("testSmtp", $testSmtp); $container->registerParameter("referrer", isset($_SERVER['HTTP_REFERER']) ? : null); - $container->registerParameter("hostname", \OCP\Util::getServerHostName()); + $container->registerParameter("hostname", Util::getServerHostName()); } } diff --git a/lib/service/autoconfig/ispdb.php b/lib/service/autoconfig/ispdb.php index b3566a183..3e96c50ae 100644 --- a/lib/service/autoconfig/ispdb.php +++ b/lib/service/autoconfig/ispdb.php @@ -1,4 +1,5 @@ <?php + /** * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @@ -17,19 +18,30 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OCA\Mail\Service\AutoConfig; +use Exception; use OCA\Mail\Service\Logger; class IspDb { + /** @var Logger */ private $logger; - private $urls = array( - 'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml', - 'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml', - 'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}', - ); + /** @var string[] */ + public function getUrls() { + return [ + 'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml', + 'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml', + 'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}', + ]; + } + + /** + * @param Logger $logger + * @param string[] $ispUrls + */ public function __construct(Logger $logger) { $this->logger = $logger; } @@ -84,7 +96,7 @@ class IspDb { } $provider = []; - foreach ($this->urls as $url) { + foreach ($this->getUrls() as $url) { $url = str_replace("{DOMAIN}", $domain, $url); $this->logger->debug("IsbDb: querying <$domain> via <$url>"); diff --git a/tests/resources/autoconfig-freenet.xml b/tests/resources/autoconfig-freenet.xml new file mode 100644 index 000000000..08c620e0f --- /dev/null +++ b/tests/resources/autoconfig-freenet.xml @@ -0,0 +1,36 @@ +<clientConfig version="1.1"> + <emailProvider id="freenet.de"> + <domain>freenet.de</domain> + <displayName>Freenet Mail</displayName> + <displayShortName>Freenet</displayShortName> + <incomingServer type="imap"> + <hostname>mx.freenet.de</hostname> + <port>993</port> + <socketType>SSL</socketType> + <authentication>password-encrypted</authentication> + <username>%EMAILADDRESS%</username> + </incomingServer> + <incomingServer type="pop3"> + <hostname>mx.freenet.de</hostname> + <port>995</port> + <socketType>SSL</socketType> + <authentication>password-cleartext</authentication> + <username>%EMAILADDRESS%</username> + </incomingServer> + <outgoingServer type="smtp"> + <hostname>mx.freenet.de</hostname> + <port>587</port> + <socketType>STARTTLS</socketType> + <authentication>password-encrypted</authentication> + <username>%EMAILADDRESS%</username> + </outgoingServer> + <documentation url="http://email-hilfe.freenet.de/documents/Beitrag/15916/einstellungen-serverdaten-fuer-alle-e-mail-programme"> + <descr lang="de">Allgemeine Beschreibung der Einstellungen</descr> + <descr lang="en">Generic settings page</descr> + </documentation> + <documentation url="http://email-hilfe.freenet.de/documents/Beitrag/15808/thunderbird-e-mail-empfang-versand-einrichten-ueber-imap"> + <descr lang="de">TB 2.0 IMAP-Einstellungen</descr> + <descr lang="en">TB 2.0 IMAP settings</descr> + </documentation> + </emailProvider> +</clientConfig>
\ No newline at end of file diff --git a/tests/service/autoconfig/ispdbtest.php b/tests/service/autoconfig/ispdbtest.php index 9378b6039..a2b0e7e6e 100644 --- a/tests/service/autoconfig/ispdbtest.php +++ b/tests/service/autoconfig/ispdbtest.php @@ -22,26 +22,24 @@ namespace OCA\Mail\Tests\Service\Autoconfig; use OCA\Mail\Service\AutoConfig\IspDb; -use PHPUnit_Framework_TestCase; +use Test\TestCase; -class IspDbtest extends PHPUnit_Framework_TestCase { +class IspDbtest extends TestCase { - private $ispDb; + private $logger; protected function setUp() { parent::setUp(); - $logger = $this->getMockBuilder('\OCA\Mail\Service\Logger') + $this->logger = $this->getMockBuilder('\OCA\Mail\Service\Logger') ->disableOriginalConstructor() ->getMock(); - $this->ispDb = new IspDb($logger); } public function queryData() { return [ - ['gmail.com'], - ['outlook.com'], - ['yahoo.de'], + ['gmail.com'], + ['outlook.com'], ]; } @@ -50,12 +48,51 @@ class IspDbtest extends PHPUnit_Framework_TestCase { * * @param string $domain */ - public function testQueryGmail($domain) { - $result = $this->ispDb->query($domain); - + public function testQueryRealServers($domain) { + $ispDb = new IspDb($this->logger); + $result = $ispDb->query($domain); $this->assertContainsIspData($result); } + public function fakeAutoconfigData() { + return [ + ['freenet.de', true], + //['example.com', false], //should it fail? + ]; + } + + /** + * @dataProvider fakeAutoconfigData + */ + public function testQueryFakeAutoconfig($domain, $shouldSucceed) { + $urls = [ + dirname(__FILE__) . '/../../resources/autoconfig-freenet.xml', + ]; + $ispDb = $this->getIspDbMock($urls); + + $result = $ispDb->query($domain); + + if ($shouldSucceed) { + $this->assertContainsIspData($result); + } else { + $this->assertEmpty($result); + } + } + + private function getIspDbMock($urls) { + $mock = $this->getMockBuilder('\OCA\Mail\Service\AutoConfig\IspDb') + ->setMethods(['getUrls']) + ->setConstructorArgs([$this->logger]) + ->getMock(); + $mock->expects($this->once()) + ->method('getUrls') + ->will($this->returnValue($urls)); + return $mock; + } + + /** + * @todo check actual values + */ private function assertContainsIspData($data) { $this->assertArrayHasKey('imap', $data); $this->assertTrue(count($data['imap']) >= 1, 'no isp imap data returned'); |