mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 04:07:07 +09:00
* Fix validateAndSanitizeEmail for international And write tests to prove it works as intended * Update FOSS_Tools.php * Update tests * Update FOSS_ToolsTest.php * This should fix it * Disabled test * Require intl polyfill
50 lines
1.5 KiB
Plaintext
50 lines
1.5 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* FOSSBilling tools tests
|
|
*/
|
|
class FOSS_ToolsTest extends PHPUnit\Framework\TestCase
|
|
{
|
|
public function testValidateAndSanitizeEmail()
|
|
{
|
|
$testEmail = 'example@example.com';
|
|
|
|
$toolsMock = $this->getMockBuilder('\Box_Tools')->getMock();
|
|
$toolsMock->expects($this->atLeastOnce())->method('validateAndSanitizeEmail');
|
|
|
|
$di = new \Box_Di();
|
|
$di['tools'] = $toolsMock;
|
|
|
|
$result = $this->di['tools']->validateAndSanitizeEmail($testEmail, false);
|
|
$this->assertEquals($testEmail, $result);
|
|
}
|
|
|
|
public function testValidateAndSanitizeEmailID()
|
|
{
|
|
$testEmail = 'example@example-tést.eu';
|
|
|
|
$toolsMock = $this->getMockBuilder('\Box_Tools')->getMock();
|
|
$toolsMock->expects($this->atLeastOnce())->method('validateAndSanitizeEmail');
|
|
|
|
$di = new \Box_Di();
|
|
$di['tools'] = $toolsMock;
|
|
|
|
$result = $this->di['tools']->validateAndSanitizeEmail($testEmail, false);
|
|
$this->assertEquals($testEmail, $result);
|
|
}
|
|
|
|
public function testValidateAndSanitizeEmailInvalid()
|
|
{
|
|
$testEmail = '<a href="http://somethingnotgood.com">Totally an email</a>"';
|
|
|
|
$toolsMock = $this->getMockBuilder('\Box_Tools')->getMock();
|
|
$toolsMock->expects($this->atLeastOnce())->method('validateAndSanitizeEmail');
|
|
|
|
$di = new \Box_Di();
|
|
$di['tools'] = $toolsMock;
|
|
|
|
$result = $this->di['tools']->validateAndSanitizeEmail($testEmail, false);
|
|
$this->assertFalse($result);
|
|
}
|
|
}
|