Skip to content
Snippets Groups Projects
Unverified Commit 0bdc815a authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #17915 from demeritcowboy/useradd-messages

drupal#127 - require email for the Useradd task and errors not showing
parents 0fc6c3b2 454490fc
Branches
Tags
No related merge requests found
......@@ -73,6 +73,7 @@ class CRM_Contact_Form_Task_Useradd extends CRM_Core_Form {
$this->addRule('cms_pass', 'Password is required', 'required');
$this->addRule(['cms_pass', 'cms_confirm_pass'], 'ERROR: Password mismatch', 'compare');
$this->add('text', 'email', ts('Email:'), ['class' => 'huge'])->freeze();
$this->addRule('email', 'Email is required', 'required');
$this->add('hidden', 'contactID');
//add a rule to check username uniqueness
......@@ -101,8 +102,12 @@ class CRM_Contact_Form_Task_Useradd extends CRM_Core_Form {
// store the submitted values in an array
$params = $this->exportValues();
CRM_Core_BAO_CMSUser::create($params, 'email');
CRM_Core_Session::setStatus('', ts('User Added'), 'success');
if (CRM_Core_BAO_CMSUser::create($params, 'email') === FALSE) {
CRM_Core_Error::statusBounce(ts('Error creating CMS user account.'));
}
else {
CRM_Core_Session::setStatus(ts('User Added'), '', 'success');
}
}
/**
......
......@@ -56,6 +56,9 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase {
// Validate the user object
$violations = $account->validate();
if (count($violations)) {
foreach ($violations as $violation) {
CRM_Core_Session::setStatus($violation->getPropertyPath() . ': ' . $violation->getMessage(), '', 'alert');
}
return FALSE;
}
......
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @group headless
*/
class CRM_Contact_Form_Task_UseraddTest extends CiviUnitTestCase {
/**
* Test postProcess failure.
*
* In unit tests, the CMS user creation will always fail, but that's
* ok because that's what we're testing here.
*/
public function testUserCreateFail() {
$form = new CRM_Contact_Form_Task_Useradd();
// We don't need to set params or anything because we're testing fail,
// which the user creation will do in unit tests no matter what we set.
// But before the patch, the status messages were always success no
// matter what.
try {
$form->postProcess();
}
catch (CRM_Core_Exception_PrematureExitException $e) {
}
$statuses = CRM_Core_Session::singleton()->getStatus(TRUE);
$this->assertEquals('alert', $statuses[0]['type']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment