Cannot delete currently logged in user scenario

This commit is contained in:
Magdalena Banasiak 2016-02-09 16:01:53 +01:00
parent 24bb6bbf96
commit 7b745cb27c
29 changed files with 409 additions and 246 deletions

View file

@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;

View file

@ -33,6 +33,7 @@
<parameter key="sylius.behat.context.ui.channel.class">Sylius\Behat\Context\Ui\ChannelContext</parameter>
<parameter key="sylius.behat.context.ui.product.class">Sylius\Behat\Context\Ui\ProductContext</parameter>
<parameter key="sylius.behat.context.ui.paypal.class">Sylius\Behat\Context\Ui\PaypalContext</parameter>
<parameter key="sylius.behat.context.ui.customer.class">Sylius\Behat\Context\Ui\CustomerContext</parameter>
</parameters>
<services>
<service id="sylius.behat.context.setup.channel" class="%sylius.behat.context.setup.channel.class%" scope="scenario">
@ -149,6 +150,9 @@
</service>
<service id="sylius.behat.context.ui.user" class="%sylius.behat.context.ui.user.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.repository.user" container="symfony" />
<argument type="service" id="sylius.behat.page.customer_show" />
<argument type="service" id="sylius.behat.page.login" />
<tag name="sylius.behat.context" />
</service>
@ -169,5 +173,11 @@
<argument type="service" id="sylius.behat.page.product_show" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.customer" class="%sylius.behat.context.ui.customer.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.behat.page.customer_show" />
<tag name="sylius.behat.context" />
</service>
</services>
</container>

View file

@ -15,6 +15,7 @@
<parameters>
<parameter key="sylius.behat.page.cart_summary.class">Sylius\Behat\Page\Cart\CartSummaryPage</parameter>
<parameter key="sylius.behat.page.product_show.class">Sylius\Behat\Page\Product\ProductShowPage</parameter>
<parameter key="sylius.behat.page.customer_show.class">Sylius\Behat\Page\Customer\CustomerShowPage</parameter>
<parameter key="sylius.behat.page.login.class">Sylius\Behat\Page\User\LoginPage</parameter>
<parameter key="sylius.behat.page.home.class">Sylius\Behat\Page\Shop\HomePage</parameter>
@ -30,6 +31,7 @@
<services>
<service id="sylius.behat.page.cart_summary" class="%sylius.behat.page.cart_summary.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.product_show" class="%sylius.behat.page.product_show.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.customer_show" class="%sylius.behat.page.customer_show.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.login" class="%sylius.behat.page.login.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />
<service id="sylius.behat.page.home" class="%sylius.behat.page.home.class%" parent="sylius.behat.symfony_page" scope="scenario" public="false" />

View file

@ -34,5 +34,4 @@ imports:
- suites/ui_channel.yml
- suites/ui_checkout.yml
- suites/ui_promotion.yml
- suites/ui-user.yml
- suites/ui_user.yml

View file

@ -1,28 +0,0 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui-user:
contexts:
- Sylius\Behat\Context\Setup\ChannelContext:
defaultFranceChannelFactory: "@sylius.behat.default_france_channel_factory"
sharedStorage: "@sylius.behat.shared_storage"
- Sylius\Behat\Context\Setup\SecurityContext:
securityService: "@sylius.behat.security"
- Sylius\Behat\Context\Setup\UserContext:
userRepository: "@sylius.repository.user"
sharedStorage: "@sylius.behat.shared_storage"
userFactory: "@sylius.factory.user"
customerFactory: "@sylius.factory.customer"
addressFactory: "@sylius.factory.address"
- Sylius\Behat\Context\Ui\CustomerContext:
sharedStorage: "@sylius.behat.shared_storage"
customerRepository: "@sylius.repository.customer"
- Sylius\Behat\Context\Ui\UserContext:
sharedStorage: "@sylius.behat.shared_storage"
customerRepository: "@sylius.repository.customer"
- Sylius\Behat\Context\Hook\DoctrineORMContext:
entityManager: "@doctrine.orm.entity_manager"
filters:
tags: "@ui-user"

View file

@ -0,0 +1,17 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski
default:
suites:
ui_user:
contexts_as_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.setup.channel
- sylius.behat.context.setup.security
- sylius.behat.context.setup.user
- sylius.behat.context.ui.user
- sylius.behat.context.ui.customer
filters:
tags: @user && @ui

View file

@ -1,22 +0,0 @@
@ui-user
Feature: Deleting the account in backend
In order to delete Customer account on demand
As an Administrator
I want to be able to remove Customer account details from the system
Background:
Given there is user "theodore@example.com" identified by "pswd"
And there is an administrator account
And I am logged in as administrator
@javascript
Scenario: Deleting account should not delete customer details
When I delete the account of "theodore@example.com"
Then there should be customer with email "theodore@example.com"
And there should be no account with email "theodore@example.com"
@javascript
Scenario: A customer with no user cannot be deleted
Given the account of "theodore@example.com" was deleted
When I access the "theodore@example.com" customer show page
Then I should not see "Delete" button

View file

@ -148,36 +148,10 @@ Feature: Customers management
Then I should be on the sylius homepage page
And I should see "Logout"
Scenario: Accessing the customer details page from customers list for deleted customer
Given I deleted customer with email "rick@foo.com"
And I am on the customer index page
And I view deleted elements
When I click "Details" near "rick@foo.com"
Then I should be on the page of customer with email "rick@foo.com"
And I should see 1 orders in the list
Scenario: Deleting customer
Given I am on the page of customer with email "rick@foo.com"
When I press "Delete"
Then I should see "Do you want to delete this item"
When I press "Delete"
Then I should be on the customer index page
And I should see "Customer has been successfully deleted"
@javascript
Scenario: Deleting customer
Given I am on the page of customer with email "rick@foo.com"
When I press "Delete"
And I click "Delete" from the confirmation modal
Then I should be on the customer index page
And I should see "Customer has been successfully deleted"
And I should not see customer with email "rick@foo.com" in that list
@javascript
Scenario: Deleting customer from the list
Scenario: Deleting user from the list
Given I am on the customer index page
When I click "Delete" near "rick@foo.com"
And I click "Delete" from the confirmation modal
Then I should still be on the customer index page
And "Customer has been successfully deleted" should appear on the page
But I should not see customer with email "rick@foo.com" in that list
And "User has been successfully deleted" should appear on the page

View file

@ -0,0 +1,25 @@
@user
Feature: Deleting the user account
In order to delete customer account on demand
As an Administrator
I want to be able to remove customer account details from the system
Background:
Given there is user "theodore@example.com" identified by "pswd"
And I am logged in as administrator
@ui @javascript
Scenario: The account of currently logged in user cannot be deleted
When I try to delete my own account
Then I should not be able to do it
@ui @javascript
Scenario: Deleting account should not delete customer details
When I delete the account of "theodore@example.com" user
Then the user account should be deleted
But the customer with this email should still exist
@ui @javascript
Scenario: A customer with no user cannot be deleted
Given the account of "theodore@example.com" was deleted
Then I should not be able to delete it again

View file

@ -1,18 +0,0 @@
@account
Feature: Registering account again after it has been deleted
In order to set up a new account after I deleted it from the system
As a Visitor
I want to be able to register again with the same e-mail
Background:
Given there was account of "john@example.com"
And there was an order made by this customer
But his account was deleted
Scenario: Registering again after my account deletion
When I try to register again with email "john@example.com
Then I should be successfully registered
Scenario: Maintaining orders history after my account renewal
When I register with email "john@example.com"
Then I should have 1 order in my orders history

View file

@ -80,4 +80,17 @@ final class SecurityContext implements Context
$this->sharedStorage->set('user', $user);
}
/**
* @Given I am logged in as administrator
*/
public function iAmLoggedInAsAdministrator()
{
$admin = $this->testUserFactory->createDefaultAdmin();
$this->userRepository->add($admin);
$this->securityService->logIn($admin->getEmail());
$this->sharedStorage->set('admin', $admin);
}
}

View file

@ -18,10 +18,12 @@ use Sylius\Component\Core\Test\Factory\TestUserFactoryInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Symfony\Component\Intl\Intl;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
final class UserContext implements Context
{
@ -51,14 +53,14 @@ final class UserContext implements Context
private $userManager;
/**
* @param RepositoryInterface $userRepository
* @param UserRepositoryInterface $userRepository
* @param SharedStorageInterface $sharedStorage
* @param TestUserFactoryInterface $userFactory
* @param FactoryInterface $addressFactory
* @param ObjectManager $userManager
*/
public function __construct(
RepositoryInterface $userRepository,
UserRepositoryInterface $userRepository,
SharedStorageInterface $sharedStorage,
TestUserFactoryInterface $userFactory,
FactoryInterface $addressFactory,
@ -79,6 +81,7 @@ final class UserContext implements Context
$user = $this->userFactory->create($email, $password);
$this->sharedStorage->set('user', $user);
$this->userRepository->add($user);
}
@ -158,33 +161,14 @@ final class UserContext implements Context
return $countryCode;
}
/**
* @Given there is an administrator account
*/
public function thereIsAdministratorAccount()
{
/** @var UserInterface $user */
$user = $this->userFactory->createNew();
$customer = $this->customerFactory->createNew();
$customer->setFirstName('Admin');
$customer->setLastName('Admin');
$user->setCustomer($customer);
$user->setUsername('Administrator Account');
$user->setEmail('admin@test.com');
$user->setPlainPassword('pswd1234');
$user->addRole('ROLE_ADMINISTRATION_ACCESS');
$this->sharedStorage->setCurrentResource('administrator', $user);
$this->userRepository->add($user);
}
/**
* @Given the account of :email was deleted
*/
public function accountWasDeleted($email)
{
$user = $this->userRepository->findOneBy(array('username' => $email));
$user = $this->userRepository->findOneByEmail($email);
$this->sharedStorage->set('customer', $user->getCustomer());
$this->userRepository->remove($user);
}

View file

@ -14,7 +14,6 @@ namespace Sylius\Behat\Context\Ui;
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Customer\CustomerShowPage;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
@ -26,11 +25,6 @@ class CustomerContext implements Context
*/
private $sharedStorage;
/**
* @var RepositoryInterface
*/
private $customerRepository;
/**
* @var CustomerShowPage
*/
@ -38,30 +32,37 @@ class CustomerContext implements Context
/**
* @param SharedStorageInterface $sharedStorage
* @param RepositoryInterface $customerRepository
* @param CustomerShowPage $customerShowPage
*/
public function __construct(
SharedStorageInterface $sharedStorage,
RepositoryInterface $customerRepository,
CustomerShowPage $customerShowPage
) {
$this->sharedStorage = $sharedStorage;
$this->customerRepository = $customerRepository;
$this->customerShowPage = $customerShowPage;
}
/**
* @Then there should be customer with email :email
* @Then I should not be able to delete it again
*/
public function thereShouldBeCustomerIdentifiedBy($email)
public function iShouldNotBeAbleToDeleteCustomerAgain()
{
$customer = $this->customerRepository->findOneBy(array('email' =>$email));
$customer = $this->sharedStorage->get('customer');
$this->customerShowPage->open(array('id' => $customer->getId()));
$this->customerShowPage->open(['id' => $customer->getId()]);
if (true === $this->customerShowPage->isThisCustomerRegistered($email)) {
throw new \InvalidArgumentException('This customer is a registered user, when it should not.');
}
expect($this->customerShowPage)->toThrow(new \Exception('Element not found.'))->during('deleteAccount');
}
/**
* @Then the customer with this email should still exist
*/
public function customerShouldStillExist()
{
$deletedUser = $this->sharedStorage->get('deleted_user');
$this->customerShowPage->open(['id' => $deletedUser->getCustomer()->getId()]);
expect($this->customerShowPage->isRegistered())->toBe(false);
}
}

View file

@ -12,17 +12,16 @@
namespace Sylius\Behat\Context\Ui;
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\User\LoginPage;
use Sylius\Behat\Page\Customer\CustomerShowPage;
use Sylius\Behat\Page\Customer\CustomersIndexPage;
use Sylius\Behat\Page\User\LoginPage;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class UserContext implements Context
final class UserContext implements Context
{
/**
* @var SharedStorageInterface
@ -30,14 +29,9 @@ class UserContext implements Context
private $sharedStorage;
/**
* @var RepositoryInterface
* @var UserRepositoryInterface
*/
private $customerRepository;
/**
* @var CustomersIndexPage
*/
private $customersIndexPage;
private $userRepository;
/**
* @var CustomerShowPage
@ -51,21 +45,18 @@ class UserContext implements Context
/**
* @param SharedStorageInterface $sharedStorage
* @param RepositoryInterface $customerRepository
* @param CustomersIndexPage $customersIndexPage
* @param UserRepositoryInterface $userRepository
* @param CustomerShowPage $customerShowPage
* @param LoginPage $loginPage
*/
public function __construct(
SharedStorageInterface $sharedStorage,
RepositoryInterface $customerRepository,
CustomersIndexPage $customersIndexPage,
UserRepositoryInterface $userRepository,
CustomerShowPage $customerShowPage,
LoginPage $loginPage
) {
$this->sharedStorage = $sharedStorage;
$this->customerRepository = $customerRepository;
$this->customersIndexPage = $customersIndexPage;
$this->userRepository = $userRepository;
$this->customerShowPage = $customerShowPage;
$this->loginPage = $loginPage;
}
@ -80,24 +71,45 @@ class UserContext implements Context
}
/**
* @When I delete the account of :email
* @When I delete the account of :email user
*/
public function iDeleteAccount($email)
{
$customersIndexPage = $this->customersIndexPage;
$customersIndexPage->open();
$customersIndexPage->deleteUser($email);
$user = $this->userRepository->findOneByEmail($email);
$this->sharedStorage->set('deleted_user', $user);
$this->customerShowPage->open(['id' => $user->getCustomer()->getId()]);
$this->customerShowPage->deleteAccount();
}
/**
* @Then there should be no account with email :email
* @When I try to delete my own account
*/
public function thereShouldBeNoAccount($email)
public function iTryDeletingMyOwnAccount()
{
$customer = $this->customerRepository->findOneBy(array('email' =>$email));
$admin = $this->sharedStorage->get('admin');
$this->customerShowPage->open(array('id' => $customer->getId()));
$this->customerShowPage->open(['id' => $admin->getId()]);
}
$this->customerShowPage->isThereAccountOf($email);
/**
* @Then I should not be able to do it
*/
public function iShouldNotBeAbleToDeleteMyOwnAccount()
{
expect($this->customerShowPage)->toThrow(new \Exception('Element not found.'))->during('deleteAccount');
}
/**
* @Then the user account should be deleted
*/
public function accountShouldBeDeleted()
{
$deletedUser = $this->sharedStorage->get('deleted_user');
$this->customerShowPage->open(['id' => $deletedUser->getCustomer()->getId()]);
expect($this->customerShowPage->isRegistered())->toBe(false);
}
}

View file

@ -11,7 +11,7 @@
namespace Sylius\Behat\Page\Customer;
use Sylius\Behat\SymfonyPageObjectExtension\PageObject\SymfonyPage;
use Sylius\Behat\Page\SymfonyPage;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
@ -26,14 +26,36 @@ class CustomerShowPage extends SymfonyPage
return 'sylius_backend_customer_show';
}
public function isThisCustomerRegistered($email)
/**
* Checks if the customer on whose page we are currently on is registered,
* if not throws an exception.
*
* @return bool
*/
public function isRegistered()
{
$username = $this->getDocument()->find('css', 'table > tbody > tr > #username')->getText();
$username = $this->getDocument()->find('css', '#username')->getText();
if ($email === $username) {
return true;
return '' != $username;
}
/**
* Deletes the user on whose show page we are currently on.
*
* @throws \Exception
*/
public function deleteAccount()
{
$deleteButton = $this->getDocument()->find('css', '.delete-action-form');
if (null === $deleteButton) {
throw new \Exception('Element not found.');
}
return false;
$deleteButton->press();
$confirmationModal = $this->getDocument()->find('css', '#confirmation-modal-confirm');
$this->waitForModalToAppear($confirmationModal);
$confirmationModal->find('css', 'a:contains("Delete")')->press();
}
}

View file

@ -1,41 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Behat\Page\Customer;
use Sylius\Behat\SymfonyPageObjectExtension\PageObject\SymfonyPage;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class CustomersIndexPage extends SymfonyPage
{
/**
* @return string
*/
public function getRouteName()
{
return 'sylius_backend_customer_index';
}
/**
* @param $email
*/
public function deleteUser($email)
{
$this->getDocument()->find('css', 'table > tbody > tr:contains("'.$email.'")')->pressButton('Delete');
$this->getSession()->wait(10);
$confirmationModal = $this->getDocument()->find('css', '#confirmation-modal-confirm');
$confirmationModal->find('css', 'a:contains("Delete")')->press();
}
}

View file

@ -11,6 +11,7 @@
namespace Sylius\Behat\Page;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session;
use Symfony\Component\Routing\RouterInterface;
@ -65,6 +66,16 @@ abstract class SymfonyPage extends Page
return 0 !== strpos($path, 'http') ? $baseUrl.ltrim($path, '/') : $path;
}
/**
* @param NodeElement $modalContainer
*/
protected function waitForModalToAppear(NodeElement $modalContainer)
{
$this->getDocument()->waitFor(1, function () use ($modalContainer) {
return false !== strpos($modalContainer->getAttribute('class'), 'in');
});
}
/**
* {@inheritdoc}
*

View file

@ -20,7 +20,7 @@ use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
@ -28,7 +28,7 @@ use Sylius\Component\Resource\Repository\RepositoryInterface;
class UserContextSpec extends ObjectBehavior
{
function let(
RepositoryInterface $userRepository,
UserRepositoryInterface $userRepository,
SharedStorageInterface $sharedStorage,
TestUserFactory $userFactory,
FactoryInterface $addressFactory,
@ -53,18 +53,18 @@ class UserContextSpec extends ObjectBehavior
$this->shouldImplement(Context::class);
}
function it_creates_user_with_given_credentials_and_default_data(
function it_creates_user_with_given_email_and_default_data(
$sharedStorage,
$userFactory,
$userRepository,
UserInterface $user
) {
$userFactory->create('test@example.com', 'pa$$word')->willReturn($user);
$userFactory->create('test@example.com', 'pswd')->willReturn($user);
$sharedStorage->set('user', $user)->shouldBeCalled();
$userRepository->add($user)->shouldBeCalled();
$this->thereIsUserIdentifiedBy('test@example.com', 'pa$$word');
$this->thereIsUserIdentifiedBy('test@example.com', 'pswd');
}
function it_creates_user_with_given_credentials_default_data_and_shipping_address(
@ -126,4 +126,20 @@ class UserContextSpec extends ObjectBehavior
$this->myDefaultShippingAddressIs('United Kingdom');
}
function it_deletes_user_account(
$sharedStorage,
$userRepository,
UserInterface $user,
CustomerInterface $customer
) {
$userRepository->findOneByEmail('ted@test.com')->willReturn($user);
$user->getCustomer()->willReturn($customer);
$sharedStorage->set('customer', $customer)->shouldBeCalled();
$userRepository->remove($user)->shouldBeCalled();
$this->accountWasDeleted('ted@test.com');
}
}

View file

@ -11,23 +11,23 @@
namespace spec\Sylius\Behat\Context\Ui;
use Behat\Mink\Mink;
use Behat\Mink\WebAssert;
use Behat\Behat\Context\Context;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory;
use Sylius\Behat\Context\FeatureContext;
use Sylius\Behat\Page\Cart\CartSummaryPage;
use Sylius\Behat\Page\Customer\CustomerShowPage;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class CustomerContextSpec extends ObjectBehavior
{
function let(Factory $pageObjectFactory, Mink $mink)
{
$this->setPageObjectFactory($pageObjectFactory);
$this->setMink($mink);
public function let(
SharedStorageInterface $sharedStorage,
CustomerShowPage $customerShowPage
) {
$this->beConstructedWith($sharedStorage, $customerShowPage);
}
function it_is_initializable()
@ -35,17 +35,41 @@ class CustomerContextSpec extends ObjectBehavior
$this->shouldHaveType('Sylius\Behat\Context\Ui\CustomerContext');
}
function it_is_feature_context()
function it_implements_context_interface()
{
$this->shouldHaveType(FeatureContext::class);
$this->shouldImplement(Context::class);
}
function it_checks_if_cart_has_given_total($pageObjectFactory, $mink, CartSummaryPage $customersIndexPage, WebAssert $assert)
{
$pageObjectFactory->createPage('Customer\CustomersIndexPage')->willReturn($customersIndexPage);
$customersIndexPage->open()->shouldBeCalled();
function it_ensures_customer_is_not_deleted_again(
CustomerShowPage $customerShowPage,
SharedStorageInterface $sharedStorage,
CustomerInterface $customer
) {
$sharedStorage->get('customer')->willReturn($customer);
$mink->assertSession(null)->willReturn($assert);
$assert->elementTextContains('css', 'data-customer', Argument::type('string'))->shouldBeCalled();
$customer->getId()->willReturn(1);
$customerShowPage->open(['id' => 1])->shouldBeCalled();
$customerShowPage->deleteAccount()->willThrow(new \Exception('Element not found.'));
$this->iShouldNotBeAbleToDeleteCustomerAgain();
}
function it_checks_if_customer_still_exists(
CustomerShowPage $customerShowPage,
SharedStorageInterface $sharedStorage,
CustomerInterface $customer,
UserInterface $user
) {
$sharedStorage->get('deleted_user')->shouldBeCalled()->willReturn($user);
$user->getCustomer()->willReturn($customer);
$customer->getId()->willReturn(1);
$customerShowPage->open(['id' => 1])->shouldBeCalled();
$customerShowPage->isRegistered()->willReturn(false);
$this->customerShouldStillExist();
}
}

View file

@ -13,16 +13,26 @@ namespace spec\Sylius\Behat\Context\Ui;
use Behat\Behat\Context\Context;
use PhpSpec\ObjectBehavior;
use Sylius\Behat\Page\Customer\CustomerShowPage;
use Sylius\Behat\Page\User\LoginPage;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\User\Model\CustomerInterface;
use Sylius\Component\User\Model\UserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
*/
class UserContextSpec extends ObjectBehavior
{
function let(LoginPage $loginPage)
{
$this->beConstructedWith($loginPage);
public function let(
SharedStorageInterface $sharedStorage,
UserRepositoryInterface $userRepository,
CustomerShowPage $customerShowPage,
LoginPage $loginPage
) {
$this->beConstructedWith($sharedStorage, $userRepository, $customerShowPage, $loginPage);
}
function it_is_initializable()
@ -42,4 +52,55 @@ class UserContextSpec extends ObjectBehavior
$this->iLogInAs('john.doe@example.com', 'password123');
}
function it_deletes_account(
$userRepository,
$customerShowPage,
$sharedStorage,
UserInterface $user,
CustomerInterface $customer
) {
$userRepository->findOneByEmail('theodore@test.com')->willReturn($user);
$sharedStorage->set('deleted_user', $user)->shouldBeCalled();
$user ->getCustomer()->willReturn($customer);
$customer->getId()->willReturn(1);
$customerShowPage->open(['id' => 1])->shouldBeCalled();
$customerShowPage->deleteAccount()->shouldBeCalled();
$this->iDeleteAccount('theodore@test.com');
}
function it_does_not_allow_deleting_my_own_account(
SharedStorageInterface $sharedStorage, UserInterface $admin, CustomerShowPage $customerShowPage
) {
$sharedStorage->get('admin')->willReturn($admin);
$admin->getId()->willReturn(1);
$customerShowPage->open(['id' => 1])->shouldBeCalled();
$this->iTryDeletingMyOwnAccount();
$customerShowPage->deleteAccount()->willThrow(new \Exception('Element not found.'));
$this->iShouldNotBeAbleToDeleteMyOwnAccount();
}
function it_checks_if_account_was_deleted(
SharedStorageInterface $sharedStorage,
UserInterface $user,
CustomerInterface $customer,
CustomerShowPage $customerShowPage
) {
$sharedStorage->get('deleted_user')->willReturn($user);
$user->getCustomer()->willReturn($customer);
$customer->getId()->willReturn(1);
$customerShowPage->open(['id' => 1])->shouldBeCalled();
$customerShowPage->isRegistered()->willReturn(false);
$this->accountShouldBeDeleted();
}
}

View file

@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace spec\Sylius\Behat\Page\Customer;
use Behat\Mink\Session;
use PhpSpec\ObjectBehavior;
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory;
use Sylius\Behat\Page\SymfonyPage;
use Symfony\Component\Routing\RouterInterface;
/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class CustomerShowPageSpec extends ObjectBehavior
{
function let(Session $session, RouterInterface $router)
{
$this->beConstructedWith($session, [], $router);
}
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Behat\Page\Customer\CustomerShowPage');
}
function it_is_symfony_page()
{
$this->shouldHaveType(SymfonyPage::class);
}
function it_has_route_name()
{
$this->getRouteName()->shouldReturn('sylius_backend_customer_show');
}
}

View file

@ -17,13 +17,17 @@ use Symfony\Component\Security\Core\User\UserInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class TestUserFactory implements TestUserFactoryInterface
{
const DEFAULT_USER_EMAIL = 'john.doe@example.com';
const DEFAULT_ADMIN_EMAIL = 'admin@example.com';
const DEFAULT_USER_FIRST_NAME = 'John';
const DEFAULT_USER_LAST_NAME = 'Doe';
const DEFAULT_USER_PASSWORD = 'password123';
const DEFAULT_USER_ROLE = 'ROLE_USER';
const DEFAULT_ADMIN_ROLE = 'ROLE_ADMINISTRATION_ACCESS';
/**
* @var FactoryInterface
@ -48,7 +52,7 @@ class TestUserFactory implements TestUserFactoryInterface
/**
* {@inheritdoc}
*/
public function create($email, $password, $firstName = self::DEFAULT_USER_FIRST_NAME, $lastName = self::DEFAULT_USER_LAST_NAME)
public function create($email, $password, $firstName = self::DEFAULT_USER_FIRST_NAME, $lastName = self::DEFAULT_USER_LAST_NAME, $role = self::DEFAULT_USER_ROLE)
{
$customer = $this->customerFactory->createNew();
@ -62,12 +66,13 @@ class TestUserFactory implements TestUserFactoryInterface
$user->setEmail($email);
$user->setPlainPassword($password);
$user->enable();
$user->addRole($role);
return $user;
}
/**
* @return UserInterface
* {@inheritdoc}
*/
public function createDefault()
{
@ -75,7 +80,22 @@ class TestUserFactory implements TestUserFactoryInterface
self::DEFAULT_USER_EMAIL,
self::DEFAULT_USER_PASSWORD,
self::DEFAULT_USER_FIRST_NAME,
self::DEFAULT_USER_LAST_NAME
self::DEFAULT_USER_LAST_NAME,
self::DEFAULT_USER_ROLE
);
}
/**
* {@inheritdoc}
*/
public function createDefaultAdmin()
{
return $this->create(
self::DEFAULT_ADMIN_EMAIL,
self::DEFAULT_USER_PASSWORD,
self::DEFAULT_USER_FIRST_NAME,
self::DEFAULT_USER_LAST_NAME,
self::DEFAULT_ADMIN_ROLE
);
}
}

View file

@ -19,6 +19,7 @@ use Sylius\Component\Resource\Factory\FactoryInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
class TestUserFactorySpec extends ObjectBehavior
{
@ -54,6 +55,7 @@ class TestUserFactorySpec extends ObjectBehavior
$user->setEmail('oliver.queen@star.com')->shouldBeCalled();
$user->setPlainPassword('a££ow')->shouldBeCalled();
$user->enable()->shouldBeCalled();
$user->addRole('ROLE_USER')->shouldBeCalled();
$this->create('oliver.queen@star.com', 'a££ow', 'Oliver', 'Queen')->shouldReturn($user);
}
@ -75,7 +77,30 @@ class TestUserFactorySpec extends ObjectBehavior
$user->setEmail('john.doe@example.com')->shouldBeCalled();
$user->setPlainPassword('password123')->shouldBeCalled();
$user->enable()->shouldBeCalled();
$user->addRole('ROLE_USER')->shouldBeCalled();
$this->createDefault()->shouldReturn($user);
}
function it_creates_default_admin(
$customerFactory,
$userFactory,
CustomerInterface $customer,
UserInterface $admin
) {
$customerFactory->createNew()->willReturn($customer);
$customer->setFirstName('John')->shouldBeCalled();
$customer->setLastName('Doe')->shouldBeCalled();
$userFactory->createNew()->willReturn($admin);
$admin->setCustomer($customer)->shouldBeCalled();
$admin->setUsername('admin@example.com')->shouldBeCalled();
$admin->setEmail('admin@example.com')->shouldBeCalled();
$admin->setPlainPassword('password123')->shouldBeCalled();
$admin->enable()->shouldBeCalled();
$admin->addRole('ROLE_ADMINISTRATION_ACCESS')->shouldBeCalled();
$this->createDefaultAdmin()->shouldReturn($admin);
}
}

View file

@ -14,7 +14,7 @@
{% block content %}
<div class="page-header">
<div class="actions-menu">
{% if customer.user is not null and customer.user is not null and customer.user.id is not same as(app.user.id)%}
{% if customer.user is not null and customer.user.id is not same as(app.user.id)%}
{{ buttons.generic(path('sylius_account_profile_show', {'_switch_user': customer.user.username}), 'sylius.user.impersonate'|trans) }}
{% endif %}
{{ buttons.manage(path('sylius_backend_customer_index'), 'sylius.customer.manage'|trans) }}

View file

@ -15,6 +15,7 @@ use Sylius\Component\Core\Model\UserInterface;
/**
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
*/
interface TestUserFactoryInterface
{
@ -23,13 +24,19 @@ interface TestUserFactoryInterface
* @param string $password
* @param string $firstName
* @param string $lastName
* @param string $role
*
* @return UserInterface
*/
public function create($email, $password, $firstName, $lastName);
public function create($email, $password, $firstName, $lastName, $role);
/**
* @return UserInterface
*/
public function createDefault();
/**
* @return UserInterface
*/
public function createDefaultAdmin();
}

View file

@ -13,7 +13,6 @@ namespace Sylius\Component\User\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\SoftDeletableTrait;
use Sylius\Component\Resource\Model\TimestampableTrait;
/**

View file

@ -12,7 +12,6 @@
namespace Sylius\Component\User\Model;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\SoftDeletableInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
/**

View file

@ -13,7 +13,6 @@ namespace Sylius\Component\User\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\SoftDeletableTrait;
use Sylius\Component\Resource\Model\TimestampableTrait;
use Sylius\Component\Resource\Model\ToggleableTrait;

View file

@ -13,7 +13,6 @@ namespace Sylius\Component\User\Model;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\SoftDeletableInterface;
use Sylius\Component\Resource\Model\TimestampableInterface;
use Sylius\Component\Resource\Model\ToggleableInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;