You are here

class PasswordPolicyTest in Password Policy 5

Unit tests (based on the simpletest module) for the password policy module.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$_cleanupModules property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA 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::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::clickLink 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::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPostRequest function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a druapl variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter
DrupalTestCase::tearDown function tearDown implementation, setting back switched modules etc 1
PasswordPolicyTest::get_info function
PasswordPolicyTest::testConstraints function