Commit 42bfe929 authored by alexpott's avatar alexpott
Browse files

Issue #1843380 by wuinfo, netol, xjm: Fixed The message telling that the new...

Issue #1843380 by wuinfo, netol, xjm: Fixed The message telling that the new user has been e-mailed is always displayed, even if it's not true.
parent f3966d6c
<?php
/**
* @file
* Contains \Drupal\system_mail_failure_test\TestPhpMailFailure.
*/
namespace Drupal\system_mail_failure_test;
use Drupal\Core\Mail\PhpMail;
use Drupal\Core\Mail\MailInterface;
/**
* Defines a mail sending implementation that returns false.
*
* This class is for running tests or for development. To use set the
* configuration:
* @code
* config('system.mail')->set('interface.default', 'Drupal\system_mail_failure_test\TestPhpMailFailure')->save();
* @endcode
*/
class TestPhpMailFailure extends PhpMail implements MailInterface {
/**
* Overrides Drupal\Core\Mail\PhpMail::mail().
*/
public function mail(array $message) {
// Instead of attempting to send a message, just return failure.
return FALSE;
}
}
name: 'System mail failure test'
description: 'Provides a malfunctioning mail service for testing purposes.'
package: Testing
version: VERSION
core: 8.x
hidden: true
<?php
/**
* @file
* Disables the email function for testing purposes.
*/
......@@ -131,13 +131,14 @@ public function save(array $form, array &$form_state) {
}
else {
$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
_user_mail_notify($op, $account);
if ($notify) {
drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
}
else {
drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));
$form_state['redirect'] = '';
if (_user_mail_notify($op, $account)) {
if ($notify) {
drupal_set_message(t('A welcome message with further instructions has been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url($uri['path'], $uri['options']), '%name' => $account->name)));
}
else {
drupal_set_message(t('A welcome message with further instructions has been sent to your e-mail address.'));
$form_state['redirect'] = '';
}
}
}
}
......
<?php
/**
* @file
* Contains Drupal\user\Tests\UserCreateFailMailTest.
*/
namespace Drupal\user\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the create user administration page.
*/
class UserCreateFailMailTest extends WebTestBase {
/**
* Modules to enable
*
* @var array
*/
public static $modules = array('system_mail_failure_test');
public static function getInfo() {
return array(
'name' => 'User create with failed mail function',
'description' => 'Test the create user administration page.',
'group' => 'User',
);
}
/**
* Tests the create user administration page.
*/
protected function testUserAdd() {
$user = $this->drupalCreateUser(array('administer users'));
$this->drupalLogin($user);
// Replace the mail functionality with a fake, malfunctioning service.
config('system.mail')->set('interface.default', 'Drupal\system_mail_failure_test\TestPhpMailFailure')->save();
// Create a user, but fail to send an email.
$name = $this->randomName();
$edit = array(
'name' => $name,
'mail' => $this->randomName() . '@example.com',
'pass[pass1]' => $pass = $this->randomString(),
'pass[pass2]' => $pass,
'notify' => TRUE,
);
$this->drupalPost('admin/people/create', $edit, t('Create new account'));
$this->assertText(t('Unable to send e-mail. Contact the site administrator if the problem persists.'));
$this->assertNoText(t('A welcome message with further instructions has been e-mailed to the new user @name.', array('@name' => $edit['name'])));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment