domain_registration.test in Restrict Domain Registration 7
Tests for the Domain Registration Module
File
domain_registration.testView source
<?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.'));
}
}
Classes
Name | Description |
---|---|
DomainRegistrationTest | @file Tests for the Domain Registration Module |