Review fixes

This commit is contained in:
Arminek 2016-08-11 02:40:53 +02:00
parent 83212f1ed0
commit db3ca6a44e
30 changed files with 135 additions and 111 deletions

View file

@ -4,9 +4,9 @@
security:
providers:
sylius_admin_user_provider:
id: sylius.admin_user.provider.name_based
id: sylius.admin_user.provider.email_or_name_based
sylius_shop_user_provider:
id: sylius.shop_user.provider.name_based
id: sylius.shop_user.provider.email_or_name_based
encoders:
Sylius\Component\User\Model\UserInterface: sha512
firewalls:

View file

@ -6,7 +6,7 @@ Feature: Viewing payment's amount on my account panel
Background:
Given the store operates on a single channel in "France"
And there is user "lucy@teamlucifer.com" identified by "dantesdreams"
And there is a user "lucy@teamlucifer.com" identified by "dantesdreams"
And the store has a product "Angel T-Shirt" priced at "39.00"
And the store has a product "Angel Mug" priced at "19.00"
But the store has "DHL" shipping method with "8.60" fee

View file

@ -9,7 +9,7 @@ Feature: Account registration
@ui
Scenario: Trying to register a new account with email that has been already used
Given there is user "goodman@gmail.com" identified by "heisenberg"
Given there is a user "goodman@gmail.com" identified by "heisenberg"
And I want to register a new account
When I specify the email as "goodman@gmail.com"
And I try to register this account

View file

@ -6,7 +6,7 @@ Feature: Resetting a password
Background:
Given the store operates on a single channel in "France"
And there is user "goodman@example.com" identified by "heisenberg"
And there is a user "goodman@example.com" identified by "heisenberg"
@ui @email
Scenario: Resetting an account password

View file

@ -6,7 +6,7 @@ Feature: Sign in to the store
Background:
Given the store operates on a single channel in "France"
And there is user "ted@example.com" identified by "bear"
And there is a user "ted@example.com" identified by "bear"
@ui
Scenario: Sign in with email and password

View file

@ -6,7 +6,7 @@ Feature: Sign in to the store
Background:
Given the store operates on a single channel in "France"
And there is user "ted@example.com" identified by "bear"
And there is a user "ted@example.com" identified by "bear"
And there is an administrator "admin@example.com" identified by "sylius"
@ui

View file

@ -7,7 +7,7 @@ Feature: Maintaining cart after authorization
Background:
Given the store operates on a single channel in "France"
And the store has a product "Stark T-shirt" priced at "12.00"
And there is user "robb@stark.com" identified by "KingInTheNorth"
And there is a user "robb@stark.com" identified by "KingInTheNorth"
@ui
Scenario: Having cart maintained after logging in

View file

@ -6,7 +6,7 @@ Feature: Changing the method after order confirmation
Background:
Given the store operates on a single channel in "France"
And there is user "john@example.com" identified by "password123"
And there is a user "john@example.com" identified by "password123"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying "PayPal Express Checkout"

View file

@ -6,7 +6,7 @@ Feature: Paying with paypal during checkout
Background:
Given the store operates on a single channel in "France"
And there is user "john@example.com" identified by "password123"
And there is a user "john@example.com" identified by "password123"
And the store has a product "PHP T-Shirt" priced at "$19.99"
And the store ships everywhere for free
And the store allows paying "PayPal Express Checkout"

View file

@ -6,7 +6,7 @@ Feature: Retrying to pay the order from my account panel
Background:
Given the store operates on a single channel in "France"
And there is user "john@example.com" identified by "password123"
And there is a user "john@example.com" identified by "password123"
And the store allows paying "PayPal Express Checkout"
And the store ships everywhere for free
And I have one unpaid order #000001 with total $29.99

View file

@ -5,7 +5,7 @@ Feature: Deleting the user account
I want to be able to remove customer account details from the system
Background:
Given there is user "theodore@example.com" identified by "pswd"
Given there is a user "theodore@example.com" identified by "pswd"
And I am logged in as an administrator
@ui @javascript

View file

@ -35,29 +35,29 @@ final class AdminSecurityContext implements Context
/**
* @var TestUserFactoryInterface
*/
private $testAdminUserFactory;
private $testUserFactory;
/**
* @var UserRepositoryInterface
*/
private $adminUserRepository;
private $userRepository;
/**
* @param SharedStorageInterface $sharedStorage
* @param SecurityServiceInterface $securityService
* @param TestUserFactoryInterface $testAdminUserFactory
* @param UserRepositoryInterface $adminUserRepository
* @param TestUserFactoryInterface $testUserFactory
* @param UserRepositoryInterface $userRepository
*/
public function __construct(
SharedStorageInterface $sharedStorage,
SecurityServiceInterface $securityService,
TestUserFactoryInterface $testAdminUserFactory,
UserRepositoryInterface $adminUserRepository
TestUserFactoryInterface $testUserFactory,
UserRepositoryInterface $userRepository
) {
$this->sharedStorage = $sharedStorage;
$this->securityService = $securityService;
$this->testAdminUserFactory = $testAdminUserFactory;
$this->adminUserRepository = $adminUserRepository;
$this->testUserFactory = $testUserFactory;
$this->userRepository = $userRepository;
}
/**
@ -65,11 +65,11 @@ final class AdminSecurityContext implements Context
*/
public function iAmLoggedInAsAnAdministrator()
{
$adminUser = $this->testAdminUserFactory->createDefault();
$this->adminUserRepository->add($adminUser);
$user = $this->testUserFactory->createDefault();
$this->userRepository->add($user);
$this->securityService->logIn($adminUser);
$this->securityService->logIn($user);
$this->sharedStorage->set('admin', $adminUser);
$this->sharedStorage->set('admin', $user);
}
}

View file

@ -19,7 +19,7 @@ use Sylius\Component\User\Repository\UserRepositoryInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class AdminUserContext implements Context
final class AdminUserContext implements Context
{
/**
* @var SharedStorageInterface
@ -29,26 +29,26 @@ class AdminUserContext implements Context
/**
* @var TestUserFactoryInterface
*/
private $adminTestUserFactory;
private $testUserFactory;
/**
* @var UserRepositoryInterface
*/
private $adminUserRepository;
private $userRepository;
/**
* @param SharedStorageInterface $sharedStorage
* @param TestUserFactoryInterface $adminTestUserFactory
* @param UserRepositoryInterface $adminUserRepository
* @param TestUserFactoryInterface $testUserFactory
* @param UserRepositoryInterface $userRepository
*/
public function __construct(
SharedStorageInterface $sharedStorage,
TestUserFactoryInterface $adminTestUserFactory,
UserRepositoryInterface $adminUserRepository
TestUserFactoryInterface $testUserFactory,
UserRepositoryInterface $userRepository
) {
$this->sharedStorage = $sharedStorage;
$this->adminTestUserFactory = $adminTestUserFactory;
$this->adminUserRepository = $adminUserRepository;
$this->testUserFactory = $testUserFactory;
$this->userRepository = $userRepository;
}
/**
@ -56,8 +56,8 @@ class AdminUserContext implements Context
*/
public function thereIsAnAdministratorIdentifiedBy($email, $password)
{
$adminUser = $this->adminTestUserFactory->create($email, $password);
$this->adminUserRepository->add($adminUser);
$adminUser = $this->testUserFactory->create($email, $password);
$this->userRepository->add($adminUser);
$this->sharedStorage->set('administrator', $adminUser);
}
}

View file

@ -36,52 +36,52 @@ final class ShopSecurityContext implements Context
/**
* @var TestUserFactoryInterface
*/
private $testShopUserFactory;
private $testUserFactory;
/**
* @var UserRepositoryInterface
*/
private $shopUserRepository;
private $userRepository;
/**
* @param SharedStorageInterface $sharedStorage
* @param SecurityServiceInterface $securityService
* @param TestUserFactoryInterface $testAdminUserFactory
* @param UserRepositoryInterface $shopUserRepository
* @param TestUserFactoryInterface $testUserFactory
* @param UserRepositoryInterface $userRepository
*/
public function __construct(
SharedStorageInterface $sharedStorage,
SecurityServiceInterface $securityService,
TestUserFactoryInterface $testAdminUserFactory,
UserRepositoryInterface $shopUserRepository
TestUserFactoryInterface $testUserFactory,
UserRepositoryInterface $userRepository
) {
$this->sharedStorage = $sharedStorage;
$this->securityService = $securityService;
$this->testShopUserFactory = $testAdminUserFactory;
$this->shopUserRepository = $shopUserRepository;
$this->testUserFactory = $testUserFactory;
$this->userRepository = $userRepository;
}
/**
* @Given /^I am logged in as "([^""]+)"$/
* @Given I am logged in as :email
*/
public function iAmLoggedInAs($email)
{
$shopUser = $this->shopUserRepository->findOneByEmail($email);
Assert::notNull($shopUser);
$user = $this->userRepository->findOneByEmail($email);
Assert::notNull($user);
$this->securityService->logIn($shopUser);
$this->securityService->logIn($user);
}
/**
* @Given /^I am a logged in customer$/
* @Given I am a logged in customer
*/
public function iAmLoggedInCustomer()
{
$shopUser = $this->testShopUserFactory->createDefault();
$this->shopUserRepository->add($shopUser);
$user = $this->testUserFactory->createDefault();
$this->userRepository->add($user);
$this->securityService->logIn($shopUser);
$this->securityService->logIn($user);
$this->sharedStorage->set('user', $shopUser);
$this->sharedStorage->set('user', $user);
}
}

View file

@ -82,7 +82,7 @@ final class UserContext implements Context
}
/**
* @Given there is user :email identified by :password
* @Given there is a user :email identified by :password
* @Given there was account of :email with password :password
* @Given there is a user :email
* @Given there is a :email user

View file

@ -19,7 +19,7 @@ use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class LoginContext implements Context
final class LoginContext implements Context
{
/**
* @var DashboardPageInterface

View file

@ -24,7 +24,7 @@ use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class LoginContext implements Context
final class LoginContext implements Context
{
/**
* @var HomePageInterface

View file

@ -66,7 +66,7 @@ class SyliusApiExtension extends AbstractResourceExtension implements PrependExt
'auth_code_class' => $resourcesConfig['api_auth_code']['classes']['model'],
'service' => [
'user_provider' => 'sylius.admin_user.provider.name_based',
'user_provider' => 'sylius.admin_user.provider.email_or_name_based',
'client_manager' => 'sylius.oauth_server.client_manager',
],
]);

View file

@ -47,6 +47,7 @@ class CanonicalizerListener
$item->setEmailCanonical($this->canonicalizer->canonicalize($item->getEmail()));
} elseif ($item instanceof UserInterface) {
$item->setUsernameCanonical($this->canonicalizer->canonicalize($item->getUsername()));
$item->setEmailCanonical($this->canonicalizer->canonicalize($item->getEmail()));
}
}

View file

@ -759,12 +759,6 @@ sylius_user:
model: Sylius\Component\User\Model\UserOAuth
interface: Sylius\Component\User\Model\UserOAuthInterface
controller: Sylius\Bundle\ResourceBundle\Controller\ResourceController
shop_oauth:
user:
classes:
model: Sylius\Component\User\Model\UserOAuth
interface: Sylius\Component\User\Model\UserOAuthInterface
controller: Sylius\Bundle\ResourceBundle\Controller\ResourceController
sylius_customer:
resources:

View file

@ -20,11 +20,11 @@
<service id="sylius.oauth.user_provider" class="%sylius.oauth.user_provider.class%" lazy="true">
<argument type="service" id="sylius.factory.customer" />
<argument type="service" id="sylius.repository.customer" />
<argument type="service" id="sylius.factory.shop_user" />
<argument type="service" id="sylius.repository.shop_user" />
<argument type="service" id="sylius.factory.shop_user_oauth" />
<argument type="service" id="sylius.repository.shop_user_oauth" />
<argument type="service" id="sylius.manager.shop_user" />
<argument type="service" id="sylius.factory.admin_user" />
<argument type="service" id="sylius.repository.admin_user" />
<argument type="service" id="sylius.factory.admin_user_oauth" />
<argument type="service" id="sylius.repository.admin_user_oauth" />
<argument type="service" id="sylius.manager.admin_user" />
<argument type="service" id="sylius.user.canonicalizer" />
</service>
</services>

View file

@ -32,7 +32,6 @@
<argument type="service" id="sylius.factory.shop_user" />
</service>
<service id="sylius.test.factory.admin_user" class="Sylius\Bundle\CoreBundle\Test\Factory\TestAdminUserFactory">
<argument type="service" id="sylius.factory.customer" />
<argument type="service" id="sylius.factory.admin_user" />
</service>

View file

@ -29,15 +29,14 @@ final class TestAdminUserFactory implements TestUserFactoryInterface
/**
* @var FactoryInterface
*/
private $adminUserFactory;
private $userFactory;
/**
* @param FactoryInterface $customerFactory
* @param FactoryInterface $adminUserFactory
* @param FactoryInterface $userFactory
*/
public function __construct(FactoryInterface $customerFactory, FactoryInterface $adminUserFactory)
public function __construct(FactoryInterface $userFactory)
{
$this->adminUserFactory = $adminUserFactory;
$this->userFactory = $userFactory;
}
/**
@ -46,9 +45,9 @@ final class TestAdminUserFactory implements TestUserFactoryInterface
public function create($email, $password, $firstName = self::DEFAULT_FIRST_NAME, $lastName = self::DEFAULT_LAST_NAME, $role = self::DEFAULT_ROLE)
{
/** @var AdminUser $user */
$user = $this->adminUserFactory->createNew();
$user = $this->userFactory->createNew();
$user->setUsername($email);
$user->setUsername($firstName.' '.$lastName);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->enable();

View file

@ -37,9 +37,12 @@ final class CanonicalizerListenerSpec extends ObjectBehavior
{
$event->getEntity()->willReturn($user);
$user->getUsername()->willReturn('testUser');
$user->getEmail()->willReturn('test@email.com');
$user->setUsernameCanonical('testuser')->shouldBeCalled();
$user->setEmailCanonical('test@email.com')->shouldBeCalled();
$canonicalizer->canonicalize('testUser')->willReturn('testuser')->shouldBeCalled();
$canonicalizer->canonicalize('test@email.com')->willReturn('test@email.com')->shouldBeCalled();
$this->prePersist($event);
}
@ -59,9 +62,12 @@ final class CanonicalizerListenerSpec extends ObjectBehavior
{
$event->getEntity()->willReturn($user);
$user->getUsername()->willReturn('testUser');
$user->getEmail()->willReturn('test@email.com');
$user->setUsernameCanonical('testuser')->shouldBeCalled();
$user->setEmailCanonical('test@email.com')->shouldBeCalled();
$canonicalizer->canonicalize('testUser')->willReturn('testuser')->shouldBeCalled();
$canonicalizer->canonicalize('test@email.com')->willReturn('test@email.com')->shouldBeCalled();
$this->preUpdate($event);
}

View file

@ -70,7 +70,7 @@ class UserController extends ResourceController
public function requestPasswordResetPinAction(Request $request)
{
$generator = $this->container->get(sprintf('sylius.user.generator.password_reset_pin', $this->metadata->getName()));
$generator = $this->container->get(sprintf('sylius.%s.generator.password_reset_pin', $this->metadata->getName()));
return $this->prepareResetPasswordRequest($request, $generator, UserEvents::REQUEST_RESET_PASSWORD_PIN);
}

View file

@ -52,20 +52,12 @@ class SyliusUserExtension extends AbstractResourceExtension
$this->registerResources('sylius', $config['driver'], $this->resolveResources($config['resources'], $container), $container);
$configFiles = [
'services.xml',
];
foreach ($configFiles as $configFile) {
$loader->load($configFile);
}
$loader->load('services.xml');
$this->createServices($config['resources'], $config['driver'], $container);
}
/**
* Resolve resources for every subject.
*
* @param array $resources
* @param ContainerBuilder $container
*
@ -114,37 +106,54 @@ class SyliusUserExtension extends AbstractResourceExtension
{
$this->createUniquenessCheckers($userType, $config, $container);
$passwordResetTokenGeneratorDefinition = new Definition(UniqueTokenGenerator::class);
$passwordResetTokenGeneratorDefinition->addArgument(
new Reference(sprintf('sylius.%s_user.checker.token_uniqueness.password_reset', $userType))
);
$passwordResetTokenGeneratorDefinition->addArgument($config['resetting']['token']['length']);
$container->setDefinition(
sprintf('sylius.%s_user.generator.password_reset_token', $userType),
$passwordResetTokenGeneratorDefinition
$this->createTokenGeneratorDefinition(
UniqueTokenGenerator::class,
[
new Reference(sprintf('sylius.%s_user.checker.token_uniqueness.password_reset', $userType)),
$config['resetting']['token']['length']
]
)
);
$passwordResetPinGeneratorDefinition = new Definition(UniquePinGenerator::class);
$passwordResetPinGeneratorDefinition->addArgument(
new Reference(sprintf('sylius.%s_user.checker.pin_uniqueness.password_reset', $userType))
);
$passwordResetPinGeneratorDefinition->addArgument($config['resetting']['pin']['length']);
$container->setDefinition(
sprintf('sylius.%s_user.generator.password_reset_pin', $userType),
$passwordResetPinGeneratorDefinition
$this->createTokenGeneratorDefinition(
UniquePinGenerator::class,
[
new Reference(sprintf('sylius.%s_user.checker.pin_uniqueness.password_reset', $userType)),
$config['resetting']['pin']['length']
]
)
);
$emailVerificationTokenGeneratorDefinition = new Definition(UniqueTokenGenerator::class);
$emailVerificationTokenGeneratorDefinition->addArgument(
new Reference(sprintf('sylius.%s_user.checker.token_uniqueness.email_verification', $userType))
);
$emailVerificationTokenGeneratorDefinition->addArgument($config['verification']['token']['length']);
$container->setDefinition(
sprintf('sylius.%s_user.generator.email_verification_token', $userType),
$emailVerificationTokenGeneratorDefinition
$this->createTokenGeneratorDefinition(
UniqueTokenGenerator::class,
[
new Reference(sprintf('sylius.%s_user.checker.token_uniqueness.email_verification', $userType)),
$config['verification']['token']['length']
]
)
);
}
/**
* @param string $generatorClass
* @param array $arguments
*
* @return Definition
*/
private function createTokenGeneratorDefinition($generatorClass, array $arguments)
{
$generatorDefinition = new Definition($generatorClass);
$generatorDefinition->setArguments($arguments);
return $generatorDefinition;
}
/**
* @param string $userType
* @param array $config

View file

@ -13,6 +13,7 @@ namespace spec\Sylius\Component\Core\Model;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\AdminUser;
use Sylius\Component\Core\Model\AdminUserInterface;
use Sylius\Component\User\Model\User;
use Sylius\Component\User\Model\UserInterface;
@ -28,13 +29,18 @@ class AdminUserSpec extends ObjectBehavior
$this->shouldHaveType(AdminUser::class);
}
function it_implements_user_interface()
{
$this->shouldImplement(UserInterface::class);
}
function it_extends_base_user_model()
{
$this->shouldHaveType(User::class);
}
function it_implements_admin_user_interface()
{
$this->shouldImplement(AdminUserInterface::class);
}
function it_implements_user_interface()
{
$this->shouldImplement(UserInterface::class);
}
}

View file

@ -176,7 +176,7 @@ class User implements UserInterface
*/
public function setEmailCanonical($emailCanonical)
{
$this->emailCanonical;
$this->emailCanonical = $emailCanonical;
}
/**

View file

@ -25,7 +25,7 @@ final class UserSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Sylius\Component\User\Model\User');
$this->shouldHaveType(User::class);
}
function it_implements_user_interface()
@ -82,4 +82,13 @@ final class UserSpec extends ObjectBehavior
$this->isPasswordRequestNonExpired($ttl)->shouldReturn(false);
}
function it_has_email_and_email_canonical()
{
$this->setEmail('admin@example.com');
$this->setEmailCanonical('user@example.com');
$this->getEmail()->shouldReturn('admin@example.com');
$this->getEmailCanonical()->shouldReturn('user@example.com');
}
}

View file

@ -21,4 +21,5 @@ Sylius\Component\Core\Model\AdminUser:
plainPassword: sylius
roles: [ROLE_API_ACCESS]
enabled: true
username: api@sylius.com
email: api@sylius.com
username: sylius