class PasswordPolicyTest in Password Policy 5
Unit tests (based on the simpletest module) for the password policy module.
Hierarchy
- class \DrupalTestCase extends \WebTestCase
- class \PasswordPolicyTest
Expanded class hierarchy of PasswordPolicyTest
File
- tests/
password_policy.test, line 6
View source
class PasswordPolicyTest extends DrupalTestCase {
function get_info() {
return array(
'name' => 'Password policy test',
'desc' => t('Tests the core functionality of the password policy module.'),
'group' => 'Password policy tests',
);
}
function testConstraints() {
// ensure the constraints are loaded
_password_policy_load_constraint_definitions();
$this
->assertTrue(class_exists('Letter_Constraint'), 'Letter constraint does not exist.');
$this
->assertTrue(class_exists('And_Constraint'), 'And constraint does not exist.');
$this
->assertTrue(class_exists('Character_Constraint'), 'Character constraint does not exist.');
$this
->assertTrue(class_exists('Length_Constraint'), 'Length constraint does not exist.');
$this
->assertTrue(class_exists('Lowercase_Constraint'), 'Lowercase constraint does not exist.');
$this
->assertTrue(class_exists('Uppercase_Constraint'), 'Uppercase constraint does not exist.');
$this
->assertTrue(class_exists('Digit_Constraint'), 'Digit constraint does not exist.');
$this
->assertTrue(class_exists('Punctuation_Constraint'), 'Punctuation constraint does not exist.');
$this
->assertTrue(class_exists('Constraint'), 'Constraint constraint does not exist.');
$c = new Constraint(3);
$this
->assertTrue($c
->validate(''), 'Constraint test failed.');
$this
->assertTrue($c
->getName() != '', 'Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Constraint has no min value.');
$c = new Character_Constraint(4);
$this
->assertTrue(!$c
->validate('abc'), 'Character_Constraint test #1 failed.');
$this
->assertTrue($c
->validate('abcd'), 'Character_Constraint test #2 failed.');
$this
->assertTrue($c
->validate('abcd3'), 'Character_Constraint test #3 failed.');
$this
->assertTrue($c
->getName(), 'Character_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Character_Constraint has no min value.');
$c = new Letter_Constraint(3);
$this
->assertTrue($c
->validate('abc'), 'Letter_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('ab3'), 'Letter_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Letter_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Letter_Constraint has no min value.');
$c = new Uppercase_Constraint(3);
$this
->assertTrue($c
->validate('ABC'), 'Uppercase_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('AbC'), 'Uppercase_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Uppercase_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Uppercase_Constraint has no min value.');
$c = new Lowercase_Constraint(3);
$this
->assertTrue($c
->validate('abc'), 'Lowercase_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('aBc'), 'Lowercase_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Lowercase_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Lowercase_Constraint has no min value.');
$c = new Digit_Constraint(3);
$this
->assertTrue($c
->validate('123'), 'Digit_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('1b3'), 'Digit_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Digit_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Digit_Constraint has no min value.');
$c = new Punctuation_Constraint(4);
$this
->assertTrue($c
->validate('*(@"'), 'Punctuation_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate("'b(@"), 'Punctuation_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Punctuation_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Punctuation_Constraint has no min value.');
$c = new Length_Constraint(4);
$this
->assertTrue($c
->validate('....'), 'Length_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('...'), 'Length_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Length_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Length_Constraint has no min value.');
$c = new Letter_Digit_Constraint(4);
$this
->assertTrue($c
->validate('12ab'), 'Letter_Digit_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('1b3.'), 'Letter_Digit_Constraint test #2 failed.');
$this
->assertTrue($c
->getName(), 'Letter_Digit_Constraint has no name.');
$this
->assertTrue($c
->getMinimumConstraintValue() != '', 'Letter_Digit_Constraint has no min value.');
$c = new And_Constraint();
$c
->addConstraint(new Length_Constraint(4));
$c
->addConstraint(new Digit_Constraint(2));
$c
->addConstraint(new Punctuation_Constraint(2));
$this
->assertTrue(!$c
->validate('aaaa'), 'And_Constraint test #1 failed.');
$this
->assertTrue(!$c
->validate('12ab'), 'And_Constraint test #2 failed.');
$this
->assertTrue(!$c
->validate('..ab'), 'And_Constraint test #3 failed.');
$this
->assertTrue($c
->validate('12..'), 'And_Constraint test #4 failed.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
property | |||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to different objects. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value only. Otherwise a fail. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and optionally that the error text matches exactly. | ||
DrupalTestCase:: |
function | Confirms that an error has occurred and that the error text matches a Perl regular expression. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail. | ||
DrupalTestCase:: |
function | Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct. | ||
DrupalTestCase:: |
function | Confirms that no errors have occurred so far in the test method. | ||
DrupalTestCase:: |
function | Type and class mismatch test. Will pass if class name or underling type does not match the one specified. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have a different value. Otherwise a fail. | ||
DrupalTestCase:: |
function | Will trigger a pass if the two parameters have the different value or different type. | ||
DrupalTestCase:: |
function | Will be true if the value is set. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Will be true if the value is null. | ||
DrupalTestCase:: |
function | Will trigger a pass if both parameters refer to the same object. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise. | ||
DrupalTestCase:: |
function | Will trigger a pass if the raw text is found on the loaded page Fail otherwise. | ||
DrupalTestCase:: |
function | Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does… | ||
DrupalTestCase:: |
function | @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site. | ||
DrupalTestCase:: |
function | Create a role / perm combination specified by permissions | ||
DrupalTestCase:: |
function | Creates a user / role / permissions combination specified by permissions | ||
DrupalTestCase:: |
function | @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | @TODO: needs documentation | ||
DrupalTestCase:: |
function | Logs in a user with the internal browser | ||
DrupalTestCase:: |
function | Disables a drupal module | ||
DrupalTestCase:: |
function | Enables a drupal module | ||
DrupalTestCase:: |
function | Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser | ||
DrupalTestCase:: |
function | @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com> | ||
DrupalTestCase:: |
function | |||
DrupalTestCase:: |
function | Set a druapl variable and keep track of the changes for tearDown() | ||
DrupalTestCase:: |
function | Generates a random string, to be used as name or whatever | ||
DrupalTestCase:: |
function | Just some info for the reporter | ||
DrupalTestCase:: |
function | tearDown implementation, setting back switched modules etc | 1 | |
PasswordPolicyTest:: |
function | |||
PasswordPolicyTest:: |
function |