ea-Geiertest
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file check.class.php

Documentation is available at check.class.php

  1. <?php
  2. /**
  3.  * test case for validator class
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage test
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: check.class.php 71 2007-05-22 21:25:51Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * class to be tested
  29.  */
  30. require_once('code/base/check.class.php');
  31.  
  32. /**
  33.  * tast case for input wrapper
  34.  *
  35.  * @package       ea-Geier
  36.  */
  37. class TestValidator extends UnitTestCase {
  38.     
  39.     /**
  40.      * constructor
  41.      */
  42.     function TestValidator({
  43.         $this->UnitTestCase('Test Validator');
  44.     }
  45.  
  46.     /**
  47.      * tests text validator
  48.      *
  49.      * checks
  50.      * - text,
  51.      * - long text,
  52.      * - tags,
  53.      * - hidden tags
  54.      */
  55.     function testTxt({
  56.         $check new eaCheck();
  57.         $text " Normal Text with 'quotes', \"double quotes\", tabs \t, 
  58.             new lines \n, numbers 123,22," addslashes(" addslashes '\"\0,")
  59.             . addcslashes(" addcslashes \0\1    
  60.             ,""\0..\37!@\177..\377");
  61.         $this->assertTrue($check->txt($text)'text');
  62.         $text str_repeat("test"1024)// 4kbyte ... increase it if you want ;)
  63.         $this->assertTrue($check->txt($text)'long text');
  64.         $text ' ';
  65.         $this->assertFalse($check->txt($text)'text empty');
  66.         $text '<b>text</b>';
  67.         $this->assertFalse($check->txt($text)'tag');
  68.         $this->assertEqual($text'text''text not escaped');
  69.         $text '&lt;b&gt;text&lt;/b&gt';
  70.         $this->assertFalse($check->txt($text)'hidden tag');
  71.         $this->assertEqual($text'text''text escaped - hidden tag');
  72.     }
  73.  
  74.     /**
  75.      * tests number validator
  76.      *
  77.      * checks
  78.      * - integer,
  79.      * - float,
  80.      * - zero,
  81.      * - zero float,
  82.      * - comma notation,
  83.      * - negative,
  84.      * - wrong format
  85.      */
  86.     function testNum({
  87.         $check new eaCheck();
  88.         $num ' 10 ';
  89.         $this->assertTrue($check->num($num)'integer');
  90.         $num ' 10.10 ';
  91.         $this->assertTrue($check->num($num)'float');
  92.         $num ' 0 ';
  93.         $this->assertTrue($check->num($num)'zero');
  94.         $num ' 0.000 ';
  95.         $this->assertTrue($check->num($num)'zero float');
  96.         $num ' 12,34 ';
  97.         $this->assertTrue($check->num($num)'float (comma notation)');
  98.         $num ' -12.34 ';
  99.         $this->assertTrue($check->num($num)'negativ');
  100.         $num ' ab22ddc ';
  101.         $this->assertFalse($check->num($num)'letters');
  102.         $this->assertEqual($num22'number escaped');        
  103.         $num ' abddc ';
  104.         $this->assertFalse($check->num($num)'only letters');
  105.         $num ' ';
  106.         $this->assertFalse($check->num($num)'empty');
  107.     }
  108.  
  109.     /**
  110.      * tests email-address validator
  111.      *
  112.      * checks
  113.      * - valid mail,
  114.      * - short mail,
  115.      * - tags,
  116.      * - empty, tags,
  117.      * - invalid characters,
  118.      * - missing @,
  119.      * - multiple @,
  120.      * - multiple .,
  121.      * - false .,
  122.      * - missing user,
  123.      * - missing host
  124.      */
  125.     function testMail({
  126.         $check new eaCheck();
  127.         $mail ' Bastl@ea-geier.at ';
  128.         $this->assertTrue($check->mail($mail)'mail');
  129.         $this->assertEqual($mail'bastl@ea-geier.at''normalized');
  130.         $mail ' ';
  131.         $this->assertFalse($check->mail($mail)'empty');
  132.         $mail ' <badtag> bastl@ea-geier.at ';
  133.         $this->assertFalse($check->mail($mail)'tags');
  134.         $mail ' "<badtag> bastl"@ea-geier.at ';
  135.         $this->assertFalse($check->mail($mail)'quoted tags');
  136.         $mail ' ba…stl@ea-geier.at ';
  137.         $this->assertFalse($check->mail($mail)'invalid characters');
  138.         $mail ' why@bastl@ea-geier.at ';
  139.         $this->assertFalse($check->mail($mail)'multiple @');
  140.         $mail ' bastl@ea-geier..at ';
  141.         $this->assertFalse($check->mail($mail)'multiple .');
  142.         $mail ' bastl@.ea-geier.at ';
  143.         $this->assertFalse($check->mail($mail)'multiple .');
  144.         $mail ' bastl@.ea-geier.at. ';
  145.         $this->assertFalse($check->mail($mail)'false .');
  146.         $mail ' bastl.@ea-geier.at ';
  147.         $this->assertFalse($check->mail($mail)'false .');
  148.         $mail ' .bastl@ea-geier.at ';
  149.         $this->assertFalse($check->mail($mail)'false .');
  150.         $mail ' bastlea-geier.at ';
  151.         $this->assertFalse($check->mail($mail)'missing @');
  152.         $mail ' @ea-geier.at ';
  153.         $this->assertFalse($check->mail($mail)'missing user');
  154.         $mail ' bastl@ ';
  155.         $this->assertFalse($check->mail($mail)'missing host');
  156.     }
  157.     
  158.     /**
  159.      * tests character validator
  160.      *
  161.      * checks
  162.      * - valid string,
  163.      * - invalid string,
  164.      * - empty
  165.      */
  166.     function testAbc({
  167.         $check new eaCheck();
  168.         $abc ' aBc ';
  169.         $this->assertTrue($check->abc($abc)'string');
  170.         $abc ' ';
  171.         $this->assertFalse($check->abc($abc)'empty');
  172.         $mail ' x@x.y ';
  173.         $this->assertFalse($check->abc($abc)'invalid string');
  174.     }
  175.  
  176.     /**
  177.      * tests ip validator
  178.      *
  179.      * checks
  180.      * - valid string,
  181.      * - invalid string,
  182.      * - empty
  183.      */
  184.     function testIP({
  185.         $check new eaCheck();
  186.         $ip ' 192.168.1.1 ';
  187.         $this->assertTrue($check->ip($ip)'valid ip');
  188.         $ip ' 192.168.1.266 ';
  189.         $this->assertFalse($check->ip($ip)'invalid ip');
  190.         $ip ' bastl ';
  191.         $this->assertFalse($check->ip($ip)'string');
  192.         $ip ' ';
  193.         $this->assertFalse($check->ip($ip)'empty');
  194.         $ip ' 192.168.1.1 ';
  195.         $mask ' 255.255.255.0 ';
  196.         $this->assertTrue($check->ip($ip$mask)'mask ip');
  197.         $this->assertEqual($ip'192.168.1.0''subnet');        
  198.     }
  199.  
  200.     /**
  201.      * tests dsn validator
  202.      *
  203.      * checks
  204.      * - valid string,
  205.      * - invalid string,
  206.      * - empty
  207.      */
  208.     function testDSN({
  209.         $check new eaCheck();
  210.  
  211.         // valid dsn
  212.         $dsn ' driver://user:password@server/database ';
  213.         $this->assertTrue($check->dsn($dsn));
  214.         
  215.         // invalid dsn
  216.         $dsn ' dummy ';
  217.         $this->assertFalse($check->dsn($dsn));
  218.         
  219.         // empty
  220.         $dsn '  ';
  221.         $this->assertFalse($check->dsn($dsn));
  222.         $this->assertEqual($check->error'empty');
  223.     }
  224.  
  225. }
  226. ?>

Documentation generated on Sun, 09 Sep 2007 17:08:06 +0200 by phpDocumentor 1.3.1