Source for file String_Test.php
Documentation is available at String_Test.php
* Test case for the String data type
* @author John Collins <dev@alphaframework.org>
* @version $Id: String_Test.php 1341 2011-03-17 15:02:02Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* A helper string for username reg-ex validation tests
private $usernameHelper = 'Please provide a name for display on the website (only letters, numbers, and .-_ characters are allowed!).';
* A helper string for email reg-ex validation tests
private $emailHelper = 'Please provide a valid e-mail address as your username';
* A helper string for URL reg-ex validation tests
private $urlHelper = 'URLs must be in the format http://some_domain/ or left blank!';
* Called before the test functions will be executed
* this function is defined in PHPUnit_TestCase and overwritten
protected function setUp() {
* Called after the test functions are executed
* this function is defined in PHPUnit_TestCase and overwritten
* Testing the str constructor for acceptance of correct data
$this->str1 = new String('A String Value!');
$this->assertEquals('A String Value!', $this->str1->getValue(), "testing the String constructor for pass");
* Testing passing an invalid username string
$this->str1->setSize(70);
$this->str1->setHelper($this->usernameHelper);
$this->str1->setValue('invalid user.');
$this->fail('testing passing an invalid username string');
$this->assertEquals($this->usernameHelper
, 'testing passing an invalid username string');
* Testing passing a valid username string
$this->str1->setSize(70);
$this->str1->setHelper($this->usernameHelper);
$this->str1->setValue('user_name.-test123gg');
$this->fail('testing passing a valid username string: '. $e->getMessage());
* Testing passing an invalid email string
$this->str1->setSize(70);
$this->str1->setHelper($this->emailHelper);
$this->str1->setValue('invalid email');
$this->fail('testing passing an invalid email string');
$this->assertEquals($this->emailHelper
, 'testing passing an invalid email string');
* Testing passing a valid email string
$this->str1->setSize(70);
$this->str1->setHelper($this->emailHelper);
$this->str1->setValue('user@somewhere.com');
$this->str1->setValue('user@somewhere.ie');
$this->str1->setValue('user@somewhere.co.uk');
$this->str1->setValue('user@somewhere.net');
$this->str1->setValue('user@somewhere.org');
$this->str1->setValue('some.user@somewhere.com');
$this->str1->setValue('some.user@somewhere.ie');
$this->str1->setValue('some.user@somewhere.co.uk');
$this->str1->setValue('some.user@somewhere.net');
$this->str1->setValue('some.user@somewhere.org');
$this->fail('testing passing a valid email string: '. $e->getMessage());
* Testing passing an invalid URL string
$this->str1->setHelper($this->urlHelper);
$this->str1->setValue('invalid url');
$this->fail('testing passing an invalid URL string');
$this->assertEquals($this->urlHelper
, 'testing passing an invalid URL string');
* Testing passing a valid URL string
$this->str1->setHelper($this->urlHelper);
$this->str1->setValue('http://www.google.com/');
$this->str1->setValue('http://slashdot.org/');
$this->str1->setValue('http://www.yahoo.com/');
$this->str1->setValue('http://www.design-ireland.net/');
$this->str1->setValue('http://www.theregister.co.uk/');
$this->str1->setValue('http://www.bbc.co.uk/');
$this->fail('testing passing a valid URL string: '. $e->getMessage());
* Testing the setSize method to see if validation fails
$this->str1->setValue('Too many characters!');
$this->fail('testing the setSize method to see if validation fails');
$this->assertEquals('Not a valid string value!'
, 'testing the setSize method to see if validation fails');
* Testing the __toString method
$this->str1 = new String('__toString result');
$this->assertEquals('The value of __toString result', 'The value of '. $this->str1, 'testing the __toString method');
* Testing to see if the password setter/inspector is working
$this->str1->isPassword();
$this->assertTrue($this->str1->checkIsPassword(), 'testing to see if the password setter/inspector is working');
* Testing to see that isPassword makes the string required
$this->str1->isPassword();
$this->str1->setValue('');
$this->fail('testing to see that isPassword makes the string required');
$this->assertEquals('Password is required!'
, 'testing to see that isPassword makes the string required');
|