domain_registration.test 5.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
<?php

/**
 * @file
 * Tests for the Domain Registration Module
 */

class DomainRegistrationTest extends DrupalWebTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Domain Registration',
      'description' => 'Test if the Domain Registration module properly allows and denies specified domains',
      'group' => 'Domain Registration',
    );
  }

  public function setUp() {
    parent::setUp(array('domain_registration'));
    variable_set('user_register', USER_REGISTER_VISITORS);
    variable_set('user_email_verification', TRUE);
    variable_set('domain_registration', 'example.com');
  }

  public function testAllowExactMatch() {
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_ALLOW);
    variable_set('domain_registration', 'example.com');
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@example.com',
    );
    // Attempt to register a user with a whitelist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('A welcome message'), t('User registered successfully.'));
  }

  public function testAllowEmptyPatternMatch() {
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_ALLOW);
    variable_set('domain_registration', '');

    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@example.com',
    );
    // Attempt to register a user with a whitelist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('A welcome message'), t('User registered successfully.'));
  }

  public function testAllowWildcardMatch() {
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_ALLOW);
    variable_set('domain_registration', '*.example.com');
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@subdomain.example.com',
    );
    // Attempt to register a user with a whitelist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('A welcome message'), t('User registered successfully.'));
  }

  public function testDenyNoMatch() {
    variable_set('domain_registration', 'example.com');
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_ALLOW);
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@otherexample.com',
    );
    // Attempt to register a user with a non whitelist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('You are not allowed to register for this site.'), t('User was successfully denied registration.'));
  }

  public function testDenyExactMatch() {
    variable_set('domain_registration', 'example.com');
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_DENY);
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@example.com',
    );
    // Attempt to register a user with a blacklist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('You are not allowed to register for this site.'), t('User was successfully denied registration.'));
  }

  public function testDenyWildcardMatch() {
    variable_set('domain_registration', '*.example.com');
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_DENY);
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@subdomain.example.com',
    );
    // Attempt to register a user with blacklist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('You are not allowed to register for this site.'), t('User was successfully denied registration.'));
  }

  public function testDenyCustomMessage() {
    variable_set('domain_registration', 'example.com');
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_DENY);
    variable_set('domain_registration_message', 'foo bar baz');
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@example.com',
    );
    // Attempt to register a user with a blacklist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('foo bar baz'), t('Custom denial message was shown.'));
  }


  public function testAllowNoMatch() {
    variable_set('domain_registration', 'example.com');
    variable_set('domain_registration_method', DOMAIN_REGISTRATION_DENY);
    // Get the user data for registration.
    $edit = array(
      'name' => $this->randomName(),
      'mail' => $this->randomName() . '@otherexample.com',
    );
    // Attempt to register a user with a non blacklist email.
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertText(t('A welcome message'), t('User registered successfully.'));
  }
}