Add Icloud.com service support

This commit is contained in:
gridnev 2020-02-19 12:34:15 +03:00 committed by alexey11996
parent dc65847371
commit 2e4cd9ff47
3 changed files with 73 additions and 1 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class IcloudCom implements ServiceInterface
{
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
{
return (new EditableEmail($email))
->removeSuffixAlias('+')
->lowerCaseLocalPartIf(true);
}
public function isSupported(EmailInterface $email) : bool
{
return in_array($email->getDomain(), ['icloud.com']);
}
}

View File

@ -7,6 +7,7 @@ namespace bkrukowski\TransparentEmail;
use bkrukowski\TransparentEmail\Services\AppsGoogleCom; use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
use bkrukowski\TransparentEmail\Services\GmailCom; use bkrukowski\TransparentEmail\Services\GmailCom;
use bkrukowski\TransparentEmail\Services\MailRu; use bkrukowski\TransparentEmail\Services\MailRu;
use bkrukowski\TransparentEmail\Services\IcloudCom;
use bkrukowski\TransparentEmail\Services\OutlookCom; use bkrukowski\TransparentEmail\Services\OutlookCom;
use bkrukowski\TransparentEmail\Services\TlenPl; use bkrukowski\TransparentEmail\Services\TlenPl;
use bkrukowski\TransparentEmail\Services\Www33MailCom; use bkrukowski\TransparentEmail\Services\Www33MailCom;
@ -41,7 +42,8 @@ class TransparentEmailFactory
TlenPl::class, TlenPl::class,
AppsGoogleCom::class, AppsGoogleCom::class,
MailRu::class, MailRu::class,
YandexRu::class YandexRu::class,
IcloudCom::class
]; ];
} }
} }

View File

@ -0,0 +1,49 @@
<?php
namespace bkrukowski\TransparentEmail\Tests\Services;
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\IcloudCom;
use PHPUnit\Framework\TestCase;
class IcloudComTest extends TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
*
* @param string $inputEmail
* @param string $outputEmail
*/
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail)
{
$this->assertEquals($outputEmail, (new IcloudCom())->getPrimaryEmail(new Email($inputEmail)));
}
public function providerGetPrimaryEmail() : array
{
return [
['foobar@ICLOUD.COM', 'foobar@icloud.com'],
['foobar+alias@icloud.com', 'foobar@icloud.com'],
];
}
/**
* @dataProvider providerIsSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsSupported(string $domain, bool $result)
{
$this->assertSame($result, (new IcloudCom())->isSupported(new Email('Jane.Doe@' . $domain)));
}
public function providerIsSupported() : array
{
return [
['icloud.com', true],
['ICLOUD.COM', true],
['i.cloud.com', false],
];
}
}