transparent-email/tests/Services/MultiDomainTest.php

91 lines
3.0 KiB
PHP
Raw Normal View History

2016-09-10 01:41:21 +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\Services;
2016-09-10 01:41:21 +03:00
2016-09-24 13:09:20 +03:00
use bkrukowski\TransparentEmail\Emails\Email;
2016-09-10 16:13:55 +03:00
use bkrukowski\TransparentEmail\Services\MultiDomain;
2016-09-10 01:41:21 +03:00
class MultiDomainTest extends \PHPUnit_Framework_TestCase
{
/**
2016-09-24 13:09:20 +03:00
* @dataProvider providerIsSupported
2016-09-10 01:41:21 +03:00
*
* @param MultiDomain $mock
* @param string $domain
* @param bool $expected
*/
2016-09-24 13:09:20 +03:00
public function testIsSupported(MultiDomain $mock, string $domain, bool $expected)
2016-09-10 01:41:21 +03:00
{
2016-09-24 13:09:20 +03:00
$this->assertSame($expected, $mock->isSupported(new Email('Jane.Doe@' . $domain, true)));
2016-09-10 01:41:21 +03:00
}
2016-09-24 13:09:20 +03:00
public function providerIsSupported()
2016-09-10 01:41:21 +03:00
{
return [
[$this->getMultiDomainMock('foo.bar', ['foo.bar']), 'gmail.com', false],
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'gmail.com']), 'gmail.com', true],
2016-09-10 17:20:08 +03:00
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'gmail.com']), 'GMAIL.COM', true],
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'gmail.com'], true), 'GMAIL.COM', true],
2016-09-10 01:41:21 +03:00
];
}
/**
* @dataProvider providerGetPrimaryDomain
*
* @param MultiDomain $mock
* @param string $email
* @param string $expectedEmail
*/
2016-09-24 13:09:20 +03:00
public function testGetPrimaryDomain(MultiDomain $mock, string $email, string $expectedEmail) {
$this->assertEquals($expectedEmail, $mock->getPrimaryEmail(new Email($email, true)));
2016-09-10 01:41:21 +03:00
}
public function providerGetPrimaryDomain()
{
return [
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'foo.bar2']), 'name@foo.bar', 'name@foo.bar'],
2016-09-10 02:45:42 +03:00
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'foo.bar2'], true), 'Name@foo.bar', 'Name@foo.bar'],
2016-09-24 13:09:20 +03:00
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'foo.bar2'], true), 'Name@FOO.bar', 'Name@foo.bar'],
2016-09-10 01:41:21 +03:00
[$this->getMultiDomainMock('foo.bar', ['foo.bar', 'foo.bar2']), 'name@foo.bar2', 'name@foo.bar'],
];
}
2016-09-10 02:45:42 +03:00
private function getMultiDomainMock(
string $primaryDomain,
array $supportedDomains,
bool $caseSensitive = false) : MultiDomain
2016-09-10 01:41:21 +03:00
{
2016-09-10 02:45:42 +03:00
return new class ($primaryDomain, $supportedDomains, $caseSensitive) extends MultiDomain {
2016-09-10 01:41:21 +03:00
private $primaryDomain;
private $supportedDomains;
2016-09-10 02:45:42 +03:00
private $caseSensitive;
public function __construct(string $primaryDomain, array $supportedDomains, bool $caseSensitive)
2016-09-10 01:41:21 +03:00
{
$this->primaryDomain = $primaryDomain;
$this->supportedDomains = $supportedDomains;
2016-09-10 02:45:42 +03:00
$this->caseSensitive = $caseSensitive;
2016-09-10 01:41:21 +03:00
}
protected function getDomainList() : array
{
return $this->supportedDomains;
}
protected function getPrimaryDomain() : string
{
return $this->primaryDomain;
}
2016-09-10 02:45:42 +03:00
protected function isCaseSensitive() : bool
{
return $this->caseSensitive;
}
2016-09-10 01:41:21 +03:00
};
}
}