View source
<?php
define('TEST_SITE_DISCLAIMER_SETTINGS_PATH', 'admin/config/people/site_disclaimer');
class SiteDisclaimerWebTestCase extends DrupalWebTestCase {
protected $admin_user;
protected $node;
protected $node1;
protected $label;
protected $label_link;
protected $label_link_titles;
protected $title;
protected $body;
protected $body1;
protected $xss;
public function setUp() {
$this->label = $this
->testXssString();
$this->label_link = $this
->testXssString() . ' @link ' . $this
->testXssString();
$this->title = $this
->testXssString();
$this->body1 = $this
->randomName();
parent::setUp('site_disclaimer');
variable_set('user_email_verification', FALSE);
variable_set('user_register', USER_REGISTER_VISITORS);
$this->admin_user = $this
->drupalCreateUser(array(
'administer site disclaimer',
));
$this
->drupalLogin($this->admin_user);
$this->node1 = $this
->drupalCreateNode(array(
'type' => 'page',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => $this->body1,
),
),
),
));
$this->label_link_titles = $this
->testXssString() . ' @"' . $this->node1->title . '" ';
$this->body = $this
->randomName() . ' ' . l($this->node1->title, 'node/' . $this->node1->nid, array(
'absolute' => TRUE,
)) . ' ' . $this
->randomName();
$this->node = $this
->drupalCreateNode(array(
'type' => 'page',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => $this->body,
),
),
),
));
}
private function testXssString() {
return '<a href="/' . $this
->randomString() . '">' . $this
->randomString() . '</a><script>alert("' . $this
->randomString() . '");</script>';
}
}
class SiteDisclaimerSettingsTestCase extends SiteDisclaimerWebTestCase {
public static function getInfo() {
return array(
'name' => 'Site Disclaimer Basic',
'description' => 'Basic functionality tests.',
'group' => 'Site Disclaimer',
);
}
public function testSiteDisclaimerBasic() {
$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();
$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');
$this
->drupalPost('user/register', array(), t('Create new account'));
$this
->assertRaw(t('!name field is required.', array(
'!name' => filter_xss_admin($edit['site_disclaimer_checkbox_label']),
)), 'Checkbox label found, required.');
$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(t('Registration successful. You are now logged in.'), t('Users are logged in after registering.'));
$this
->drupalLogout();
$auth = array(
'name' => $name,
'pass' => $pass,
);
$this
->drupalPost('user/login', $auth, t('Log in'));
$this
->assertText(t('Member for'), t('User can log in.'));
$this
->drupalLogout();
$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();
$this
->drupalGet('user/register');
$this
->assertRaw($label_raw, 'Checkbox label found.');
$this
->assertNoRaw($this->body, 'Terms node body text not found.');
$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 site_disclaimer_allow_nodes=' . print_r(variable_get('site_disclaimer_allow_nodes', array()), 1));
$this
->drupalLogout();
$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.');
$this
->clickLink($this->node->title);
$this
->assertRaw($this->body, 'Site Disclaimer node found');
$this
->clickLink($this->node1->title);
$this
->assertRaw($this->body1, 'node linked from Site Disclaimer node found');
$this
->drupalGet('');
$this
->assertRaw(filter_xss_admin($edit['site_disclaimer_version_details']), 'Site Disclaimer version details found');
$this
->assertRaw($label_raw, 'Checkbox label found.');
$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();
}
}