/** * @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(); $this->userRepository->add($user); $this->securityService->logIn($user); $this->sharedStorage->set('user', $user); }
/** * @Given the store has static content :title with name :name */ public function theStoreHasStaticContentWithName($title, $name) { $staticContent = $this->staticContentExampleFactory->create(['title' => $title, 'name' => $name]); $this->staticContentManager->persist($staticContent); $this->staticContentManager->flush(); $this->sharedStorage->set('static_content', $staticContent); }
/** * @Given there is an administrator with name :username */ public function thereIsAnAdministratorWithName($username) { $adminUser = $this->userFactory->create(['username' => $username]); $adminUser->setUsername($username); $this->userRepository->add($adminUser); $this->sharedStorage->set('administrator', $adminUser); }
/** * @When I delete the account of :email user */ public function iDeleteAccount($email) { $user = $this->userRepository->findOneByEmail($email); $this->sharedStorage->set('deleted_user', $user); $this->customerShowPage->open(['id' => $user->getCustomer()->getId()]); $this->customerShowPage->deleteAccount(); }
/** * @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 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 the store has a product option :productOptionName with a code :productOptionCode */ public function theStoreHasAProductOptionWithACode($productOptionName, $productOptionCode) { $productOption = $this->productOptionFactory->createNew(); $productOption->setCode($productOptionCode); $productOption->setName($productOptionName); $this->sharedStorage->set('product_option', $productOption); $this->productOptionRepository->add($productOption); }
/** * @Given the store has route :name with :contentTitle as its content */ public function theStoreHasRouteWithAsItsContent($name, $contentTitle) { $content = $this->staticContentRepository->findOneBy(['title' => $contentTitle]); $route = $this->routeExampleFactory->create(['name' => $name, 'content' => $content]); $this->routeManager->persist($route); $this->routeManager->flush(); $this->sharedStorage->set('route', $route); }
/** * @When I set :channel channel theme to :theme */ public function iSetChannelThemeTo(ChannelInterface $channel, ThemeInterface $theme) { $this->channelUpdatePage->open(['id' => $channel->getId()]); $this->channelUpdatePage->setTheme($theme); $this->channelUpdatePage->saveChanges(); $this->sharedStorage->set('channel', $channel); $this->sharedStorage->set('theme', $theme); }
/** * @When /^I delete a ("([^"]+)" promotion)$/ * @When /^I try to delete a ("([^"]+)" promotion)$/ */ public function iTryToDeletePromotion(PromotionInterface $promotion) { try { $this->promotionRepository->remove($promotion); } catch (ForeignKeyConstraintViolationException $exception) { $this->sharedStorage->set('last_exception', $exception); } }
/** * @param string $name */ private function createCustomerGroup($name) { /** @var CustomerGroupInterface $customerGroup */ $customerGroup = $this->customerGroupFactory->createNew(); $customerGroup->setName(ucfirst($name)); $this->sharedStorage->set('customer_group', $customerGroup); $this->customerGroupRepository->add($customerGroup); }
/** * @When /^I delete the ("[^"]+" product)$/ * @When /^I try to delete the ("([^"]+)" product)$/ */ public function iDeleteTheProduct(ProductInterface $product) { try { $this->sharedStorage->set('product_id', $product->getId()); $this->productRepository->remove($product); } catch (DBALException $exception) { $this->sharedStorage->set('last_exception', $exception); } }
/** * @When I create a new channel :channelName */ public function iCreateNewChannel($channelName) { $this->channelCreatePage->open(); $this->channelCreatePage->nameIt($channelName); $this->channelCreatePage->specifyCode($channelName); $this->channelCreatePage->create(); $channel = $this->channelRepository->findOneBy(['name' => $channelName]); $this->sharedStorage->set('channel', $channel); }
/** * @param string $type * @param string $name * @param string|null $code */ private function createProductAttribute($type, $name, $code = null) { $productAttribute = $this->productAttributeFactory->createTyped($type); if (null === $code) { $code = StringInflector::nameToUppercaseCode($name); } $productAttribute->setCode($code); $productAttribute->setName($name); $this->productAttributeRepository->add($productAttribute); $this->sharedStorage->set('product_attribute', $productAttribute); }
/** * @When I delete the order :order */ public function iDeleteTheOrder(OrderInterface $order) { $adjustmentsId = []; foreach ($order->getAdjustments() as $adjustment) { $adjustmentsId[] = $adjustment->getId(); } $this->sharedStorage->set('deleted_adjustments', $adjustmentsId); $this->sharedStorage->set('deleted_addresses', [$order->getShippingAddress()->getId(), $order->getBillingAddress()->getId()]); $this->sharedStorage->set('order_id', $order->getId()); $this->orderRepository->remove($order); }
/** * @param string $type * @param string $name * @param string|null $code */ private function createProductAttribute($type, $name, $code = null) { $productAttribute = $this->productAttributeFactory->createTyped($type); if (null === $code) { $code = str_replace(' ', '_', strtoupper($name)); } $productAttribute->setCode($code); $productAttribute->setName($name); $this->productAttributeRepository->add($productAttribute); $this->sharedStorage->set('product_attribute', $productAttribute); }
/** * @param string $shippingCategoryName * @param string $shippingCategoryCode */ private function createShippingCategory($shippingCategoryName, $shippingCategoryCode = null) { /** @var ShippingCategoryInterface $shippingCategory */ $shippingCategory = $this->shippingCategoryFactory->createNew(); $shippingCategory->setName($shippingCategoryName); $shippingCategory->setCode($shippingCategoryCode); if (null === $shippingCategoryCode) { $shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName)); } $this->shippingCategoryRepository->add($shippingCategory); $this->sharedStorage->set('shipping_category', $shippingCategory); }
/** * @When I delete the order :order */ public function iDeleteTheOrder(OrderInterface $order) { /** @var OrderInterface $order */ $order = $this->orderRepository->findOneBy(['number' => $order->getNumber()]); if (null === $order) { throw new \InvalidArgumentException(sprintf('Order with %s number was not found in an order repository', $order->getNumber())); } $adjustmentsId = []; foreach ($order->getAdjustments() as $adjustment) { $adjustmentsId[] = $adjustment->getId(); } $this->sharedStorage->set('deleted_adjustments', $adjustmentsId); $this->sharedStorage->set('deleted_addresses', [$order->getShippingAddress()->getId(), $order->getBillingAddress()->getId()]); $this->orderRepository->remove($order); }
/** * @param string $name * @param string|null $code * @param int|null $position * @param ZoneInterface|null $zone * @param string $locale * @param array $configuration * @param string $calculator * @param bool $enabled * @param bool $addForCurrentChannel */ private function createShippingMethod($name, $code = null, $position = null, ZoneInterface $zone = null, $locale = 'en', $configuration = ['amount' => 0], $calculator = DefaultCalculators::FLAT_RATE, $enabled = true, $addForCurrentChannel = true) { if (null === $zone) { $zone = $this->sharedStorage->get('zone'); } if (null === $code) { $code = $this->generateCodeFromNameAndZone($name, $zone->getCode()); } /** @var ShippingMethodInterface $shippingMethod */ $shippingMethod = $this->shippingMethodFactory->createNew(); $shippingMethod->setCode($code); $shippingMethod->setName($name); $shippingMethod->setPosition($position); $shippingMethod->setCurrentLocale($locale); $shippingMethod->setConfiguration($configuration); $shippingMethod->setCalculator($calculator); $shippingMethod->setZone($zone); $shippingMethod->setEnabled($enabled); if ($addForCurrentChannel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); $channel->addShippingMethod($shippingMethod); } $this->shippingMethodRepository->add($shippingMethod); $this->sharedStorage->set('shipping_method', $shippingMethod); }
/** * @param UserInterface $user */ private function prepareUserVerification(UserInterface $user) { $token = 'marryhadalittlelamb'; $this->sharedStorage->set('verification_token', $token); $user->setEmailVerificationToken($token); $this->userManager->flush(); }
/** * @Given /^(I) placed (an order "[^"]+")$/ */ public function iPlacedAnOrder(UserInterface $user, $orderNumber) { $customer = $user->getCustomer(); $order = $this->createOrder($customer, $orderNumber); $this->sharedStorage->set('order', $order); $this->orderRepository->add($order); }
/** * @param string $name * @param string|null $code * @param int|null $position * @param ZoneInterface|null $zone * @param string $locale * @param array $configuration * @param string $calculator * @param bool $enabled * @param bool $addForCurrentChannel * @param array $channels * * @return ShippingMethodInterface */ private function createShippingMethod($name, $code = null, $position = null, ZoneInterface $zone = null, $locale = 'en', array $configuration = [], $calculator = DefaultCalculators::FLAT_RATE, $enabled = true, $addForCurrentChannel = true, array $channels = []) { $channel = $this->sharedStorage->get('channel'); if (null === $zone) { $zone = $this->sharedStorage->get('zone'); } if (null === $code) { $code = $this->generateCodeFromNameAndZone($name, $zone->getCode()); } if (empty($configuration)) { $configuration = $this->getConfigurationByChannels([$channel]); } /** @var ShippingMethodInterface $shippingMethod */ $shippingMethod = $this->shippingMethodFactory->createNew(); $shippingMethod->setCode($code); $shippingMethod->setName($name); $shippingMethod->setPosition($position); $shippingMethod->setCurrentLocale($locale); $shippingMethod->setConfiguration($configuration); $shippingMethod->setCalculator($calculator); $shippingMethod->setZone($zone); $shippingMethod->setEnabled($enabled); if ($addForCurrentChannel && $channel) { $shippingMethod->addChannel($channel); } if (!$addForCurrentChannel) { foreach ($channels as $channel) { $shippingMethod->addChannel($channel); } } $this->shippingMethodRepository->add($shippingMethod); $this->sharedStorage->set('shipping_method', $shippingMethod); return $shippingMethod; }
/** * @Then /^(this product) should have(?:| also) an image with a code "([^"]*)"$/ * @Then /^the (product "[^"]+") should have(?:| also) an image with a code "([^"]*)"$/ */ public function thisProductShouldHaveAnImageWithCode(ProductInterface $product, $code) { $this->sharedStorage->set('product', $product); /** @var UpdateSimpleProductPageInterface|UpdateConfigurableProductPageInterface $currentPage */ $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->updateSimpleProductPage, $this->updateConfigurableProductPage], $product); Assert::true($currentPage->isImageWithCodeDisplayed($code), sprintf('Image with a code %s should have been displayed.', $code)); }
/** * @Given the store has a zone :zoneName with code :code * @Given the store also has a zone :zoneName with code :code */ public function theStoreHasAZoneWithCode($zoneName, $code) { $zone = $this->zoneFactory->createTyped(ZoneInterface::TYPE_ZONE); $zone->setCode($code); $zone->setName($zoneName); $this->sharedStorage->set('zone', $zone); $this->zoneRepository->add($zone); }
/** * @When I want to modify the :product product * @When /^I want to modify (this product)$/ */ public function iWantToModifyAProduct(ProductInterface $product) { $this->sharedStorage->set('product', $product); if ($product->isSimple()) { $this->updateSimpleProductPage->open(['id' => $product->getId()]); return; } $this->updateConfigurableProductPage->open(['id' => $product->getId()]); }
/** * @Given /^(this country)(?:| also) has the "([^"]+)" province with "([^"]+)" code$/ * @Given /^(?:|the )(country "[^"]+") has the "([^"]+)" province with "([^"]+)" code$/ */ public function theCountryHasProvinceWithCode(CountryInterface $country, $name, $code) { /** @var ProvinceInterface $province */ $province = $this->provinceFactory->createNew(); $province->setName($name); $province->setCode($code); $country->addProvince($province); $this->sharedStorage->set('province', $province); $this->countryManager->flush(); }
/** * @Given the store has promotion :promotionName with coupon :couponCode * @Given the store has also promotion :promotionName with coupon :couponCode */ public function thereIsPromotionWithCoupon($promotionName, $couponCode) { /** @var CouponInterface $coupon */ $coupon = $this->couponFactory->createNew(); $coupon->setCode($couponCode); $promotion = $this->testPromotionFactory->createForChannel($promotionName, $this->sharedStorage->get('channel')); $promotion->addCoupon($coupon); $promotion->setCouponBased(true); $this->promotionRepository->add($promotion); $this->sharedStorage->set('promotion', $promotion); $this->sharedStorage->set('coupon', $coupon); }
/** * @param string $name * @param string|null $code */ private function createProductAssociationType($name, $code = null) { if (null === $code) { $code = $this->generateCodeFromName($name); } /** @var ProductAssociationTypeInterface $productAssociationType */ $productAssociationType = $this->productAssociationTypeFactory->createNew(); $productAssociationType->setCode($code); $productAssociationType->setName($name); $this->productAssociationTypeRepository->add($productAssociationType); $this->sharedStorage->set('product_association_type', $productAssociationType); }
/** * @param ProductInterface $product * @param $productVariantName * @param int $price * @param string $code * @param ChannelInterface $channel */ private function createProductVariant(ProductInterface $product, $productVariantName, $price, $code, ChannelInterface $channel = null) { $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_CHOICE); /** @var ProductVariantInterface $variant */ $variant = $this->productVariantFactory->createNew(); $variant->setName($productVariantName); $variant->setCode($code); $variant->setProduct($product); $variant->addChannelPricing($this->createChannelPricingForChannel($price, $channel)); $product->addVariant($variant); $this->objectManager->flush(); $this->sharedStorage->set('variant', $variant); }