Skip to content

Commit

Permalink
Merge pull request #1764 from micszo/ibx-405-change-password
Browse files Browse the repository at this point in the history
[Behat] IBX-405: Behat coverage for changing user password
  • Loading branch information
mnocon authored May 31, 2021
2 parents 382b365 + a4753d5 commit 0c71a29
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ adminui:
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\NotificationContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\TrashContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\UDWContext
- EzSystems\EzPlatformAdminUi\Behat\BusinessContext\UserPreferencesContext
16 changes: 16 additions & 0 deletions features/personas/ChangePassword.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@javascript @changePassword
Feature: Verify that an User allowed to change password can change his password

Scenario: I can change my password
Given I open Login page
And I log in as "UserPassword" with password "Passw0rd-42"
When I go to change my password
And I change password from "Passw0rd-42" to "Passw0rd-43"
And I click on the edit action bar button "Update"
Then success notification that "Your password has been successfully changed." appears
And I should be on Dashboard page

Scenario: I can log in with new password
Given I open Login page
When I log in as "UserPassword" with password "Passw0rd-43"
Then I should be on Dashboard page
10 changes: 10 additions & 0 deletions src/lib/Behat/BusinessContext/NavigationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ public function iGoToUserNotifications()
$upperMenu->chooseFromUserDropdown('View Notifications');
}

/**
* @Given I go to change my password
* @Given I go to change my password in user preferences
*/
public function iGoToChangeMyPassword()
{
$upperMenu = ElementFactory::createElement($this->utilityContext, UpperMenu::ELEMENT_NAME);
$upperMenu->chooseFromUserDropdown('Change password');
}

/**
* @Then I should be redirected to root in default view
*/
Expand Down
25 changes: 25 additions & 0 deletions src/lib/Behat/BusinessContext/UserPreferencesContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\BusinessContext;

use EzSystems\EzPlatformAdminUi\Behat\PageObject\ChangePasswordPage;
use EzSystems\EzPlatformAdminUi\Behat\PageObject\PageObjectFactory;

class UserPreferencesContext extends BusinessContext
{
/**
* @When I change password from :oldPassword to :newPassword
*/
public function iChangePassword($oldPassword, $newPassword): void
{
$passwordPage = PageObjectFactory::createPage($this->utilityContext, ChangePasswordPage::PAGE_NAME);
$passwordPage->verifyIsLoaded();
$passwordPage->setOldPassword($oldPassword);
$passwordPage->setNewPassword($newPassword);
$passwordPage->setConfirmPassword($newPassword);
}
}
75 changes: 75 additions & 0 deletions src/lib/Behat/PageObject/ChangePasswordPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageObject;

use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\ElementFactory;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\RightMenu;
use PHPUnit\Framework\Assert;

class ChangePasswordPage extends Page
{
/** @var string Name by which Page is recognised */
public const PAGE_NAME = 'Change my password';

/**
* @var RightMenu
*/
private $rightMenu;

public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->rightMenu = ElementFactory::createElement($this->context, RightMenu::ELEMENT_NAME);
$this->siteAccess = 'admin';
$this->route = '/user/change-password';
$this->pageTitleLocator = '.ez-header h1';
$this->fields = [
'oldPassword' => '#user_password_change_oldPassword',
'newPassword' => '#user_password_change_newPassword_first',
'confirmPassword' => '#user_password_change_newPassword_second',
];
}

public function verifyElements(): void
{
$this->rightMenu->verifyVisibility();
}

public function verifyRoute(): void
{
$expectedRoute = '/' . $this->siteAccess . $this->route;
Assert::assertContains($expectedRoute, $this->getCurrentRoute());
}

public function verifyTitle(): void
{
Assert::assertContains($this::PAGE_NAME, $this->getPageTitle());
}

public function verifyIsLoaded(): void
{
$this->verifyElements();
$this->verifyRoute();
$this->verifyTitle();
}

public function setOldPassword(string $value): void
{
$this->context->findElement($this->fields['oldPassword'])->setValue($value);
}

public function setNewPassword(string $value): void
{
$this->context->findElement($this->fields['newPassword'])->setValue($value);
}

public function setConfirmPassword(string $value): void
{
$this->context->findElement($this->fields['confirmPassword'])->setValue($value);
}
}
2 changes: 2 additions & 0 deletions src/lib/Behat/PageObject/PlatformPageObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public static function createPage(UtilityContext $context, string $pageName, ?st
return new SearchPage($context);
case UserCreationPage::PAGE_NAME:
return new UserCreationPage($context);
case ChangePasswordPage::PAGE_NAME:
return new ChangePasswordPage($context);
default:
throw new \InvalidArgumentException(sprintf('Unrecognised page name: %s', $pageName));
}
Expand Down

0 comments on commit 0c71a29

Please sign in to comment.