Alpha Framework alpha--tests
[ class tree: alpha--tests ] [ index: alpha--tests ] [ all elements ]

Source for file AlphaValidator_Test.php

Documentation is available at AlphaValidator_Test.php

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/util/helpers/AlphaValidator.inc';
  4.  
  5. /**
  6.  *
  7.  * Test case for the AlphaValidator helper class
  8.  * 
  9.  * @package alpha::tests
  10.  * @since 1.0
  11.  * @author John Collins <dev@alphaframework.org>
  12.  * @version $Id: AlphaValidator_Test.php 1341 2011-03-17 15:02:02Z johnc $
  13.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  14.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  15.  *  All rights reserved.
  16.  * 
  17.  *  <pre>
  18.  *  Redistribution and use in source and binary forms, with or
  19.  *  without modification, are permitted provided that the
  20.  *  following conditions are met:
  21.  * 
  22.  *  * Redistributions of source code must retain the above
  23.  *    copyright notice, this list of conditions and the
  24.  *    following disclaimer.
  25.  *  * Redistributions in binary form must reproduce the above
  26.  *    copyright notice, this list of conditions and the
  27.  *    following disclaimer in the documentation and/or other
  28.  *    materials provided with the distribution.
  29.  *  * Neither the name of the Alpha Framework nor the names
  30.  *    of its contributors may be used to endorse or promote
  31.  *    products derived from this software without specific
  32.  *    prior written permission.
  33.  *   
  34.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  39.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  44.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  45.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  *  </pre>
  48.  *  
  49.  */
  50. class AlphaValidator_Test extends PHPUnit_Framework_TestCase {
  51.     /**
  52.      * Validate that the provided value is a valid integer
  53.      * 
  54.      * @since 1.0
  55.      */
  56.     public function testIsInteger({
  57.         $this->assertTrue(AlphaValidator::isInteger(100));
  58.         $this->assertTrue(AlphaValidator::isInteger(-100));
  59.         $this->assertTrue(AlphaValidator::isInteger(0));
  60.         $this->assertTrue(AlphaValidator::isInteger(00000000008));
  61.         $this->assertTrue(AlphaValidator::isInteger('00000000008'));
  62.         $this->assertTrue(AlphaValidator::isInteger('100'));
  63.         $this->assertFalse(AlphaValidator::isInteger('1.1'));
  64.         $this->assertFalse(AlphaValidator::isInteger(1.1));
  65.         $this->assertFalse(AlphaValidator::isInteger('twenty'));
  66.     }
  67.  
  68.     /**
  69.      * Validate that the provided value is a valid double
  70.      * 
  71.      * @since 1.0
  72.      */
  73.     public function testIsDouble({
  74.         $this->assertTrue(AlphaValidator::isDouble(10.0));
  75.         $this->assertTrue(AlphaValidator::isDouble(-10.0));
  76.         $this->assertTrue(AlphaValidator::isDouble(0.10));
  77.         $this->assertFalse(AlphaValidator::isDouble('twenty'));
  78.         $this->assertFalse(AlphaValidator::isDouble(100));
  79.         $this->assertFalse(AlphaValidator::isDouble('100'));
  80.     }
  81.     
  82.     /**
  83.      * Validate that the provided value is a valid boolean
  84.      * 
  85.      * @since 1.0
  86.      */
  87.     public function testIsBoolean({
  88.         $this->assertTrue(AlphaValidator::isBoolean(true));
  89.         $this->assertTrue(AlphaValidator::isBoolean(1));
  90.         $this->assertTrue(AlphaValidator::isBoolean(0));
  91.         $this->assertFalse(AlphaValidator::isBoolean('test')'test');
  92.         $this->assertFalse(AlphaValidator::isBoolean(5));
  93.         $this->assertFalse(AlphaValidator::isBoolean(1.0));
  94.     }
  95.  
  96.     /**
  97.      * Validate that the provided value is a valid alphabetic string (strictly a-zA-Z)
  98.      * 
  99.      * @since 1.0
  100.      */
  101.     public function testIsAlpha({
  102.         $this->assertTrue(AlphaValidator::isAlpha('test'));
  103.         $this->assertTrue(AlphaValidator::isAlpha('Test'));
  104.         $this->assertTrue(AlphaValidator::isAlpha('TEST'));
  105.         $this->assertFalse(AlphaValidator::isAlpha('number5'));
  106.         $this->assertFalse(AlphaValidator::isAlpha('!-++#'));
  107.         $this->assertFalse(AlphaValidator::isAlpha('100'));
  108.     }
  109.  
  110.     /**
  111.      * Validate that the provided value is a valid alpha-numeric string (strictly a-zA-Z0-9)
  112.      * 
  113.      * @since 1.0
  114.      */
  115.     public function testIsAlphaNum({
  116.         $this->assertTrue(AlphaValidator::isAlphaNum('test1'));
  117.         $this->assertTrue(AlphaValidator::isAlphaNum('1Test'));
  118.         $this->assertTrue(AlphaValidator::isAlphaNum('1TEST1'));
  119.         $this->assertFalse(AlphaValidator::isAlphaNum('test value'));
  120.         $this->assertFalse(AlphaValidator::isAlphaNum('!-++#'));
  121.         $this->assertFalse(AlphaValidator::isAlphaNum('1.00'));
  122.     }
  123.  
  124.     /**
  125.      * Validate that the provided value is a valid URL
  126.      * 
  127.      * @since 1.0
  128.      */
  129.     public function testIsURL({
  130.         $this->assertTrue(AlphaValidator::isURL('http://www.alphaframework.org'));
  131.         $this->assertTrue(AlphaValidator::isURL('http://www.alphaframework.org/controller/View.php?some=value'));
  132.         $this->assertTrue(AlphaValidator::isURL('http://alphaframework.org/'));
  133.         $this->assertFalse(AlphaValidator::isURL('http://alpha framework.org/'));
  134.         $this->assertFalse(AlphaValidator::isURL('http//www.alphaframework.org'));
  135.         $this->assertFalse(AlphaValidator::isURL('http:/www.alphaframework.org'));
  136.     }
  137.  
  138.     /**
  139.      * Validate that the provided value is a valid IP address
  140.      * 
  141.      * @since 1.0
  142.      */
  143.     public function testIsIP({
  144.         $this->assertTrue(AlphaValidator::isIP('127.0.0.1'));
  145.         $this->assertTrue(AlphaValidator::isIP('254.254.254.254'));
  146.         $this->assertTrue(AlphaValidator::isIP('100.100.100.100'));
  147.         $this->assertFalse(AlphaValidator::isIP('127.0.0.1000'));
  148.         $this->assertFalse(AlphaValidator::isIP('127.0.0'));
  149.         $this->assertFalse(AlphaValidator::isIP('127.0.0.1.1'));
  150.     }
  151.  
  152.     /**
  153.      * Validate that the provided value is a valid email address
  154.      * 
  155.      * @since 1.0
  156.      */
  157.     public function testIsEmail({
  158.         $this->assertTrue(AlphaValidator::isEmail('nobody@alphaframework.org'));
  159.         $this->assertTrue(AlphaValidator::isEmail('no.body@alphaframework.com'));
  160.         $this->assertTrue(AlphaValidator::isEmail('no_body1@alphaframework.net'));
  161.         $this->assertFalse(AlphaValidator::isEmail('nobodyalphaframework.org'));
  162.         $this->assertFalse(AlphaValidator::isEmail('no body@alphaframework.org'));
  163.         $this->assertFalse(AlphaValidator::isEmail('nobody@alphaframework'));
  164.     }
  165.     
  166.     /**
  167.      * Validate that the provided value is a valid Sequence value
  168.      * 
  169.      * @since 1.0
  170.      */
  171.     public function testIsSequence({
  172.         $this->assertTrue(AlphaValidator::isSequence('BARS-150'));
  173.         $this->assertTrue(AlphaValidator::isSequence('ALPH-15'));
  174.         $this->assertTrue(AlphaValidator::isSequence('DESI-1'));
  175.         $this->assertFalse(AlphaValidator::isSequence('1'));
  176.         $this->assertFalse(AlphaValidator::isSequence('1.0'));
  177.         $this->assertFalse(AlphaValidator::isSequence('DESI8'));
  178.     }
  179. }
  180.  
  181. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:43 +0000 by phpDocumentor 1.4.3