Source for file check.class.php
Documentation is available at check.class.php
* test case for validator class
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: check.class.php 71 2007-05-22 21:25:51Z m2mtech $
* @link http://www.ea-geier.at/
require_once('code/base/check.class.php');
* tast case for input wrapper
$this->UnitTestCase('Test Validator');
$text = " Normal Text with 'quotes', \"double quotes\", tabs \t,
new lines \n, numbers 123,22," . addslashes(" addslashes '\"\0,")
,", "\0..\37!@\177..\377");
$this->assertTrue($check->txt($text), 'text');
$text = str_repeat("test", 1024); // 4kbyte ... increase it if you want ;)
$this->assertTrue($check->txt($text), 'long text');
$this->assertFalse($check->txt($text), 'text empty');
$this->assertFalse($check->txt($text), 'tag');
$this->assertEqual($text, 'text', 'text not escaped');
$text = '<b>text</b>';
$this->assertFalse($check->txt($text), 'hidden tag');
$this->assertEqual($text, 'text', 'text escaped - hidden tag');
$this->assertTrue($check->num($num), 'integer');
$this->assertTrue($check->num($num), 'float');
$this->assertTrue($check->num($num), 'zero');
$this->assertTrue($check->num($num), 'zero float');
$this->assertTrue($check->num($num), 'float (comma notation)');
$this->assertTrue($check->num($num), 'negativ');
$this->assertFalse($check->num($num), 'letters');
$this->assertEqual($num, 22, 'number escaped');
$this->assertFalse($check->num($num), 'only letters');
$this->assertFalse($check->num($num), 'empty');
* tests email-address validator
$mail = ' Bastl@ea-geier.at ';
$this->assertTrue($check->mail($mail), 'mail');
$this->assertEqual($mail, 'bastl@ea-geier.at', 'normalized');
$this->assertFalse($check->mail($mail), 'empty');
$mail = ' <badtag> bastl@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'tags');
$mail = ' "<badtag> bastl"@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'quoted tags');
$mail = ' ba…stl@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'invalid characters');
$mail = ' why@bastl@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'multiple @');
$mail = ' bastl@ea-geier..at ';
$this->assertFalse($check->mail($mail), 'multiple .');
$mail = ' bastl@.ea-geier.at ';
$this->assertFalse($check->mail($mail), 'multiple .');
$mail = ' bastl@.ea-geier.at. ';
$this->assertFalse($check->mail($mail), 'false .');
$mail = ' bastl.@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'false .');
$mail = ' .bastl@ea-geier.at ';
$this->assertFalse($check->mail($mail), 'false .');
$mail = ' bastlea-geier.at ';
$this->assertFalse($check->mail($mail), 'missing @');
$mail = ' @ea-geier.at ';
$this->assertFalse($check->mail($mail), 'missing user');
$this->assertFalse($check->mail($mail), 'missing host');
* tests character validator
$this->assertTrue($check->abc($abc), 'string');
$this->assertFalse($check->abc($abc), 'empty');
$this->assertFalse($check->abc($abc), 'invalid string');
$this->assertTrue($check->ip($ip), 'valid ip');
$this->assertFalse($check->ip($ip), 'invalid ip');
$this->assertFalse($check->ip($ip), 'string');
$this->assertFalse($check->ip($ip), 'empty');
$mask = ' 255.255.255.0 ';
$this->assertTrue($check->ip($ip, $mask), 'mask ip');
$this->assertEqual($ip, '192.168.1.0', 'subnet');
$dsn = ' driver://user:password@server/database ';
$this->assertTrue($check->dsn($dsn));
$this->assertFalse($check->dsn($dsn));
$this->assertFalse($check->dsn($dsn));
$this->assertEqual($check->error, 'empty');
|