You are here

public function SiteDisclaimerSettingsTestCase::testSiteDisclaimerBasic in Site Disclaimer 6

Same name and namespace in other branches
  1. 7 tests/site_disclaimer.test \SiteDisclaimerSettingsTestCase::testSiteDisclaimerBasic()

File

tests/site_disclaimer.test, line 89
Site Disclaimer module functionality tests.

Class

SiteDisclaimerSettingsTestCase
Test for all simple settings.

Code

public function testSiteDisclaimerBasic() {

  // Test basic settings
  $edit = array(
    'site_disclaimer_node_title' => $this->node->title,
    'site_disclaimer_checkbox_label' => $this->label,
    'site_disclaimer_title' => $this->title,
    'site_disclaimer_version_details' => $this
      ->randomName(),
  );
  $this
    ->drupalPost(TEST_SITE_DISCLAIMER_SETTINGS_PATH, $edit, t('Save configuration'));
  $this
    ->assertFieldByName('site_disclaimer_node_title', $edit['site_disclaimer_node_title'], 'Node set.');
  $this
    ->assertFieldByName('site_disclaimer_checkbox_label', $edit['site_disclaimer_checkbox_label'], 'Label name set.');
  $this
    ->assertFieldByName('site_disclaimer_title', $edit['site_disclaimer_title'], 'Title set.');
  $this
    ->drupalLogout();

  // Test registration page contains Site Disclaimer with basic settings
  $this
    ->drupalGet('user/register');
  $this
    ->assertRaw(filter_xss_admin($edit['site_disclaimer_checkbox_label']), 'Checkbox label found.');
  $this
    ->assertRaw(check_plain($edit['site_disclaimer_title']), 'Title found.');
  $this
    ->assertRaw($this->body, 'Terms node body text found.');
  $this
    ->assertNoRaw(filter_xss_admin($edit['site_disclaimer_version_details']), 'Site Disclaimer version details not found');

  // Test registration requires the [x] checkbox
  $this
    ->drupalPost('user/register', array(), t('Create new account'));

  //D7    $this->assertRaw(t('!name field is required.', array('!name' => filter_xss_admin($edit['site_disclaimer_checkbox_label']))), 'Checkbox label found, required.');
  $this
    ->assertRaw(t('You must agree with the !terms to get an account.', array(
    '!terms' => check_plain($edit['site_disclaimer_title']),
  )), 'Checkbox lable found, required.');

  // Test successful registration
  $edit = array();
  $edit['name'] = $name = $this
    ->randomName();
  $edit['mail'] = $mail = $this
    ->randomName() . '@example.com';
  $edit['I_agree'] = TRUE;
  $edit['pass[pass1]'] = $pass = $this
    ->randomName();
  $edit['pass[pass2]'] = $pass;
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));

  //    $this->assertText('Thank you for applying for an account.', 'Account creation successfull.');
  $this
    ->assertText(t('Registration successful. You are now logged in.'), t('Users are logged in after registering.'));
  $this
    ->drupalLogout();

  // Test successful login after registration (no Site Disclaimer)
  $auth = array(
    'name' => $name,
    'pass' => $pass,
  );

  // Login after administrator approval.
  $this
    ->drupalPost('user/login', $auth, t('Log in'));
  $this
    ->assertText(t('Member for'), t('User can log in.'));
  $this
    ->drupalLogout();

  // Test settings with link from [x] checkbox label
  $this
    ->drupalLogin($this->admin_user);
  $edit = array(
    'site_disclaimer_checkbox_label' => $this->label_link,
  );
  $label_raw = str_replace('@link', l($this->node->title, 'node/' . $this->node->nid), filter_xss_admin($edit['site_disclaimer_checkbox_label']));
  $this
    ->drupalPost(TEST_SITE_DISCLAIMER_SETTINGS_PATH, $edit, t('Save configuration'));
  $this
    ->assertFieldByName('site_disclaimer_checkbox_label', $edit['site_disclaimer_checkbox_label'], 'Label name with @link set.');
  $this
    ->drupalLogout();

  // Test registration page contains [x] checkbox label but no node shown
  $this
    ->drupalGet('user/register');
  $this
    ->assertRaw($label_raw, 'Checkbox label found.');
  $this
    ->assertNoRaw($this->body, 'Terms node body text not found.');

  // Test Site Disclaimer version update
  $this
    ->drupalLogin($this->admin_user);
  $edit = array(
    'site_disclaimer_checkbox_label' => $this->label_link,
    'site_disclaimer_version' => 2,
    'site_disclaimer_version_details' => $this
      ->randomName(),
  );
  $label_raw = str_replace('@link', l($this->node->title, 'node/' . $this->node->nid), filter_xss_admin($edit['site_disclaimer_checkbox_label']));
  $this
    ->drupalPost(TEST_SITE_DISCLAIMER_SETTINGS_PATH, $edit, t('Save configuration'));
  $this
    ->assertFieldByName('site_disclaimer_checkbox_label', $edit['site_disclaimer_checkbox_label'], 'Label name with @link set.');

  //debug('Inspect base_url=' . print_r($GLOBALS['base_url'], 1) . ' base_root=' . print_r($GLOBALS['base_root'], 1) );

  //debug('Inspect node->body=' . htmlentities(print_r($this->body, 1)));
  debug('Inspect site_disclaimer_allow_nodes=' . print_r(variable_get('site_disclaimer_allow_nodes', array()), 1));
  $this
    ->drupalLogout();

  // Test that a request is shown to accept new version of Site Disclaimer when an old user logs in
  $auth = array(
    'name' => $name,
    'pass' => $pass,
  );
  $this
    ->drupalPost('user/login', $auth, t('Log in'));
  $this
    ->assertNoText(t('Member for'), t('User log in incomplete.'));
  $this
    ->assertRaw(filter_xss_admin($edit['site_disclaimer_version_details']), 'Site Disclaimer version details found');
  $this
    ->assertRaw($label_raw, 'Checkbox label found.');

  // Test that user can open the linked node
  $this
    ->clickLink($this->node->title);
  $this
    ->assertRaw($this->body, 'Site Disclaimer node found');

  // Test that user can also open the node linked from Site Disclaimer node
  $this
    ->clickLink($this->node1->title);
  $this
    ->assertRaw($this->body1, 'node linked from Site Disclaimer node found');

  // Test that other pages are redirected to the Site Disclaimer page
  $this
    ->drupalGet('');
  $this
    ->assertRaw(filter_xss_admin($edit['site_disclaimer_version_details']), 'Site Disclaimer version details found');
  $this
    ->assertRaw($label_raw, 'Checkbox label found.');

  // Test accepting the new Site Disclaimer
  $edit = array(
    'I_agree' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Continue'));
  $this
    ->assertText(t('Log out'), t('User can log in.'));
  $this
    ->assertText(t('My account'), t('User can log in.'));
  $this
    ->drupalLogout();

  //@todo:

  // Test settings with quoted links from [x] checkbox label
}