Commit 630cfff5 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

TEST: make functional tests idempotent

Refs: #643
parent c43a8af5
Pipeline #13446 passed with stage
in 5 minutes and 10 seconds
......@@ -36,6 +36,22 @@ class AcceptanceTester extends Actor
use _generated\AcceptanceTesterActions;
private $lang = 'en';
private static $random;
/**
* Return self::$random (static property)
* and initialize it if necessary
*
* @return string
*/
public function getCurrentRandom()
{
if (is_null(self::$random)) {
self::$random = bin2hex(openssl_random_pseudo_bytes(6));
}
return self::$random;
}
/**
* With $email as login,
......@@ -107,12 +123,16 @@ class AcceptanceTester extends Actor
$I->amOnPage('/');
$I->click('//nav/ul[2]/li[2]/a');
$I->seeInCurrentUrl('/users/add');
$random = $I->getCurrentRandom();
$randomUsername = "$username"."_$random";
$randomEmail = str_replace("@", "$random@", "$email");
// echo "\n-------------\n$randomUsername\n$randomEmail\n---------\n";
$I->submitForm(
'#createAccountForm',
[
'user_type_id' => $userTypeId,
'username' => $username,
'email' => $email,
'username' => $randomUsername,
'email' => $randomEmail,
'password' => $password,
'confirm_password' => $confirmPwd,
]
......
......@@ -43,48 +43,67 @@ class BasicTestsAccountsCest
/**
* Tests the creation functionality as an Association user named Association1
*
* @param AcceptanceTester $I codeception variable
* @group createUser
* @group createUserAssociation
* @group userAccountAssociation
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function createAccountAsAssociation(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$I->createAccountMinimal('6', 'Association1', 'asso@comptoir-du-libre.org', 'mdptest', 'mdptest');
$I->seeElement('div.message.success');
$I->dontSeeInCurrentUrl('/users/add');
$I->canSeeInCurrentUrl('/users/'); // url: /users/<idUser> --> how to really test it?
$I->see('Association1');
$I->see("Association1_$ramdom");
}
/**
* Tests the login functionality as an Association named Association1
*
* @group userLogin
* @group userLoginAssociation
* @group userAccountAssociation
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function tryToLoginAsAssociation(AcceptanceTester $I)
{
$lang = $this->lang;
$userName = 'Association1';
$I->loginMe('asso@comptoir-du-libre.org', 'mdptest', $userName);
$ramdom = $I->getCurrentRandom();
$userName = "Association1_$ramdom";
$I->loginMe("asso$ramdom@comptoir-du-libre.org", 'mdptest', $userName);
$I->seeElement('div.message.success');
$I->canSee('Association1');
$I->canSee("Association1_$ramdom");
$I->cantSeeElement("//a[@href=\"/$lang/users/login\"]");
}
/**
* Tests the logout functionality as an Association account named Association1
*
* @param AcceptanceTester $I codeception variable
* @group userLogout
* @group userLogoutAssociation
* @group userAccountAssociation
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function checkLougoutAssociation(AcceptanceTester $I)
{
$lang = $this->lang;
$I->loginMe('asso@comptoir-du-libre.org', 'mdptest', 'Association1');
$I->logoutMe('Association1');
$I->cantSee('Association1');
$ramdom = $I->getCurrentRandom();
$I->loginMe("asso$ramdom@comptoir-du-libre.org", 'mdptest', "Association1_$ramdom");
$I->logoutMe("Association1_$ramdom");
$I->cantSee("Association1_$ramdom");
$I->seeElement("//a[@href=\"/$lang/users/login\"]");
}
......@@ -95,48 +114,72 @@ class BasicTestsAccountsCest
/**
* Tests the account creation functionality as a Person named Person1
*
* @param AcceptanceTester $I codeception variable
* @group createUser
* @group createUserPerson
* @group userAccountPerson
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function createAccountAsPerson(AcceptanceTester $I)
{
$I->createAccountMinimal('4', 'Person1', 'person@comptoir-du-libre.org', 'mdptest', 'mdptest');
$ramdom = $I->getCurrentRandom();
$I->createAccountMinimal(
'4',
'Person1',
'person@comptoir-du-libre.org',
'mdptest',
'mdptest'
);
$I->seeElement('div.message.success');
$I->dontSeeInCurrentUrl('/users/add');
$I->canSeeInCurrentUrl('/users/'); // url: /users/<idUser> --> how to really test it?
$I->see('Person1');
$I->see("Person1_$ramdom");
}
/**
* Tests the login functionality as a Person account named Person1
*
* @param AcceptanceTester $I codeception variable
* @group userLogin
* @group userLoginPerson
* @group userAccountPerson
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function tryToLoginAsPerson(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('person@comptoir-du-libre.org', 'mdptest', 'Person1');
$I->loginMe("person$ramdom@comptoir-du-libre.org", 'mdptest', "Person1_$ramdom");
$I->seeElement('div.message.success');
$I->canSee('Person1');
$I->canSee("Person1_$ramdom");
$I->cantSeeElement("//a[@href=\"/$lang/users/login\"]");
}
/**
* Tests the login functionality as a Person account named Person1
*
* @param AcceptanceTester $I codeception variable
* @group userLogout
* @group userLogoutPerson
* @group userAccountPerson
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function checkLougoutPerson(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('person@comptoir-du-libre.org', 'mdptest', 'Person1');
$I->logoutMe('Person1');
$I->cantSee('Person1');
$I->loginMe("person$ramdom@comptoir-du-libre.org", 'mdptest', "Person1_$ramdom");
$I->logoutMe("Person1_$ramdom");
$I->cantSee("Person1_$ramdom");
$I->seeElement("//a[@href=\"/$lang/users/login\"]");
}
......@@ -147,48 +190,66 @@ class BasicTestsAccountsCest
/**
* Tests the account creation functionality as an Administration named Administration1
*
* @param AcceptanceTester $I codeception variable
* @group createUser
* @group createUserAdministration
* @group userAccountAdministration
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function createAccountAsAdministration(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$I->createAccountMinimal('2', 'Administration1', 'administration@comptoir-du-libre.org', 'mdptest', 'mdptest');
$I->seeElement('div.message.success');
$I->dontSeeInCurrentUrl('/users/add');
$I->canSeeInCurrentUrl('/users/'); // url: /users/<idUser> --> how to really test it?
$I->see('Administration1');
$I->see("Administration1_$ramdom");
}
/**
* Tests the login functionality as an Administration account named Administration1
*
* @param AcceptanceTester $I codeception variable
* @group userLogin
* @group userLoginAdministration
* @group userAccountAdministration
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function tryToLoginAsAdministration(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('administration@comptoir-du-libre.org', 'mdptest', 'Administration1');
$I->loginMe("administration$ramdom@comptoir-du-libre.org", 'mdptest', "Administration1_$ramdom");
$I->seeElement('div.message.success');
$I->canSee('Administration');
$I->canSee("Administration1_$ramdom");
$I->cantSeeElement("//a[@href=\"/$lang/users/login\"]");
}
/**
* Tests the logout functionality as an Administration account named Administration1
*
* @param AcceptanceTester $I codeception variable
* @group userLogout
* @group userLogoutAdministration
* @group userAccountAdministration
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function checkLougoutAdministration(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('administration@comptoir-du-libre.org', 'mdptest', 'Administration1');
$I->logoutMe('Administration1');
$I->cantSee('Administration1');
$I->loginMe("administration$ramdom@comptoir-du-libre.org", 'mdptest', "Administration1_$ramdom");
$I->logoutMe("Administration1_$ramdom");
$I->cantSee("Administration1_$ramdom");
$I->seeElement("//a[@href=\"/$lang/users/login\"]");
}
......@@ -199,48 +260,66 @@ class BasicTestsAccountsCest
/**
* Tests the account creation functionality as a Company named Company1
*
* @param AcceptanceTester $I codeception variable
* @group createUser
* @group createUserCompany
* @group userAccountCompany
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function createAccountAsServiceProvider(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$I->createAccountMinimal('2', 'Company1', 'company@comptoir-du-libre.org', 'mdptest', 'mdptest');
$I->seeElement('div.message.success');
$I->dontSeeInCurrentUrl('/users/add');
$I->canSeeInCurrentUrl('/users/'); // url: /users/<idUser> --> how to really test it?
$I->see('Company1');
$I->see("Company1_$ramdom");
}
/**
* Tests the login functionality as a Company account named Company1
*
* @param AcceptanceTester $I codeception variable
* @group userLogin
* @group userLoginCompany
* @group userAccountCompany
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function tryToLoginAsServiceProvider(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('company@comptoir-du-libre.org', 'mdptest', 'Company1');
$I->loginMe("company$ramdom@comptoir-du-libre.org", 'mdptest', "Company1_$ramdom");
$I->seeElement('div.message.success');
$I->canSee('Company1');
$I->canSee("Company1_$ramdom");
$I->cantSeeElement("//a[@href=\"/$lang/users/login\"]");
}
/**
* Tests the logout functionality as a Company account named Company1
*
* @param AcceptanceTester $I codeception variable
* @group userLogout
* @group userLogoutCompany
* @group userAccountCompany
* @group userAccount
* @group user
*
* @param AcceptanceTester $I codeception variable
* @return void
*/
public function checkLougoutServiceProvider(AcceptanceTester $I)
{
$ramdom = $I->getCurrentRandom();
$lang = $this->lang;
$I->loginMe('company@comptoir-du-libre.org', 'mdptest', 'Company1');
$I->logoutMe('Company1');
$I->cantSee('Company1');
$I->loginMe("company$ramdom@comptoir-du-libre.org", 'mdptest', "Company1_$ramdom");
$I->logoutMe("Company1_$ramdom");
$I->cantSee("Company1_$ramdom");
$I->seeElement("//a[@href=\"/$lang/users/login\"]");
}
......
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