[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/tests/cases/validation/rules/ -> pattern.test.php (source)

   1  <?php
   2  /**
   3  * @package WACT_TESTS
   4  * @version $Id: pattern.test.php,v 1.2 2004/11/12 21:25:20 jeffmoore Exp $
   5  */
   6  
   7  require_once  'singlefield.inc.php';
   8  require_once WACT_ROOT . 'validation/rules/pattern.inc.php';
   9  
  10  class PatternRuleTestCase extends SingleFieldRuleTestCase {
  11      function PatternRuleTestCase($name = 'PatternRuleTestCase') {
  12          $this->UnitTestCase($name);
  13      }
  14      function testPatternRule() {
  15          $this->validator->addRule(new PatternRule('testfield', '/^\w+$/'));
  16          
  17          $Data =& new DataSpace();
  18          $Data->set('testfield', 'SimpletestisCool');
  19  
  20          $this->ErrorList->expectNever('addError');
  21          
  22          $this->validator->validate($Data);
  23          $this->assertTrue($this->validator->IsValid());
  24      }
  25      function testPatternRuleFailed() {
  26          $this->validator->addRule(new PatternRule('testfield', '/^\w+$/'));
  27          
  28          $Data =& new DataSpace();
  29          $Data->set('testfield', 'Simpletest is Cool!');
  30  
  31          $this->ErrorList->expectOnce('addError', array('validation', 'INVALID', array('Field'=>'testfield'), NULL));
  32          
  33          $this->validator->validate($Data);
  34          $this->assertFalse($this->validator->IsValid());
  35      }
  36  }
  37  
  38  class ExcludePatternRuleTestCase extends SingleFieldRuleTestCase {
  39      function ExcludePatternRuleTestCase($name = 'ExcludePatternRuleTestCase') {
  40          $this->UnitTestCase($name);
  41      }
  42      function testExcludePatternRule() {
  43          $this->validator->addRule(new ExcludePatternRule('testfield', '/\d/'));
  44          
  45          $Data =& new DataSpace();
  46          $Data->set('testfield', 'Error!');
  47  
  48          $this->ErrorList->expectNever('addError');
  49          
  50          $this->validator->validate($Data);
  51          $this->assertTrue($this->validator->IsValid());
  52      }
  53      function testExcludePatternRuleFailed() {
  54          $this->validator->addRule(new ExcludePatternRule('testfield', '/\d/'));
  55          
  56          $Data =& new DataSpace();
  57          $Data->set('testfield', '3rror!');
  58  
  59          $this->ErrorList->expectOnce('addError', array('validation', 'INVALID', array('Field'=>'testfield'), NULL));
  60          
  61          $this->validator->validate($Data);
  62          $this->assertFalse($this->validator->IsValid());
  63      }
  64  }
  65  
  66  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5