BasicUserTest.php in Multiple E-mail Addresses 2.x
Definition of Drupal\multiple_email\Tests\BasicUserTest.
Namespace
Drupal\multiple_email\TestsFile
src/Tests/BasicUserTest.phpView source
<?php
/**
* @file
* Definition of Drupal\multiple_email\Tests\BasicUserTest.
*/
namespace Drupal\multiple_email\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Test basic user registration without 'use multiple email permissions' and its
* interactions with the module.
*
* @group multiple_email
*/
class BasicUserTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'multiple_email',
);
protected function setUp() {
// Set up basic Drupal install.
parent::setUp();
// Create a user allowed to have multiple emails.
$this->user = $this
->drupalCreateUser();
$this
->drupalLogin($this->user);
}
/**
* Test that the Multiple E-mails user can add a new e-mail address.
*/
public function testMultipleEmailBasicUser() {
// Test that the e-mail address appears on the page
$this
->drupalGet('user/' . $this->loggedInUser
->id() . '/edit');
$this
->assertRaw($this->loggedInUser
->getEmail(), t('Registered e-mail successfully added'));
// Test can't add a new e-mail address.
$edit = array(
'email' => $this
->randomMachineName() . '@example.com',
'current_pass' => $this->loggedInUser->pass_raw,
);
$this
->drupalGet('user/' . $this->loggedInUser
->id() . '/edit/email-addresses');
$this
->assertNoText(t('Add E-mail Address'));
// Load the address object.
$addresses = multiple_email_load_addresses($this->loggedInUser
->id());
array_shift($addresses);
foreach ($addresses as $address) {
if ($address->email == $this->loggedInUser
->getEmail()) {
break;
}
}
// Test submitting the user edit form with the same address.
$this
->drupalGet('user/' . $this->loggedInUser
->id() . '/edit');
$this
->assertRaw($address->email);
$edit = array(
'mail' => $address->email,
);
$this
->drupalPostForm('user/' . $this->loggedInUser
->id() . '/edit', $edit, t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertRaw($edit['mail']);
// Test submitting the user edit form with a different address.
$edit = array(
'mail' => $this
->randomMachineName() . '@example.com',
'current_pass' => $this->loggedInUser->pass_raw,
);
$this
->drupalPostForm('user/' . $this->loggedInUser
->id() . '/edit', $edit, t('Save'));
$this
->assertText(t('The changes have been saved.'));
$this
->assertRaw($edit['mail']);
// Test deleting the address.
$this
->drupalGet('user/' . $this->loggedInUser
->id() . '/edit/email-addresses/delete/' . $address->eid);
$this
->assertNoRaw(t('Are you sure you wish to delete the address %email from your user account?', array(
'%email' => $edit['mail'],
)));
}
}
Classes
Name | Description |
---|---|
BasicUserTest | Test basic user registration without 'use multiple email permissions' and its interactions with the module. |