/** * @Given I am logged in as an administrator */ public function iAmLoggedInAsAnAdministrator() { $admin = $this->testUserFactory->createDefaultAdmin(); $this->userRepository->add($admin); $this->securityService->logIn($admin->getEmail()); $this->sharedStorage->set('admin', $admin); }
/** * @Given /^I am logged in as "([^"]+)" administrator$/ */ public function iAmLoggedInAsAdministrator($email) { $user = $this->userRepository->findOneByEmail($email); Assert::notNull($user); $this->securityService->logIn($user); $this->sharedStorage->set('admin', $user); }
/** * @Given I am a logged in customer */ public function iAmLoggedInCustomer() { $user = $this->userFactory->create(['email' => '*****@*****.**', 'password' => 'sylius', 'enabled' => true]); $this->userRepository->add($user); $this->securityService->logIn($user); $this->sharedStorage->set('user', $user); }
/** * @Given I am a logged in customer */ public function iAmLoggedInCustomer() { $user = $this->userFactory->create(); $this->userRepository->add($user); $this->securityService->logIn($user); $this->sharedStorage->set('user', $user); }
function it_performs_action_as_given_admin_user_and_logout(SecurityServiceInterface $adminSecurityService, OrderInterface $order, AdminUserInterface $adminUser) { $adminSecurityService->getCurrentToken()->willThrow(TokenNotFoundException::class); $adminSecurityService->logIn($adminUser)->shouldBeCalled(); $order->completeCheckout()->shouldBeCalled(); $adminSecurityService->restoreToken(Argument::any())->shouldNotBeCalled(); $adminSecurityService->logOut()->shouldBeCalled(); $wrappedOrder = $order->getWrappedObject(); $this->performActionAsAdminUser($adminUser, function () use($wrappedOrder) { $wrappedOrder->completeCheckout(); }); }
/** * @param SecurityServiceInterface $securityService * @param UserInterface $user * @param callable $action */ private function performActionAs(SecurityServiceInterface $securityService, UserInterface $user, callable $action) { try { $token = $securityService->getCurrentToken(); } catch (TokenNotFoundException $exception) { $token = null; } $securityService->logIn($user); $action(); if (null === $token) { $securityService->logOut(); return; } $securityService->restoreToken($token); }
/** * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/ */ public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(UserInterface $user, $note, OrderInterface $order) { $this->securityService->performActionAs($user, function () use($note, $order) { $this->showPage->open(['id' => $order->getId()]); Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note)); }); }
/** * @Given /^(this user) bought this product$/ */ public function thisUserBought(UserInterface $user) { $this->securityService->performActionAs($user, function () { $this->iProceedSelectingPaymentMethod(); $this->iConfirmMyOrder(); }); }
/** * @Then /^(my) account should be verified$/ */ public function myAccountShouldBeVerified(ShopUserInterface $user) { $this->securityService->logIn($user); Assert::true($this->dashboardPage->isVerified(), 'My account should be verified.'); }
/** * @Given /^(this user) has ("[^"]+" product) in the cart$/ */ public function thisUserHasProductInTheCart(UserInterface $user, ProductInterface $product) { $this->securityService->performActionAs($user, function () use($product) { $this->iAddProductToTheCart($product); }); }