Skip to content

Commit

Permalink
d8-contrib-modules#9: SettingsFormTest.php clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jstephendix committed Aug 26, 2015
1 parent 5afd903 commit 7671da8
Showing 1 changed file with 53 additions and 33 deletions.
86 changes: 53 additions & 33 deletions src/Tests/SettingsFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,70 @@
use Drupal\simpletest\WebTestBase;

/**
* Tests settings form.
* Tests the Drupal 8 securepages module functionality
*
* @group securepages
*/
class SettingsFormTest extends WebTestBase {

public static $modules = array(
'password_policy',
'password_policy_length',
'node'
);
class SecurePagesTest extends WebTestBase {

/**
* Test failing password and verify it fails.
* Modules to install.
*
* @var array
*/
function testOwnUserPasswords() {
// Create password policy length.
$pid = db_insert('password_policy_length_policies')
->fields(array('character_length' => '5'))
->execute();

// Create user with permission to create policy.
$user1 = $this->drupalCreateUser(array('enforce password_policy_length_constraint.' . $pid . ' constraint'));

$this->drupalLogin($user1);
public static $modules = array('securepages', 'node', 'block', 'taxonomy_menu', 'taxonomy');

// Try failing password on form submit.
$edit = array();
$edit['current_pass'] = $user1->pass_raw;
$edit['pass'] = '111';
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
/**
* A simple user with 'access content' permission
*/
private $user;

$this->assertText('The password does not satisfy the password policies');
/**
* Perform any initial set up tasks that run before every test method
*/
public function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy'));
$this->drupalLogin($this->user);
}
/**
* Tests that the 'history/' path returns the right content
*/
public function testHistoryExists() {
$this->drupalLogin($this->user);
$this->drupalGet('history');
$this->assertResponse(200);
$this->assertText(sprintf('Hello %s!', 'World'), 'Correct message is shown.');
}

// Try failing password on AJAX.
/**
* Tests the securepages_match() function.
*/
function testMatch() {
global $is_https;
$config = \Drupal::configFactory()->getEditable('securepages.settings');
$config->set('securepages_ignore', '*/autocomplete/*')->save();

// Try passing password on form submit.
$edit = array();
$edit['current_pass'] = $user1->pass_raw;
$edit['pass'] = '111111';
$this->drupalPostForm("user/" . $user1->id() . "/edit", $edit, t('Save'));
$securepagesservice = \Drupal::service('securepages.securepagesservice');
$this->assertTrue($securepagesservice->securePagesMatch('user'), 'path user matches.');
$this->assertTrue($securepagesservice->securePagesMatch('user/login'), 'path user/login matches.');
$this->assertTrue($securepagesservice->securePagesMatch('admin/modules'), 'path admin/modules matches.');
$this->assertFalse($securepagesservice->securePagesMatch('node'), 'path node does not match.');
$this->assertTrue($securepagesservice->securePagesMatch('user/autocomplete/alice') == $is_https ? 1 : 0, 'autocomplete path is ignored.');

$this->assertNoText('The password does not satisfy the password policies');
// Clean up
$config->clear('securepages_ignore')->save();
}

// Try passing password on AJAX.
/**
* Logs in a user using HTTPS.
*/
function loginHTTPS($user) {
$edit = array(
'name' => $user->name,
'pass' => $user->pass_raw,
);
$this->drupalPost('user', $edit, t('Log in'), array('https' => TRUE));
}

}

0 comments on commit 7671da8

Please sign in to comment.