2016-09-10 16:13:55 +03:00
|
|
|
<?php
|
|
|
|
|
2016-09-23 22:39:33 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-09-10 16:13:55 +03:00
|
|
|
namespace bkrukowski\TransparentEmail\Tests;
|
|
|
|
|
2016-09-24 13:09:20 +03:00
|
|
|
use bkrukowski\TransparentEmail\Emails\Email;
|
2016-09-24 13:42:00 +03:00
|
|
|
use bkrukowski\TransparentEmail\Emails\EmailInterface;
|
2016-09-23 22:29:25 +03:00
|
|
|
use bkrukowski\TransparentEmail\ServiceCollector;
|
|
|
|
use bkrukowski\TransparentEmail\ServiceCollectorInterface;
|
|
|
|
use bkrukowski\TransparentEmail\Services\TlenPl;
|
2016-09-10 16:13:55 +03:00
|
|
|
use bkrukowski\TransparentEmail\TransparentEmail;
|
|
|
|
|
|
|
|
class TransparentEmailTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerGetPrimaryEmail
|
|
|
|
*
|
2016-09-13 19:23:07 +03:00
|
|
|
* @param TransparentEmail $transparentEmail
|
2016-09-10 16:13:55 +03:00
|
|
|
* @param string $email
|
|
|
|
* @param string $expectedEmail
|
2016-09-24 13:09:20 +03:00
|
|
|
* @param bool $caseSensitive
|
2016-09-10 16:13:55 +03:00
|
|
|
*/
|
2016-09-24 13:09:20 +03:00
|
|
|
public function testGetPrimaryEmail(
|
|
|
|
TransparentEmail $transparentEmail,
|
|
|
|
string $email,
|
|
|
|
string $expectedEmail,
|
|
|
|
bool $caseSensitive = false
|
|
|
|
) {
|
|
|
|
$this->assertEquals($expectedEmail, $transparentEmail->getPrimaryEmail(new Email($email, $caseSensitive)));
|
2016-09-10 16:13:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerGetPrimaryEmail()
|
|
|
|
{
|
2016-09-23 22:29:25 +03:00
|
|
|
$emptyServiceCollector = $this->createServiceCollector();
|
|
|
|
$tlenServiceCollector = $this->createServiceCollector([TlenPl::class]);
|
|
|
|
|
2016-09-10 16:13:55 +03:00
|
|
|
return [
|
2016-09-10 16:18:48 +03:00
|
|
|
[
|
2016-09-23 22:29:25 +03:00
|
|
|
new TransparentEmail($tlenServiceCollector),
|
2016-09-10 16:18:48 +03:00
|
|
|
'john.doe+alias@gmail.com',
|
|
|
|
'john.doe+alias@gmail.com'
|
|
|
|
],
|
2016-09-10 16:13:55 +03:00
|
|
|
[new TransparentEmail(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
|
2016-09-23 22:29:25 +03:00
|
|
|
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'john.doe@example.com'],
|
2016-09-24 13:09:20 +03:00
|
|
|
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'John.Doe@example.com', true],
|
|
|
|
[new TransparentEmail(), 'John.Doe@gmail.com', 'johndoe@gmail.com', true],
|
2016-09-10 16:13:55 +03:00
|
|
|
[new TransparentEmail(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
|
|
|
|
[new TransparentEmail(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'],
|
|
|
|
];
|
|
|
|
}
|
2016-09-23 22:29:25 +03:00
|
|
|
|
2016-09-24 13:42:00 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider providerDefault
|
|
|
|
*
|
|
|
|
* @param EmailInterface $inputEmail
|
|
|
|
* @param string $expectedEmail
|
|
|
|
*/
|
|
|
|
public function testDefault(EmailInterface $inputEmail, string $expectedEmail)
|
|
|
|
{
|
|
|
|
$this->assertEquals($expectedEmail, (new TransparentEmail())->getPrimaryEmail($inputEmail));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerDefault()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[new Email('John.Doe+spam@gmail.com', true), 'johndoe@gmail.com'],
|
|
|
|
[new Email('Jane.Doe+spam@outlook.com', true), 'jane.doe@outlook.com'],
|
|
|
|
[new Email('John.Doe@tlen.pl', true), 'john.doe@o2.pl'],
|
|
|
|
[new Email('ALIAS@janedoe.33mail.com', true), 'janedoe@janedoe.33mail.com'],
|
|
|
|
[new Email('John.Doe-facebook@yahoo.com', true), 'john.doe@yahoo.com'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-09-23 22:29:25 +03:00
|
|
|
private function createServiceCollector(array $classes = []) : ServiceCollectorInterface
|
|
|
|
{
|
|
|
|
$collector = new ServiceCollector();
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
$collector->addService(new $class());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $collector;
|
|
|
|
}
|
2016-09-10 16:13:55 +03:00
|
|
|
}
|