Add Yandex.ru and Mail.ru domains support

This commit is contained in:
gridnev 2020-02-13 13:00:21 +03:00
parent ba89a9b17b
commit 7b9128331a
6 changed files with 176 additions and 0 deletions

View File

@ -17,6 +17,8 @@ To detect multi-accounts on your website.
* [33mail.com](https://www.33mail.com)
* [outlook.com](http://outlook.com)
* [yahoo.com](http://mail.yahoo.com)
* [yandex.ru](https://yandex.ru/)
* [mail.ru](https://mail.ru/)
## Usage

23
src/Services/MailRU.php Normal file
View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class MailRU 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(), ['mail.ru']);
}
}

36
src/Services/YandexRu.php Normal file
View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class YandexRu implements ServiceInterface
{
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
{
return (new EditableEmail($email))
->removeSuffixAlias('+')
->lowerCaseLocalPartIf(true)
->setDomain($this->mapDomain($email->getDomain()));
}
public function isSupported(EmailInterface $email) : bool
{
return in_array($email->getDomain(), ['ya.ru', 'yandex.ru']);
}
protected function getDomainMapping() : array
{
return [
'ya.ru' => 'yandex.ru',
];
}
private function mapDomain(string $domain) : string
{
return $this->getDomainMapping()[$domain] ?? $domain;
}
}

View File

@ -28,6 +28,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase
return [
[new Email('jane.doe.1990@gmail.com'), '.'],
[new Email('janedoe1990@gmail.com'), '.'],
[new Email('jane.doe.1990@yandex.ru'), '.'],
[new Email('janedoe1990@yandex.ru'), '.'],
];
}
@ -53,6 +55,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase
[new Email('John.Doe+alias@gmail.com', true), '+', 'John.Doe@gmail.com'],
[new Email('JohnDoe-alias@gmail.com'), '-', 'johndoe@gmail.com'],
[new Email('JohnDoe@gmail.com'), '-', 'johndoe@gmail.com'],
[new Email('JohnDoe+alias@yandex.ru'), '+', 'johndoe@yandex.ru'],
[new Email('JohnDoe+alias@mail.ru'), '+', 'johndoe@mail.ru'],
];
}
@ -77,6 +81,10 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase
[new Email('jane.doe@foo.bar'), 'gmail.com'],
[new Email('jane.doe@foo.bar'), 'foo.bar'],
[new Email('jane.doe@gmail.com'), 'foo.bar'],
[new Email('jane.doe@yandex.ru'), 'yandex.ru'],
[new Email('jane.doe@mail.ru'), 'mail.ru'],
[new Email('jane.doe@yandex.ru'), 'foo.bar'],
[new Email('jane.doe@mail.ru'), 'foo.bar'],
];
}
@ -101,6 +109,8 @@ class EditableEmailTest extends \PHPUnit_Framework_TestCase
[new Email('jane.doe@foo.bar'), 'jane'],
[new Email('jane.doe@foo.bar'), 'john'],
[new Email('jane.doe@gmail.com'), 'jane.doe'],
[new Email('jane.doe@yandex.ru'), 'jane.doe'],
[new Email('jane.doe@mail.ru'), 'jane.doe'],
];
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Tests\Services;
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\MailRU;
class MailRUTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
*
* @param string $inputEmail
* @param string $outputEmail
*/
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail)
{
$this->assertEquals($outputEmail, (new MailRU())->getPrimaryEmail(new Email($inputEmail)));
}
public function providerGetPrimaryEmail() : array
{
return [
['foobar@MAIL.RU', 'foobar@mail.ru'],
['fOObar@MaiL.Ru', 'foobar@mail.ru'],
['foobar+alias@mail.ru', 'foobar@mail.ru'],
];
}
/**
* @dataProvider providerIsSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsSupported(string $domain, bool $result)
{
$this->assertSame($result, (new MailRU())->isSupported(new Email('Jane.Doe@' . $domain)));
}
public function providerIsSupported() : array
{
return [
['mail.ru', true],
['mail.RU', true],
['MAIL.RU', true],
['ma.il.ru', false],
];
}
}

View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Tests\Services;
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\YandexRu;
class YandexRuTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
*
* @param string $inputEmail
* @param string $outputEmail
*/
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail)
{
$this->assertEquals($outputEmail, (new YandexRu())->getPrimaryEmail(new Email($inputEmail)));
}
public function providerGetPrimaryEmail() : array
{
return [
['foobar@YANDEX.RU', 'foobar@yandex.ru'],
['fOObar@YAndEX.ru', 'foobar@yandex.ru'],
['foobar+alias@yandex.ru', 'foobar@yandex.ru'],
['JaneDoe@ya.ru', 'janedoe@yandex.ru'],
];
}
/**
* @dataProvider providerIsSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsSupported(string $domain, bool $result)
{
$this->assertSame($result, (new YandexRu())->isSupported(new Email('Jane.Doe@' . $domain)));
}
public function providerIsSupported() : array
{
return [
['yandex.ru', true],
['yandex.RU', true],
['yan.dex.ru', false],
['YANDEX.RU', true],
];
}
}