Spaces:
No application file
No application file
namespace Mautic\LeadBundle\Tests\Helper; | |
use Mautic\LeadBundle\Helper\IdentifyCompanyHelper; | |
use Mautic\LeadBundle\Model\CompanyModel; | |
class IdentifyCompanyHelperTest extends \PHPUnit\Framework\TestCase | |
{ | |
public function testDomainExistsRealDomain(): void | |
{ | |
$helper = new IdentifyCompanyHelper(); | |
$reflection = new \ReflectionClass(IdentifyCompanyHelper::class); | |
$method = $reflection->getMethod('domainExists'); | |
$method->setAccessible(true); | |
$result = $method->invokeArgs($helper, ['[email protected]']); | |
$this->assertTrue(is_string($result)); | |
$this->assertGreaterThan(0, strlen($result)); | |
} | |
public function testDomainExistsWithFakeDomain(): void | |
{ | |
$helper = new IdentifyCompanyHelper(); | |
$reflection = new \ReflectionClass(IdentifyCompanyHelper::class); | |
$method = $reflection->getMethod('domainExists'); | |
$method->setAccessible(true); | |
$result = $method->invokeArgs($helper, ['[email protected]']); | |
$this->assertFalse($result); | |
} | |
public function testFindCompanyByName(): void | |
{ | |
$company = [ | |
'company' => 'Mautic', | |
]; | |
$expected = [ | |
'companyname' => 'Mautic', | |
]; | |
$model = $this->getMockBuilder(CompanyModel::class) | |
->disableOriginalConstructor() | |
->getMock(); | |
$model->expects($this->once()) | |
->method('checkForDuplicateCompanies') | |
->willReturn([]); | |
$model->expects($this->any()) | |
->method('fetchCompanyFields') | |
->willReturn([['alias' => 'companyname']]); | |
$helper = new IdentifyCompanyHelper(); | |
$reflection = new \ReflectionClass(IdentifyCompanyHelper::class); | |
$method = $reflection->getMethod('findCompany'); | |
$method->setAccessible(true); | |
[$resultCompany, $entities] = $method->invokeArgs($helper, [$company, $model]); | |
$this->assertEquals($expected, $resultCompany); | |
} | |
public function testFindCompanyByNameWithValidEmail(): void | |
{ | |
$company = [ | |
'company' => 'Mautic', | |
'companyemail' => '[email protected]', | |
]; | |
$expected = [ | |
'companyname' => 'Mautic', | |
'companyemail' => '[email protected]', | |
]; | |
$model = $this->getMockBuilder(CompanyModel::class) | |
->disableOriginalConstructor() | |
->getMock(); | |
$model->expects($this->once()) | |
->method('checkForDuplicateCompanies') | |
->willReturn([]); | |
$model->expects($this->any()) | |
->method('fetchCompanyFields') | |
->willReturn([['alias' => 'companyname']]); | |
$helper = new IdentifyCompanyHelper(); | |
$reflection = new \ReflectionClass(IdentifyCompanyHelper::class); | |
$method = $reflection->getMethod('findCompany'); | |
$method->setAccessible(true); | |
[$resultCompany, $entities] = $method->invokeArgs($helper, [$company, $model]); | |
$this->assertEquals($expected, $resultCompany); | |
} | |
public function testFindCompanyByNameWithValidEmailAndCustomWebsite(): void | |
{ | |
$company = [ | |
'company' => 'Mautic', | |
'companyemail' => '[email protected]', | |
'companywebsite' => 'https://mautic.org', | |
]; | |
$expected = [ | |
'companyname' => 'Mautic', | |
'companywebsite' => 'https://mautic.org', | |
'companyemail' => '[email protected]', | |
]; | |
$model = $this->getMockBuilder(CompanyModel::class) | |
->disableOriginalConstructor() | |
->getMock(); | |
$model->expects($this->once()) | |
->method('checkForDuplicateCompanies') | |
->willReturn([]); | |
$model->expects($this->any()) | |
->method('fetchCompanyFields') | |
->willReturn([['alias' => 'companyname']]); | |
$helper = new IdentifyCompanyHelper(); | |
$reflection = new \ReflectionClass(IdentifyCompanyHelper::class); | |
$method = $reflection->getMethod('findCompany'); | |
$method->setAccessible(true); | |
[$resultCompany, $entities] = $method->invokeArgs($helper, [$company, $model]); | |
$this->assertEquals($expected, $resultCompany); | |
} | |
} | |