Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

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