Execute( 'SELECT 1' ); } public function tearDown(): void { Debug::text( 'Running tearDown(): ', __FILE__, __LINE__, __METHOD__, 10 ); } function testValidatorIsFloat() { TTi18n::setLocale( 'en_US' ); $validator = new Validator(); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12.9 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12.91 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12.9123 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12.91234 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12.9' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12.9123' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12.91234' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', -12.9 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', -12.91 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', -12.9123 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', -12.91234 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '123.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '30 000.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1,234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91 ' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1.234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '30 000,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91 ' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', .91 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ',91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12, 9 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12,9' ) ); TTi18n::setLocale( 'es_ES' ); if ( TTi18n::getThousandsSymbol() == '.' && TTi18n::getDecimalSymbol() == ',' ) { $this->assertEquals( true, $validator->isFloat( 'unit_test', .91 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ',91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', 12, 9 ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '12,9' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '123.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1,234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1, 234.91 ' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1 234.91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1.234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', '1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91' ) ); $this->assertEquals( true, $validator->isFloat( 'unit_test', ' 1. 234,91 ' ) ); } } function testValidatorStripNonFloat() { TTi18n::setLocale( 'en_US' ); $validator = new Validator(); $this->assertEquals( 12.9, $validator->stripNonFloat( 12.9 ) ); $this->assertEquals( 12.91, $validator->stripNonFloat( 12.91 ) ); $this->assertEquals( 12.9123, $validator->stripNonFloat( 12.9123 ) ); $this->assertEquals( 12.91234, $validator->stripNonFloat( 12.91234 ) ); $this->assertEquals( '12.9', $validator->stripNonFloat( '12.9' ) ); $this->assertEquals( '12.91', $validator->stripNonFloat( '12.91' ) ); $this->assertEquals( '12.9123', $validator->stripNonFloat( '12.9123' ) ); $this->assertEquals( '12.91234', $validator->stripNonFloat( '12.91234' ) ); $this->assertEquals( -12.9, $validator->stripNonFloat( -12.9 ) ); $this->assertEquals( -12.91, $validator->stripNonFloat( -12.91 ) ); $this->assertEquals( -12.9123, $validator->stripNonFloat( -12.9123 ) ); $this->assertEquals( -12.91234, $validator->stripNonFloat( -12.91234 ) ); $this->assertEquals( '-123.91', $validator->stripNonFloat( '-123.91' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( '123.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1234.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1 234.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1,234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( '1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91 ' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( '1 234.91' ) ); $this->assertEquals( '1.23491', $validator->stripNonFloat( '1.234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( '1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91 ' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( .91, $validator->stripNonFloat( .91 ) ); $this->assertEquals( '91', $validator->stripNonFloat( ',91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '129', $validator->stripNonFloat( '12,9' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '123.91', $validator->stripNonFloat( 'A123.91' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( 'A123.91B' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( '12A3.91' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( '123A.91' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( '123.A91' ) ); $this->assertEquals( 12.91, $validator->stripNonFloat( '12.91-' ) ); $this->assertEquals( 12.91, $validator->stripNonFloat( '12.91-ABC' ) ); $this->assertEquals( 12.91, $validator->stripNonFloat( '12.91ABC-' ) ); $this->assertEquals( 12.91, $validator->stripNonFloat( '12....91' ) ); $this->assertEquals( -12.91, $validator->stripNonFloat( '---ABC---12...ABC...91' ) ); $this->assertEquals( -12.91, $validator->stripNonFloat( '---ABC- --12. ..ABC. ..91' ) ); $this->assertEquals( '123.91', $validator->stripNonFloat( '*&#$#\'"123.JKLFDJFL91' ) ); TTi18n::setLocale( 'es_ES' ); if ( TTi18n::getThousandsSymbol() == '.' && TTi18n::getDecimalSymbol() == ',' ) { $this->assertEquals( .91, $validator->stripNonFloat( .91 ) ); $this->assertEquals( '91', $validator->stripNonFloat( ',91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '129', $validator->stripNonFloat( '12,9' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '123.91', $validator->stripNonFloat( '123.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1234.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1 234.91' ) ); $this->assertEquals( '1234.91', $validator->stripNonFloat( '1,234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( '1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( ' 1, 234.91 ' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1234.91', $validator->stripNonFloat( '1 234.91' ) ); $this->assertEquals( '1.23491', $validator->stripNonFloat( '1.234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( '1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. $this->assertEquals( '1.23491', $validator->stripNonFloat( ' 1. 234,91 ' ) ); //Always strips commas out so it doesn't work in other locales, TTi18n::parseFloat() should be called before this. } } function testValidatorStripNon32bitInteger() { $validator = new Validator(); $this->assertEquals( 0, $validator->stripNon32bitInteger( 0 ) ); $this->assertEquals( 100, $validator->stripNon32bitInteger( 100 ) ); $this->assertEquals( 1000, $validator->stripNon32bitInteger( 1000 ) ); $this->assertEquals( 2147483646, $validator->stripNon32bitInteger( 2147483646 ) ); $this->assertEquals( 0, $validator->stripNon32bitInteger( 2147483648 ) ); $this->assertEquals( -2147483647, $validator->stripNon32bitInteger( -2147483647 ) ); $this->assertEquals( 0, $validator->stripNon32bitInteger( -2147483648 ) ); } function testValidatorIsSIN() { TTi18n::setLocale( 'en_US' ); $validator = new Validator(); // // SIN - Canada // $this->assertEquals( true, $validator->isSIN( 'sin', '765 904 024', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '765904024', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', ' 765904024 ', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', ' 765-904-024 ', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', ' 765/904/024 ', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '765 904 024', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '958 752 115', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '046 454 286', null, 'CA' ) ); //As of around 2015, SINs starting with 0 apparently can now be valid rather than just fictitious purposes. //Special ones that can be entered if employee does not have one, or its unknown. Some tax documents may require this. $this->assertEquals( true, $validator->isSIN( 'sin', '999 999 999', null, 'CA' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '000 000 000', null, 'CA' ) ); //Bogus ones that should fail. $this->assertEquals( false, $validator->isSIN( 'sin', '123 456 789', null, 'CA' ) ); $this->assertEquals( false, $validator->isSIN( 'sin', '987 654 321', null, 'CA' ) ); // // SSN - US // $this->assertEquals( true, $validator->isSIN( 'sin', '662-20-0887', null, 'US' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '662/20/0887', null, 'US' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '662 20 0887', null, 'US' ) ); $this->assertEquals( true, $validator->isSIN( 'sin', '662200887', null, 'US' ) ); // Foriegn $this->assertEquals( true, $validator->isSIN( 'sin', 'ABC662200887', null, 'UK' ) ); } function testValidatorIsEmail() { TTi18n::setLocale( 'en_US' ); $validator = new Validator(); $this->assertEquals( true, $validator->isEmail( 'email', 'abc@abc.com' ) ); $this->assertEquals( true, $validator->isEmail( 'email', 'abc+123@abc.com' ) ); $this->assertEquals( true, $validator->isEmail( 'email', 'abc+123@abc.xyz.com' ) ); //Check DNS records. $this->assertEquals( true, $validator->isEmailAdvanced( 'email', 'support@timetrex.com', null, true, false ) ); $this->assertEquals( false, $validator->isEmailAdvanced( 'email', 'bogus@timetrex2323132332.com', null, true, false ) ); //Bogus domain //Check SMTP $this->assertEquals( true, $validator->isEmailAdvanced( 'email', 'support@timetrex.com', null, true, true ) ); $this->assertEquals( false, $validator->isEmailAdvanced( 'email', 'supportBOGUS@timetrex.com', null, true, true ) ); } } ?>