[pLog-svn] r3763 - in plog/trunk/class/test/tests/data/validator: .
rules
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Thu Jul 20 21:25:21 GMT 2006
Author: oscar
Date: 2006-07-20 21:25:21 +0000 (Thu, 20 Jul 2006)
New Revision: 3763
Added:
plog/trunk/class/test/tests/data/validator/rules/
plog/trunk/class/test/tests/data/validator/rules/stringrangerule_test.class.php
plog/trunk/class/test/tests/data/validator/usernamevalidator_test.class.php
Log:
test cases for the UsernameValidator and StringRangeRule classes
Added: plog/trunk/class/test/tests/data/validator/rules/stringrangerule_test.class.php
===================================================================
--- plog/trunk/class/test/tests/data/validator/rules/stringrangerule_test.class.php 2006-07-20 21:22:05 UTC (rev 3762)
+++ plog/trunk/class/test/tests/data/validator/rules/stringrangerule_test.class.php 2006-07-20 21:25:21 UTC (rev 3763)
@@ -0,0 +1,63 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/rules/stringrangerule.class.php" );
+
+ /**
+ * \ingroup Tests
+ *
+ * Test cases for the StringRangeRule class
+ */
+ class StringRangeRule_Test extends LifeTypeTestCase
+ {
+ /**
+ * creates a StringRangeRule object with a length up to 10 characters and then attempt to
+ * validate a string with 11 characters
+ */
+ function testTooLongString()
+ {
+ $r = new StringRangeRule( 0, 10 );
+
+ // check that the rule returned false
+ $this->assertFalse( $r->validate( "12345678901" ), "StringRangeRule up to 10 characters, 11-character string accepted!" );
+ // and that the error code was correct
+ $this->assertEquals( ERROR_RULE_TOO_LARGE, $r->getError(), "Error code was not ERROR_RULE_TOO_LARGE" );
+ }
+
+ /**
+ * creates a StringRangeRule object with a length of at least 5 characters and then attempt to
+ * validate a string with 13 characters
+ */
+ function testTooShortString()
+ {
+ $r = new StringRangeRule( 5, 10 );
+
+ // check that the rule returned false
+ $this->assertFalse( $r->validate( "123" ), "StringRangeRule of at least 5 characters, 3-character string accepted!" );
+ // and that the error code was correct
+ $this->assertEquals( ERROR_RULE_TOO_SMALL, $r->getError(), "Error code was not ERROR_RULE_TOO_SMALL" );
+ }
+
+ /**
+ * tests a range rule with no upper limit
+ */
+ function testUnlimitedLength()
+ {
+ $r = new StringRangeRule( 5, 0 );
+
+ // check that the rule returned false
+ $this->assertTrue( $r->validate( "123456789011231231" ), "StringRangeRule should allow unlimited length" );
+ }
+
+ /**
+ * tests a string within the defined boundaries
+ */
+ function testValidString()
+ {
+ $r = new StringRangeRule( 5, 40 );
+
+ // check that the rule returned false
+ $this->assertTrue( $r->validate( "123456789011231231" ), "StringRangeRule should allow up to 40 characters!" );
+ }
+ }
+?>
\ No newline at end of file
Added: plog/trunk/class/test/tests/data/validator/usernamevalidator_test.class.php
===================================================================
--- plog/trunk/class/test/tests/data/validator/usernamevalidator_test.class.php 2006-07-20 21:22:05 UTC (rev 3762)
+++ plog/trunk/class/test/tests/data/validator/usernamevalidator_test.class.php 2006-07-20 21:25:21 UTC (rev 3763)
@@ -0,0 +1,59 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
+
+ /**
+ * \ingroup Tests
+ *
+ * Test case for the UsernameValidator class
+ */
+ class UsernameValidator_Test extends LifeTypeTestCase
+ {
+ function setUp()
+ {
+ // create a username validator
+ $this->u = new UsernameValidator();
+ }
+
+ /**
+ * tests that an empty username does not validate
+ */
+ function testEmptyUsername()
+ {
+ $this->assertFalse( $this->u->validate( "" ), "An empty username did not generate an error!" );
+ }
+
+ /**
+ * tests a username longer than 15 characters
+ */
+ function testTooLongUsername()
+ {
+ $this->assertFalse( $this->u->validate( "12345678901234567890" ), "Username was longer than 15 characters!" );
+ }
+
+ /**
+ * tests that a forbidden username does not validate
+ */
+ function testForbiddenUsername()
+ {
+ // get the list of forbidden words, based on our configuration settings
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ $config =& Config::getConfig();
+
+ $forbiddenUsernames = $config->getValue( "forbidden_usernames" );
+ $forbiddenUsernamesArray = explode( " ", $forbiddenUsernames );
+ $tmp = array_pop( $forbiddenUsernamesArray );
+
+ $this->assertFalse( $this->u->validate( $tmp ), "A forbidden username should not be accepted as valid!" );
+ }
+
+ /**
+ * tests a valid username
+ */
+ function testValidUsername()
+ {
+ $this->assertTrue( $this->u->validate( "whatever" ), "A valid username was not accepted!" );
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list