Support for outlook.com

This commit is contained in:
bkrukowski 2016-09-10 12:15:37 +02:00
parent 21c21f1f24
commit 7bfd541973
5 changed files with 79 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Gordianus clears aliases from email address. Email `John.Doe+alias@gmail.com` wi
* [gmail.com](https://gmail.com)
* [tlen.pl](http://tlen.pl)
* [33mail.com](https://www.33mail.com)
* [outlook.com](http://outlook.com)
## Usage

View File

@ -3,6 +3,7 @@
namespace bkrukowski\Gordianus;
use bkrukowski\Gordianus\Services\GmailCom;
use bkrukowski\Gordianus\Services\OutlookCom;
use bkrukowski\Gordianus\Services\ServiceInterface;
use bkrukowski\Gordianus\Services\TlenPl;
use bkrukowski\Gordianus\Services\Www33MailCom;
@ -12,6 +13,7 @@ class Gordianus
const SERVICE_GMAIL_COM = GmailCom::class;
const SERVICE_TLEN_PL = TlenPl::class;
const SERVICE_WWW_33MAIL_COM = Www33MailCom::class;
const SERVICE_OUTLOOK_COM = OutlookCom::class;
/**
* Constant ALL_SERVICES can contain different values depends on API version
@ -20,6 +22,7 @@ class Gordianus
self::SERVICE_GMAIL_COM,
self::SERVICE_TLEN_PL,
self::SERVICE_WWW_33MAIL_COM,
self::SERVICE_OUTLOOK_COM,
];
private $services;

View File

@ -0,0 +1,21 @@
<?php
namespace bkrukowski\Gordianus\Services;
/**
* @internal
*/
class OutlookCom implements ServiceInterface
{
public function getPrimaryEmail(string $email) : string
{
list($name, $domain) = explode('@', strtolower($email));
return explode('+', $name)[0] . '@' . $domain;
}
public function isDomainSupported(string $domain) : bool
{
return in_array(strtolower($domain), ['outlook.com', 'hotmail.com']);
}
}

View File

@ -49,6 +49,7 @@ class GordianusTest extends \PHPUnit_Framework_TestCase
[new Gordianus([]), 'John.Doe@example.com', 'john.doe@example.com'],
[new Gordianus([], true), 'John.Doe@example.com', 'John.Doe@example.com'],
[new Gordianus(Gordianus::ALL_SERVICES, true), 'John.Doe@gmail.com', 'johndoe@gmail.com'],
[new Gordianus(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
];
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace bkrukowski\Gordianus\Tests\Services;
use bkrukowski\Gordianus\Services\OutlookCom;
class OutlookComTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerIsDomainSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsDomainSupported(string $domain, bool $result)
{
$this->assertSame($result, (new OutlookCom())->isDomainSupported($domain));
}
public function providerIsDomainSupported()
{
return [
['outlook.com', true],
['Outlook.Com', true],
['hotmail.com', true],
['HotMail.COM', true],
['gmail.com', false],
['tlen.pl', false],
];
}
/**
* @dataProvider providerGetPrimaryEmail
*
* @param string $inputEmail
* @param string $expectedEmail
*/
public function testGetPrimaryEmail(string $inputEmail, string $expectedEmail)
{
$this->assertSame($expectedEmail, (new OutlookCom())->getPrimaryEmail($inputEmail));
}
public function providerGetPrimaryEmail()
{
return [
['janedoe@outlook.com', 'janedoe@outlook.com'],
['jane.doe@outlook.com', 'jane.doe@outlook.com'],
['Jane.Doe@Outlook.Com', 'jane.doe@outlook.com'],
['Jane.Doe+alias@OUTLOOK.COM', 'jane.doe@outlook.com'],
['Jane.Doe+Hotmail@hotmail.com', 'jane.doe@hotmail.com'],
];
}
}