View source
<?php
namespace Drupal\domain_registration\Tests;
use Drupal\Tests\BrowserTestBase;
class DomainRegistrationTest extends BrowserTestBase {
public static $modules = [
'domain_registration',
];
public function testAllowExactMatch() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_ALLOW)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', 'example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@example.com',
];
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertText(t('A welcome message'), t('Thank you for applying for an account'));
}
public function testAllowEmptyPatternMatch() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_ALLOW)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', '')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@example.com',
];
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertText(t('A welcome message'), t('Thank you for applying for an account'));
}
public function testAllowWildcardMatch() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_ALLOW)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', '*.example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@subdomain.example.com',
];
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertText(t('A welcome message'), t('Thank you for applying for an account'));
}
public function testDisallowNoMatch() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_ALLOW)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', 'example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@otherexample.com',
];
$this
->drupalPostForm('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() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_DENY)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', 'example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@example.com',
];
$this
->drupalPostForm('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() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_DENY)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', '*.example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@subdomain.example.com',
];
$this
->drupalPostForm('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() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_DENY)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('message', 'foo bar baz')
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', 'example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@example.com',
];
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertText(t('foo bar baz'), t('Custom denial message was shown.'));
}
public function testDenyNoMatch() {
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('method', DOMAIN_REGISTRATION_DENY)
->save();
\Drupal::configFactory()
->getEditable('domain_registration.settings')
->set('pattern', 'example.com')
->save();
$edit = [
'name' => $this
->randomMachineName(),
'mail' => $this
->randomMachineName() . '@otherexample.com',
];
$this
->drupalPostForm('user/register', $edit, t('Create new account'));
$this
->assertText(t('A welcome message'), t('Thank you for applying for an account'));
}
}