From 8ac0a6cd30c67d2090d34a52c4cedf46bba14945 Mon Sep 17 00:00:00 2001 From: Tito Alvarez Date: Sun, 5 Aug 2018 12:49:35 -0600 Subject: [PATCH 1/3] [imp] Added function to create a new user --- src/JoomlaBrowser.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/JoomlaBrowser.php b/src/JoomlaBrowser.php index e5432eb..5e344b6 100644 --- a/src/JoomlaBrowser.php +++ b/src/JoomlaBrowser.php @@ -1225,4 +1225,51 @@ public function createCategory($title, $extension = '') $this->see('Category saved', '#system-message-container'); $this->checkForPhpNoticesOrWarnings(); } + + /** + * Create a user in the administrator site + * + * @param string $username User name + * @param string $password Password + * @param string $email Email + * @param string $userGroup Group id to attach to the user + * + * @return void + * + * @since 3.8.11 + * @throws \Exception + */ + public function createUser($username, $password, $email, $userGroup = 'Super Users') + { + $this->debug('User creation'); + $this->doAdministratorLogin(); + + $this->amOnPage('administrator/index.php?option=com_users'); + + $this->waitForElement(array('class' => 'page-title')); + $this->checkForPhpNoticesOrWarnings(); + + $this->debug('Click new user button'); + $this->click($this->locator->adminToolbarButtonNew); + + $this->checkForPhpNoticesOrWarnings(); + $this->debug('I fill up the new user information'); + $this->fillField(array('id' => 'jform_name'), $username); + $this->fillField(array('id' => 'jform_password'), $password); + $this->fillField(array('id' => 'jform_password2'), $password); + $this->fillField(array('id' => 'jform_password2'), $password); + $this->fillField(array('id' => 'jform_email'), $email); + + $this->debug('I open the Assigned User Groups Tab and assign the user group'); + $this->click(array('link' => 'Assigned User Groups')); + $this->click(array('xpath' => "//label[contains(text()[normalize-space()], '$userGroup')]")); + + $this->debug('Click new user apply button'); + $this->click($this->locator->adminToolbarButtonApply); + + $this->debug('see a success message after saving the user'); + + $this->see('User saved', '#system-message-container'); + $this->checkForPhpNoticesOrWarnings(); + } } From b329a1fb6fdc309aa636e7e5793e263a3074ba3e Mon Sep 17 00:00:00 2001 From: Tito Alvarez Date: Sun, 5 Aug 2018 12:54:46 -0600 Subject: [PATCH 2/3] Fixed double reference of password2 field --- src/JoomlaBrowser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/JoomlaBrowser.php b/src/JoomlaBrowser.php index 5e344b6..2abef4e 100644 --- a/src/JoomlaBrowser.php +++ b/src/JoomlaBrowser.php @@ -1257,7 +1257,6 @@ public function createUser($username, $password, $email, $userGroup = 'Super Use $this->fillField(array('id' => 'jform_name'), $username); $this->fillField(array('id' => 'jform_password'), $password); $this->fillField(array('id' => 'jform_password2'), $password); - $this->fillField(array('id' => 'jform_password2'), $password); $this->fillField(array('id' => 'jform_email'), $email); $this->debug('I open the Assigned User Groups Tab and assign the user group'); From f7939beb70876349df7e3183283b2aa16803a014 Mon Sep 17 00:00:00 2001 From: Tito Alvarez Date: Sun, 5 Aug 2018 12:57:27 -0600 Subject: [PATCH 3/3] Added user name --- src/JoomlaBrowser.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/JoomlaBrowser.php b/src/JoomlaBrowser.php index 2abef4e..5c9e7eb 100644 --- a/src/JoomlaBrowser.php +++ b/src/JoomlaBrowser.php @@ -1229,7 +1229,8 @@ public function createCategory($title, $extension = '') /** * Create a user in the administrator site * - * @param string $username User name + * @param string $name Name + * @param string $username User name (login) * @param string $password Password * @param string $email Email * @param string $userGroup Group id to attach to the user @@ -1239,7 +1240,7 @@ public function createCategory($title, $extension = '') * @since 3.8.11 * @throws \Exception */ - public function createUser($username, $password, $email, $userGroup = 'Super Users') + public function createUser($name, $username, $password, $email, $userGroup = 'Super Users') { $this->debug('User creation'); $this->doAdministratorLogin(); @@ -1254,7 +1255,8 @@ public function createUser($username, $password, $email, $userGroup = 'Super Use $this->checkForPhpNoticesOrWarnings(); $this->debug('I fill up the new user information'); - $this->fillField(array('id' => 'jform_name'), $username); + $this->fillField(array('id' => 'jform_name'), $name); + $this->fillField(array('id' => 'jform_username'), $username); $this->fillField(array('id' => 'jform_password'), $password); $this->fillField(array('id' => 'jform_password2'), $password); $this->fillField(array('id' => 'jform_email'), $email);