[ 'url' => 'ienakt-gramatvedibas-sistema', 'header' => 'Ienākt grāmatvedības sistēmā', 'header-2fa' => 'Divu faktoru autentifikācija', 'header-3pwd' => 'Mainīt lietotāja paroli', 'exists' => ['#user_name', '#old_password', '#new_password', '#rnew_password', 'button.btn.btn-block'], 'text-exists' => ['Mainīt lietotāja paroli','Manīt paroli'], 'inv-pwd' => 'Jaunā lietotāja parole nevar sakrist ar veco!', 'pwd-ok' => 'Lietotāja parole veiksmīgi nomainīta!', 'welcome-msg' => ['Laipni lūdzam,', 'Grāmatvedības sistēma', 'Sākums'], 'fill-field' => 'Lūdzu aizpildiet lauku!', 'fill-min' => 'Min value length is 6', 'fill-dont-match' => 'Fields do not match!', ] ]; protected function setUp(): void { parent::setUp(); // Set user force password change param $this->cDb->query("UPDATE mod_users SET user_fchange = '1' WHERE id = 12"); } protected function tearDown(): void { //$this->dbSetup(['App/pubUsers/mod_users_db_setup.sql']); $this->reloadDbTables(['mod_users']); parent::tearDown(); } public function testPwdChange(): void { foreach (self::url as $lang => $pageData) { // Got to location to test $this->goToPasswordChangeForm($pageData); // Change user password $this->changeUserPassword($pageData); } } public function testPwdChangeForm(): void { $loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed); foreach (self::url as $lang => $pageData) { // Got to location to test $this->goToPasswordChangeForm($pageData); // Test error containing fields $this->webDriver->action()->moveToElement($this->byId('new_password'))->perform(); $this->webDriver->executeScript('$("#new_password").focus().blur();'); $this->elementWait('#new_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-field'], $this->byCssSelector('#new_password + div.errMsg')->getText()); $this->webDriver->action()->moveToElement($this->byId('rnew_password'))->perform(); $this->webDriver->executeScript('$("#rnew_password").focus().blur();'); $this->elementWait('#rnew_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-field'], $this->byCssSelector('#rnew_password + div.errMsg')->getText()); $this->webDriver->executeScript('$("#new_password").focus().val("asd").blur();'); $this->webDriver->action()->moveToElement($this->byId('new_password'))->perform(); $this->elementWait('#new_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-min'], $this->byCssSelector('#new_password + div.errMsg')->getText()); $this->webDriver->executeScript('$("#new_password").focus().val("' . $loginData['password'] . '").blur();'); $this->webDriver->action()->moveToElement($this->byId('new_password'))->perform(); $this->elementWait('#new_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-dont-match'], $this->byCssSelector('#new_password + div.errMsg')->getText()); // Both fields should have error $this->webDriver->action()->moveToElement($this->byId('rnew_password'))->perform(); $this->elementWait('#rnew_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-field'], $this->byCssSelector('#rnew_password + div.errMsg')->getText()); $this->webDriver->executeScript('$("#rnew_password").focus().val("dsa").blur();'); $this->webDriver->action()->moveToElement($this->byId('rnew_password'))->perform(); $this->elementWait('#rnew_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-min'], $this->byCssSelector('#rnew_password + div.errMsg')->getText()); $this->webDriver->executeScript('$("#rnew_password").focus().val("testLongerPassword").blur();'); $this->webDriver->action()->moveToElement($this->byId('rnew_password'))->perform(); $this->elementWait('#rnew_password + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($pageData['fill-dont-match'], $this->byCssSelector('#rnew_password + div.errMsg')->getText()); // Set both fields to same long password $this->webDriver->executeScript('$("#rnew_password").focus().val("' . $loginData['password'] . '").blur();'); $this->webDriver->action()->moveToElement($this->byId('rnew_password'))->perform(); // Errors should be gone - hidden/removed $this->assertEquals('', $this->byCssSelector('#new_password + div.errMsg')->getText()); $this->assertEquals('', $this->byCssSelector('#rnew_password + div.errMsg')->getText()); $this->assertTrue($this->elementExists('.v-ok #new_password', self::CSS_SELECTOR)); $this->assertTrue($this->elementExists('.v-ok #rnew_password', self::CSS_SELECTOR)); // Send password change request $this->byCssSelector("form#pwd_cnt button.btn.btn-block")->click(); // Wait for error message $this->elementWait('status_error', self::CLASS_NAME); $this->assertEquals($pageData['inv-pwd'], $this->byCssSelector('div.status_error')->getText()); // Change user password $this->changeUserPassword($pageData); } } public function testPwdChangePageLoaded(): void { foreach (self::url as $lang => $pageData) { // Got to location to test $this->goToPasswordChangeForm($pageData); foreach ($pageData['exists'] as $selectorToFind) { $this->assertTrue($this->elementExists($selectorToFind, self::CSS_SELECTOR)); } $this->assertExpected($pageData['text-exists'], $this->byTagName('body')->getText()); } } private function goToPasswordChangeForm(array $pageData): void { $loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed); $this->url($pageData['url']); $this->elementWait('user_login'); $this->assertEquals($pageData['header'], $this->byCssSelector('div#form > .relative > p.font-20')->getText()); // Input login data $this->byId("user_login")->sendKeys($loginData['user']); $this->byId("user_password")->sendKeys($loginData['password']); $this->byCssSelector("form#frm_input div#agree_to_terms")->click(); $this->byCssSelector("form#frm_input button.btn.btn-block")->click(); $this->elementWait('frm_2fa_input'); $this->assertEquals($pageData['header-2fa'], $this->byCssSelector('div#form > .relative > p.font-20')->getText()); // Validate 2fa code from google $oGoogle2FA = new cGoogle2FA(); $next2FACode = $oGoogle2FA->getGoogleAuthCode($loginData['2fa']); foreach (str_split($next2FACode) as $i => $char) { $this->byCssSelector("input.code2fa[tabindex='" . ++$i . "']")->clear()->sendKeys($char); } $this->elementWait('pwd_cnt'); $this->assertEquals( $pageData['header-3pwd'], $this->byCssSelector('div.container .relative > p.font-20')->getText() ); } private function changeUserPassword(array $pageData, bool $has2FASecurityEnabled = true): void { // Input data $this->byId("new_password")->sendKeys('testmynewpassword12!@'); $this->byId("rnew_password")->sendKeys('testmynewpassword12!@'); $this->byCssSelector("form#pwd_cnt > button.btn.btn-block")->click(); // Increase response timeout before redirect - Wait for confirmation message $this->webDriver->executeScript('JsBase.jsModule.iMessageTimeOut = 3000;'); $this->waitUntilDomReadyState(); $this->assertEquals( $pageData['pwd-ok'], $this->byCssSelector('div.container .relative > div.status_ok')->getText() ); // Wait for company selection screen by default user has now multiple companies $this->elementWait( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]", self::XPATH ); $this->elementExists( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]", self::XPATH ); $this->byXPath( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]/.." )->click(); // Validate dashboard welcome messages if ($has2FASecurityEnabled) { $this->elementWait("#drop_cnt > .doc > .form-data div.container.dashboard-cnt", self::CSS_SELECTOR); $this->assertExpected($pageData['welcome-msg'], $this->byTagName('body')->getText()); } // Accept cookies message $this->awaitAndAcceptCookies(); } }