From a5c15ba72488695a328916e24fe6eae32dda7819 Mon Sep 17 00:00:00 2001 From: Danijela Mikulicic Date: Tue, 12 Mar 2019 14:59:30 +0100 Subject: [PATCH 1/8] added test setup, added shipment test, fixed shipping method from bug, fixed typos, removed wrong validation --- behat.yml.dist | 2 +- composer.json | 5 +- ...g_pick_up_at_store_shipping_method.feature | 36 +++ phpspec.yml.dist | 4 +- src/Entity/IsPickupAtStoreInterface.php | 2 +- src/Fixture/StoreFactory.php | 81 ++++++ .../Checkout/ShipmentTypeExtension.php | 5 +- .../Extension/ShippingMethodTypeExtension.php | 8 +- src/Resources/config/services.yml | 6 + src/Resources/config/validation/Shipment.yml | 4 - src/Resources/translations/messages.en.yml | 2 +- src/Resources/translations/messages.hr.yml | 2 +- .../views/ShippingMethod/_form.html.twig | 2 +- tests/Behat/Context/Setup/ShippingContext.php | 173 +++++++++++++ .../Shop/Checkout/CheckoutShippingContext.php | 232 ++++++++++++++++++ .../Behat/Context/Ui/Shop/WelcomeContext.php | 80 ------ .../Page/Shop/Checkout/SelectShippingPage.php | 69 ++++++ .../Checkout/SelectShippingPageInterface.php | 14 ++ tests/Behat/Page/Shop/DynamicWelcomePage.php | 44 ---- tests/Behat/Page/Shop/StaticWelcomePage.php | 36 --- .../Behat/Page/Shop/WelcomePageInterface.php | 15 -- tests/Behat/Resources/services.xml | 16 -- tests/Behat/Resources/services.yml | 26 ++ tests/Behat/Resources/suites.yml | 61 ++++- 24 files changed, 709 insertions(+), 216 deletions(-) create mode 100644 features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature create mode 100644 src/Fixture/StoreFactory.php delete mode 100644 src/Resources/config/validation/Shipment.yml create mode 100644 tests/Behat/Context/Setup/ShippingContext.php create mode 100644 tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php delete mode 100644 tests/Behat/Context/Ui/Shop/WelcomeContext.php create mode 100644 tests/Behat/Page/Shop/Checkout/SelectShippingPage.php create mode 100644 tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php delete mode 100644 tests/Behat/Page/Shop/DynamicWelcomePage.php delete mode 100644 tests/Behat/Page/Shop/StaticWelcomePage.php delete mode 100644 tests/Behat/Page/Shop/WelcomePageInterface.php delete mode 100644 tests/Behat/Resources/services.xml create mode 100644 tests/Behat/Resources/services.yml diff --git a/behat.yml.dist b/behat.yml.dist index 01c63a7..72ba728 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -7,7 +7,7 @@ default: FriendsOfBehat\ContextServiceExtension: imports: - vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml - - tests/Behat/Resources/services.xml + - tests/Behat/Resources/services.yml FriendsOfBehat\SymfonyExtension: kernel: diff --git a/composer.json b/composer.json index 118595f..39802d4 100644 --- a/composer.json +++ b/composer.json @@ -32,13 +32,14 @@ "phpunit/phpunit": "^6.5", "se/selenium-server-standalone": "^2.52", "sylius-labs/coding-standard": "^2.0", - "symplify/easy-coding-standard": "^4.6" + "symplify/easy-coding-standard": "^4.6", + "behat/symfony2-extension": "^2.1" }, "prefer-stable": true, "autoload": { "psr-4": { "Locastic\\SyliusStoreLocatorPlugin\\": "src/", - "Tests\\Acme\\SyliusExamplePlugin\\": "tests/" + "Tests\\Locastic\\SyliusStoreLocatorPlugin\\": "tests/" } }, "autoload-dev": { diff --git a/features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature b/features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature new file mode 100644 index 0000000..4319b02 --- /dev/null +++ b/features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature @@ -0,0 +1,36 @@ +@store +Feature: Selecting shipping method with pickup at store + In order to pick up order at store + As a Customer + I want to be able to choose a shipping method with pickup at store option + + Background: + Given the store operates on a single channel in "United States" + Given the store has a product "Targaryen T-Shirt" priced at "$19.99" + Given the store has "Dragon Store" store location + Given the store has "other shipping method" shipping method with "$10.00" fee + Given the store has "pickup at store" shipping method with enabled store pickup and "$10.00" fee + + @ui + Scenario: Selecting store pickup shipping method + Given I have product "Targaryen T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "jon.snow@example.com" + And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be redirected to the shipping step + And I select "pickup at store" shipping method + Then I should see "Dragon Store" store location + When I select "Dragon Store" store location + And I complete the shipping step + + @ui + Scenario: I should be able to select other shipping method and not choose store + Given I have product "Targaryen T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "jon.snow@example.com" + And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be redirected to the shipping step + When I select "other shipping method" shipping method + And I complete the shipping step \ No newline at end of file diff --git a/phpspec.yml.dist b/phpspec.yml.dist index ae371ee..23daa01 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -1,4 +1,4 @@ suites: main: - namespace: Acme\SyliusExamplePlugin - psr4_prefix: Acme\SyliusExamplePlugin + namespace: Locastic\SyliusStoreLocatorPlugin + psr4_prefix: Locastic\SyliusStoreLocatorPlugin diff --git a/src/Entity/IsPickupAtStoreInterface.php b/src/Entity/IsPickupAtStoreInterface.php index c77b1fb..0ad4264 100644 --- a/src/Entity/IsPickupAtStoreInterface.php +++ b/src/Entity/IsPickupAtStoreInterface.php @@ -6,5 +6,5 @@ interface IsPickupAtStoreInterface { public function isPickupAtStore(): ?bool; - public function setPickupAtStore(bool $pickupAtLocation): void; + public function setPickupAtStore(bool $pickupAtStore): void; } diff --git a/src/Fixture/StoreFactory.php b/src/Fixture/StoreFactory.php new file mode 100644 index 0000000..8a0997e --- /dev/null +++ b/src/Fixture/StoreFactory.php @@ -0,0 +1,81 @@ +imageUploader = $imageUploader; + } + + /** + * {@inheritdoc} + */ + public function create(array $options = []) + { + $store = new Store(); + $store->setCode($options['code']); + + foreach ($options['translations'] as $locale => $translation) { + $pageTranslation = new StoreTranslation(); + $pageTranslation->setLocale($locale); + + $pageTranslation->setName($translation['name']); + $pageTranslation->setSlug($translation['slug']); + $pageTranslation->setContent($translation['content']); + $pageTranslation->setOpeningHours($translation['opening_hours']); + $pageTranslation->setMetaTitle($translation['meta_title']); + $pageTranslation->setMetaDescription($translation['meta_description']); + $pageTranslation->setMetaKeywords($translation['meta_keywords']); + + $store->addTranslation($pageTranslation); + } + + $store->setLatitude($options['latitude']); + $store->setLongitude($options['longitude']); + $store->setAddress($options['address']); + $store->setContactEmail($options['contact_email']); + $store->setContactPhone($options['contact_phone']); + $store->setPickupAtStoreAvailable($options['pickup_at_store_available']); + + foreach ($options['images'] as $image) { + if (!array_key_exists('path', $image)) { + $imagePath = array_shift($image); + $imageType = array_pop($image); + } else { + $imagePath = $image['path']; + $imageType = $image['type'] ?? null; + } + + $uploadedImage = new UploadedFile($imagePath, basename($imagePath)); + + /** @var StoreImageInterface $storeImage */ + $storeImage = new StoreImage(); + + $storeImage->setPath($imagePath); + $storeImage->setFile($uploadedImage); + $storeImage->setType($imageType); + + $this->imageUploader->upload($storeImage); + + $store->addImage($storeImage); + } + + return $store; + } +} \ No newline at end of file diff --git a/src/Form/Extension/Checkout/ShipmentTypeExtension.php b/src/Form/Extension/Checkout/ShipmentTypeExtension.php index 5436487..53ddefb 100644 --- a/src/Form/Extension/Checkout/ShipmentTypeExtension.php +++ b/src/Form/Extension/Checkout/ShipmentTypeExtension.php @@ -26,14 +26,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void }, 'mapped' => true, 'class' => Store::class, - 'required' => false, 'choice_label' => 'name', ] ); } - public function getExtendedType(): string + public static function getExtendedTypes(): iterable { - return ShipmentType::class; + return [ShipmentType::class]; } } diff --git a/src/Form/Extension/ShippingMethodTypeExtension.php b/src/Form/Extension/ShippingMethodTypeExtension.php index 70d9b3b..d64e1fd 100644 --- a/src/Form/Extension/ShippingMethodTypeExtension.php +++ b/src/Form/Extension/ShippingMethodTypeExtension.php @@ -13,17 +13,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder ->add( - 'pickupAtLocation', + 'pickupAtStore', CheckboxType::class, [ - 'label' => 'locastic_sylius_store_locator_plugin.ui.pickup_at_location', + 'label' => 'locastic_sylius_store_locator_plugin.ui.pickup_at_store', 'required' => false, ] ); } - public function getExtendedType() + public static function getExtendedTypes(): iterable { - return ShippingMethodType::class; + return [ShippingMethodType::class]; } } diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 99fb9ae..5a919ca 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -40,6 +40,12 @@ services: tags: - { name: sylius_fixtures.fixture } + locastic_sylius_store_locator_plugin.example_factory.store: + class: Locastic\SyliusStoreLocatorPlugin\Fixture\StoreFactory + arguments: + - '@sylius.image_uploader' + public: true + # listeners locastic_sylius_store_locator_plugin.listener.images_upload: diff --git a/src/Resources/config/validation/Shipment.yml b/src/Resources/config/validation/Shipment.yml deleted file mode 100644 index d4d9617..0000000 --- a/src/Resources/config/validation/Shipment.yml +++ /dev/null @@ -1,4 +0,0 @@ -Locastic\SyliusStoreLocatorPlugin\Entity\Shipment: - constraints: - - Locastic\SyliusStoreLocatorPlugin\Validator\Constraints\IsStorePopulated: - groups: ['sylius'] \ No newline at end of file diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 9fb9d08..ccfc662 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -20,5 +20,5 @@ locastic_sylius_store_locator_plugin: opening_hours: Opening hours see_more: See More pickup_at_store_available: Pickup At Store Available - pickup_at_location: Pickup At Location + pickup_at_store: Pickup At Location images: Images of store diff --git a/src/Resources/translations/messages.hr.yml b/src/Resources/translations/messages.hr.yml index f75bd3f..8838263 100644 --- a/src/Resources/translations/messages.hr.yml +++ b/src/Resources/translations/messages.hr.yml @@ -20,5 +20,5 @@ locastic_sylius_store_locator_plugin: opening_hours: Radno vrijeme see_more: Pogledaj više pickup_at_store_available: Dostupno preuzimanje u trgovini - pickup_at_location: Preuzimanje u trgovini + pickup_at_store: Preuzimanje u trgovini images: Slike trgovine diff --git a/tests/Application/app/Resources/SyliusAdminBundle/views/ShippingMethod/_form.html.twig b/tests/Application/app/Resources/SyliusAdminBundle/views/ShippingMethod/_form.html.twig index 39ab5c9..7da13af 100644 --- a/tests/Application/app/Resources/SyliusAdminBundle/views/ShippingMethod/_form.html.twig +++ b/tests/Application/app/Resources/SyliusAdminBundle/views/ShippingMethod/_form.html.twig @@ -8,7 +8,7 @@ {{ form_row(form.code) }} {{ form_row(form.zone) }} {{ form_row(form.position) }} - {{ form_row(form.pickupAtLocation) }} + {{ form_row(form.pickupAtStore) }} {{ form_row(form.enabled) }}

{{ 'sylius.ui.availability'|trans }}

diff --git a/tests/Behat/Context/Setup/ShippingContext.php b/tests/Behat/Context/Setup/ShippingContext.php new file mode 100644 index 0000000..f568563 --- /dev/null +++ b/tests/Behat/Context/Setup/ShippingContext.php @@ -0,0 +1,173 @@ +storeRepository = $storeRepository; + $this->sharedStorage = $sharedStorage; + $this->shippingMethodFactory = $shippingMethodExampleFactory; + $this->storeFactory = $storeFactory; + $this->shippingMethodRepository = $shippingMethodRepository; + } + + + /** + * @Given /^the store has "([^"]*)" store location$/ + */ + public function theStoreHasStoreLocation($storeName) + { + $this->saveStore($this->storeFactory->create( + [ + 'latitude' => 43.5129188, + 'longitude' => 16.48521519999997, + 'address' => "Lovački put 7, 21000, Split, Croatia", + 'contact_phone' => '+38521782059', + 'contact_email' => 'info@locastic.com', + 'pickup_at_store_available' => true, + 'code' => StringInflector::nameToCode(strtolower($storeName)), + 'translations' => [ + 'en_US' => [ + 'name' => $storeName, + 'slug' => StringInflector::nameToCode(strtolower($storeName)), + 'meta_title' => $storeName, + 'meta_description' => $storeName, + 'meta_keywords' => $storeName, + 'content' => $storeName, + 'opening_hours' => 'Mon-Fri 09-17h', + ], + ], + 'images' => [] + ] + )); + } + + /** + * @Given /^the store has "([^"]+)" shipping method with enabled store pickup and ("[^"]+") fee$/ + */ + public function storeHasShippingMethodWithFeeAndPickupAtStore($shippingMethodName, $fee) + { + $channel = $this->sharedStorage->get('channel'); + $configuration = $this->getConfigurationByChannels([$channel], $fee); + + $this->saveShippingMethod( + $this->shippingMethodFactory->create( + [ + 'name' => $shippingMethodName, + 'enabled' => true, + 'is_pickup_at_store' => true, + 'zone' => $this->getShippingZone(), + 'calculator' => [ + 'type' => DefaultCalculators::FLAT_RATE, + 'configuration' => $configuration, + ], + 'channels' => [$this->sharedStorage->get('channel')], + ] + ) + ); + } + + /** + * @param StoreInterface $store + */ + private function saveStore(StoreInterface $store) + { + $this->storeRepository->add($store); + $this->sharedStorage->set('store', $store); + } + + /** + * @return ZoneInterface + */ + private function getShippingZone() + { + if ($this->sharedStorage->has('shipping_zone')) { + return $this->sharedStorage->get('shipping_zone'); + } + + return $this->sharedStorage->get('zone'); + } + + /** + * @param ShippingMethodInterface $shippingMethod + */ + private function saveShippingMethod(ShippingMethodInterface $shippingMethod) + { + $this->shippingMethodRepository->add($shippingMethod); + $this->sharedStorage->set('shipping_method', $shippingMethod); + + } + + /** + * @param array $channels + * @param int $amount + * + * @return array + */ + private function getConfigurationByChannels(array $channels, $amount = 0) + { + $configuration = []; + + /** @var ChannelInterface $channel */ + foreach ($channels as $channel) { + $configuration[$channel->getCode()] = ['amount' => $amount]; + } + + return $configuration; + } + +} \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php new file mode 100644 index 0000000..553ee54 --- /dev/null +++ b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php @@ -0,0 +1,232 @@ +selectShippingPage = $selectShippingPage; + $this->selectPaymentPage = $selectPaymentPage; + $this->completePage = $completePage; + } + + /** + * @Then /^I should see "([^"]*)" store location$/ + */ + public function iShouldSeeStoreLocation($storeName) + { + Assert::true($this->selectShippingPage->hasStoreSelector($storeName)); + } + + /** + * @When /^I select "([^"]*)" store location$/ + */ + public function iSelectStoreLocation($storeName) + { + $this->selectShippingPage->selectStore($storeName); + } + + /** + * @Then /^I should see selected "([^"]*)" store location$/ + */ + public function iShouldSeeSelectedStoreLocation($storeName) + { + Assert::same($this->selectShippingPage->getSelectedStoreName(), $storeName); + } + + + /** + * @Given I have proceeded selecting :shippingMethodName shipping method + * @When I proceed with :shippingMethodName shipping method + */ + public function iHaveProceededSelectingShippingMethod($shippingMethodName) + { + $this->iSelectShippingMethod($shippingMethodName); + $this->selectShippingPage->nextStep(); + } + + /** + * @Given I have selected :shippingMethod shipping method + * @When I select :shippingMethod shipping method + */ + public function iSelectShippingMethod($shippingMethod) + { + $this->selectShippingPage->selectShippingMethod($shippingMethod); + } + + /** + * @When I try to open checkout shipping page + */ + public function iTryToOpenCheckoutShippingPage() + { + $this->selectShippingPage->tryToOpen(); + } + + /** + * @When /^I(?:| try to) complete the shipping step$/ + */ + public function iCompleteTheShippingStep() + { + $this->selectShippingPage->nextStep(); + } + + /** + * @When I decide to change my address + */ + public function iDecideToChangeMyAddress() + { + $this->selectShippingPage->changeAddress(); + } + + /** + * @When I go back to shipping step of the checkout + */ + public function iGoBackToShippingStepOfTheCheckout() + { + $this->selectShippingPage->open(); + } + + /** + * @Then I should not be able to select :shippingMethodName shipping method + */ + public function iShouldNotBeAbleToSelectShippingMethod($shippingMethodName) + { + Assert::false(in_array($shippingMethodName, $this->selectShippingPage->getShippingMethods(), true)); + } + + /** + * @Then I should have :shippingMethodName shipping method available as the first choice + */ + public function iShouldHaveShippingMethodAvailableAsFirstChoice($shippingMethodName) + { + $shippingMethods = $this->selectShippingPage->getShippingMethods(); + + Assert::same(reset($shippingMethods), $shippingMethodName); + } + + /** + * @Then I should have :shippingMethodName shipping method available as the last choice + */ + public function iShouldHaveShippingMethodAvailableAsLastChoice($shippingMethodName) + { + $shippingMethods = $this->selectShippingPage->getShippingMethods(); + + Assert::same(end($shippingMethods), $shippingMethodName); + } + + /** + * @Then I should be on the checkout shipping step + * @Then I should be redirected to the shipping step + */ + public function iShouldBeOnTheCheckoutShippingStep() + { + $this->selectShippingPage->open(); + $this->selectShippingPage->verify(); + } + + /** + * @Then I should be informed that my order cannot be shipped to this address + */ + public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress() + { + Assert::true($this->selectShippingPage->hasNoShippingMethodsMessage()); + } + + /** + * @Then I should be able to go to the complete step again + */ + public function iShouldBeAbleToGoToTheCompleteStepAgain() + { + $this->selectShippingPage->nextStep(); + + $this->completePage->verify(); + } + + /** + * @Then I should be able to go to the payment step again + */ + public function iShouldBeAbleToGoToThePaymentStepAgain() + { + $this->selectShippingPage->nextStep(); + + $this->selectPaymentPage->verify(); + } + + /** + * @Then I should see shipping method :shippingMethodName with fee :fee + */ + public function iShouldSeeShippingFee($shippingMethodName, $fee) + { + Assert::true($this->selectShippingPage->hasShippingMethodFee($shippingMethodName, $fee)); + } + + /** + * @Then there should be information about no available shipping methods + */ + public function thereShouldBeInformationAboutNoShippingMethodsAvailableForMyShippingAddress() + { + Assert::true($this->selectShippingPage->hasNoAvailableShippingMethodsWarning()); + } + + /** + * @Then I should see :shippingMethodName shipping method + */ + public function iShouldSeeShippingMethod($shippingMethodName) + { + Assert::true($this->selectShippingPage->hasShippingMethod($shippingMethodName)); + } + + /** + * @Then I should see selected :shippingMethodName shipping method + */ + public function iShouldSeeSelectedShippingMethod($shippingMethodName) + { + Assert::same($this->selectShippingPage->getSelectedShippingMethodName(), $shippingMethodName); + } + + /** + * @Then I should not see :shippingMethodName shipping method + */ + public function iShouldNotSeeShippingMethod($shippingMethodName) + { + Assert::false($this->selectShippingPage->hasShippingMethod($shippingMethodName)); + } + + /** + * @Then I should be checking out as :email + */ + public function iShouldBeCheckingOutAs($email) + { + Assert::same($this->selectShippingPage->getPurchaserEmail(), 'Checking out as ' . $email . '.'); + } +} \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Shop/WelcomeContext.php b/tests/Behat/Context/Ui/Shop/WelcomeContext.php deleted file mode 100644 index a0d95b0..0000000 --- a/tests/Behat/Context/Ui/Shop/WelcomeContext.php +++ /dev/null @@ -1,80 +0,0 @@ -staticWelcomePage = $staticWelcomePage; - $this->dynamicWelcomePage = $dynamicWelcomePage; - } - - /** - * @When a customer with an unknown name visits static welcome page - */ - public function customerWithUnknownNameVisitsStaticWelcomePage(): void - { - $this->staticWelcomePage->open(); - } - - /** - * @When a customer named :name visits static welcome page - */ - public function namedCustomerVisitsStaticWelcomePage(string $name): void - { - $this->staticWelcomePage->open(['name' => $name]); - } - - /** - * @Then they should be statically greeted with :greeting - */ - public function theyShouldBeStaticallyGreetedWithGreeting(string $greeting): void - { - Assert::same($this->staticWelcomePage->getGreeting(), $greeting); - } - - /** - * @When a customer with an unknown name visits dynamic welcome page - */ - public function customerWithUnknownNameVisitsDynamicWelcomePage(): void - { - $this->dynamicWelcomePage->open(); - } - - /** - * @When a customer named :name visits dynamic welcome page - */ - public function namedCustomerVisitsDynamicWelcomePage(string $name): void - { - $this->dynamicWelcomePage->open(['name' => $name]); - } - - /** - * @Then they should be dynamically greeted with :greeting - */ - public function theyShouldBeDynamicallyGreetedWithGreeting(string $greeting): void - { - Assert::same($this->dynamicWelcomePage->getGreeting(), $greeting); - } -} diff --git a/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php b/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php new file mode 100644 index 0000000..8f7a5f2 --- /dev/null +++ b/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php @@ -0,0 +1,69 @@ +getSession()->getPage()->findAll('css', '.store-select .dropdown option'); + + $stores = []; + foreach ($inputs as $input) { + $stores[] = trim($input->getText()); + } + + return in_array($storeName, $stores); + } + + /** + * {@inheritdoc} + */ + public function selectStore($storeName) + { + $storeOptionElement = $this->getElement('store_option', ['%store%' => $storeName]); + $storeOptionValue = $storeOptionElement->getAttribute('value'); + + $this->getElement('store_select')->selectOption($storeOptionValue); + } + + /** + * {@inheritdoc} + */ + public function getSelectedStoreName() + { + $storeNames = $this->getSession()->getPage()->findAll('css', '.store-select .dropdown option'); + + dump($storeNames); + /** @var NodeElement $storeName */ + foreach ($storeNames as $storeName) { + if (null !== $storeName->find('css', ':selected')) { + return $storeName->getText(); + } + } + + return null; + } + + + /** + * {@inheritdoc} + */ + protected function getDefinedElements() + { + return array_merge( + parent::getDefinedElements(), + [ + 'store_select_outer' => '.store-select', + 'store_select' => '.store-select .dropdown', + 'store_option' => '.store-select .dropdown option:contains("%store%")', + ] + ); + } +} \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php b/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php new file mode 100644 index 0000000..b647d37 --- /dev/null +++ b/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php @@ -0,0 +1,14 @@ +getSession()->getPage()->waitFor(3, function (): string { - $greeting = $this->getElement('greeting')->getText(); - - if ('Loading...' === $greeting) { - return ''; - } - - return $greeting; - }); - } - - /** - * {@inheritdoc} - */ - public function getRouteName(): string - { - return 'acme_sylius_example_dynamic_welcome'; - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - 'greeting' => '#greeting', - ]); - } -} diff --git a/tests/Behat/Page/Shop/StaticWelcomePage.php b/tests/Behat/Page/Shop/StaticWelcomePage.php deleted file mode 100644 index 3b663a6..0000000 --- a/tests/Behat/Page/Shop/StaticWelcomePage.php +++ /dev/null @@ -1,36 +0,0 @@ -getElement('greeting')->getText(); - } - - /** - * {@inheritdoc} - */ - public function getRouteName(): string - { - return 'acme_sylius_example_static_welcome'; - } - - /** - * {@inheritdoc} - */ - protected function getDefinedElements(): array - { - return array_merge(parent::getDefinedElements(), [ - 'greeting' => '#greeting', - ]); - } -} diff --git a/tests/Behat/Page/Shop/WelcomePageInterface.php b/tests/Behat/Page/Shop/WelcomePageInterface.php deleted file mode 100644 index 1527e1c..0000000 --- a/tests/Behat/Page/Shop/WelcomePageInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/tests/Behat/Resources/services.yml b/tests/Behat/Resources/services.yml new file mode 100644 index 0000000..700cd76 --- /dev/null +++ b/tests/Behat/Resources/services.yml @@ -0,0 +1,26 @@ +services: + locastic_sylius_store_locator.context.ui.shop.checkout.shipping: + class: Tests\Locastic\SyliusStoreLocatorPlugin\Behat\Context\Ui\Shop\Checkout\CheckoutShippingContext + arguments: + - "@locastic_sylius_store_locator.page.shop.select_shipping" + - "@sylius.behat.page.shop.checkout.select_payment" + - "@sylius.behat.page.shop.checkout.complete" + tags: + - fob.context_service + + + locastic_sylius_store_locator.behat.context.setup.shipping: + class: Tests\Locastic\SyliusStoreLocatorPlugin\Behat\Context\Setup\ShippingContext + arguments: + - "@__symfony__.locastic_sylius_store_locator_plugin.repository.store" + - "@sylius.behat.shared_storage" + - "@__symfony__.app.fixture.example_factory.shipping_method" + - "@__symfony__.locastic_sylius_store_locator_plugin.example_factory.store" + - "@__symfony__.sylius.repository.shipping_method" + tags: + - fob.context_service + + locastic_sylius_store_locator.page.shop.select_shipping: + class: Tests\Locastic\SyliusStoreLocatorPlugin\Behat\Page\Shop\Checkout\SelectShippingPage + public: false + parent: sylius.behat.page.shop.checkout.select_shipping \ No newline at end of file diff --git a/tests/Behat/Resources/suites.yml b/tests/Behat/Resources/suites.yml index 914463a..d770067 100644 --- a/tests/Behat/Resources/suites.yml +++ b/tests/Behat/Resources/suites.yml @@ -1,10 +1,61 @@ -# Put your Behat suites definitions here - default: suites: - greeting_customer: + store_pickup: contexts_services: - - acme_sylius_example.context.ui.shop.welcome + - locastic_sylius_store_locator.context.ui.shop.checkout.shipping + - locastic_sylius_store_locator.behat.context.setup.shipping + + - sylius.behat.context.hook.doctrine_orm + - sylius.behat.context.hook.email_spool + + - sylius.behat.context.transform.address + - sylius.behat.context.transform.country + - sylius.behat.context.transform.channel + - sylius.behat.context.transform.currency + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.locale + - sylius.behat.context.transform.order + - sylius.behat.context.transform.payment + - sylius.behat.context.transform.product + - sylius.behat.context.transform.product_option + - sylius.behat.context.transform.province + - sylius.behat.context.transform.shared_storage + - sylius.behat.context.transform.shipping_category + - sylius.behat.context.transform.shipping_method + - sylius.behat.context.transform.tax_category + - sylius.behat.context.transform.user + - sylius.behat.context.transform.zone + + - sylius.behat.context.setup.address + - sylius.behat.context.setup.admin_user + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.currency + - sylius.behat.context.setup.customer + - sylius.behat.context.setup.exchange_rate + - sylius.behat.context.setup.geographical + - sylius.behat.context.setup.locale + - sylius.behat.context.setup.payment + - sylius.behat.context.setup.product + - sylius.behat.context.setup.promotion + - sylius.behat.context.setup.shop_security + - sylius.behat.context.setup.shipping + - sylius.behat.context.setup.shipping_category + - sylius.behat.context.setup.taxation + - sylius.behat.context.setup.user + - sylius.behat.context.setup.zone + - sylius.behat.context.ui.admin.managing_orders + - sylius.behat.context.ui.channel + - sylius.behat.context.ui.email + - sylius.behat.context.ui.shop.address_book + - sylius.behat.context.ui.shop.cart + - sylius.behat.context.ui.shop.checkout + - sylius.behat.context.ui.shop.checkout.addressing + - sylius.behat.context.ui.shop.checkout.complete + - sylius.behat.context.ui.shop.checkout.payment + - sylius.behat.context.ui.shop.checkout.thank_you + - sylius.behat.context.ui.shop.currency + - sylius.behat.context.ui.shop.homepage + - sylius.behat.context.ui.shop.locale filters: - tags: "@greeting_customer" + tags: "@store && @ui" From 27e2dffcad8a3f5a5b78a9ebfbb805eeb9616efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Duje=20=C5=A0ari=C4=87?= Date: Tue, 12 Mar 2019 16:24:02 +0100 Subject: [PATCH 2/8] Fix for hidden class on checkbox fields of store form type. --- src/Resources/public/js/locations.js | 7 +++++++ src/Resources/views/Store/Crud/_form.html.twig | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Resources/public/js/locations.js b/src/Resources/public/js/locations.js index c5d6b89..b83c8df 100644 --- a/src/Resources/public/js/locations.js +++ b/src/Resources/public/js/locations.js @@ -123,4 +123,11 @@ map.setAddress(); }); + //This is temporary fix for app.js addition of hidden class. + setTimeout(function () { + + $('#locastic_sylius_store_locator_plugin_store_enabled').removeClass('hidden'); + $('#locastic_sylius_store_locator_plugin_store_pickupAtStoreAvailable').removeClass('hidden'); + }, 500); + }(window.jQuery)); \ No newline at end of file diff --git a/src/Resources/views/Store/Crud/_form.html.twig b/src/Resources/views/Store/Crud/_form.html.twig index e99dfe6..47ac3a0 100644 --- a/src/Resources/views/Store/Crud/_form.html.twig +++ b/src/Resources/views/Store/Crud/_form.html.twig @@ -49,7 +49,7 @@ {% block javascripts %} - {% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/shop/js/app.js'} %} + {% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/admin/js/app.js'} %} {% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/locasticsyliusstorelocatorplugin/js/locations.js'} %} {% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/locasticsyliusstorelocatorplugin/js/locationImages.js'} %} {% endblock %} \ No newline at end of file From a844704312aa9f1da8cde5ad304e2d75abb0a0cc Mon Sep 17 00:00:00 2001 From: Danijela Mikulicic Date: Wed, 13 Mar 2019 15:19:24 +0100 Subject: [PATCH 3/8] added shipment validation on correct step of checkout form --- .../ShipmentFormEventListener.php | 41 +++++++++++++++++++ .../Checkout/ShipmentTypeExtension.php | 12 ++++++ .../config/config_pickup_at_store.yml | 2 + .../Constraints/IsStorePopulated.php | 21 ---------- .../Constraints/IsStorePopulatedValidator.php | 19 --------- 5 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 src/Form/EventListener/ShipmentFormEventListener.php delete mode 100644 src/Validator/Constraints/IsStorePopulated.php delete mode 100644 src/Validator/Constraints/IsStorePopulatedValidator.php diff --git a/src/Form/EventListener/ShipmentFormEventListener.php b/src/Form/EventListener/ShipmentFormEventListener.php new file mode 100644 index 0000000..5361e8d --- /dev/null +++ b/src/Form/EventListener/ShipmentFormEventListener.php @@ -0,0 +1,41 @@ +message = $message; + } + + public static function getSubscribedEvents() + { + return [ + FormEvents::POST_SUBMIT => 'onPostSubmit', + ]; + } + + + public function onPostSubmit(FormEvent $event) + { + $shipment = $event->getData(); + $form = $event->getForm(); + + if (!$shipment instanceof Shipment || !$form->isValid()) { + return; + } + + if ($shipment->getMethod()->isPickupAtStore() && $shipment->getStore() === null) { + $form->addError(new FormError($this->message)); + } + } +} \ No newline at end of file diff --git a/src/Form/Extension/Checkout/ShipmentTypeExtension.php b/src/Form/Extension/Checkout/ShipmentTypeExtension.php index 53ddefb..83e4d9c 100644 --- a/src/Form/Extension/Checkout/ShipmentTypeExtension.php +++ b/src/Form/Extension/Checkout/ShipmentTypeExtension.php @@ -5,6 +5,7 @@ namespace Locastic\SyliusStoreLocatorPlugin\Form\Extension\Checkout; use Locastic\SyliusStoreLocatorPlugin\Entity\Store; +use Locastic\SyliusStoreLocatorPlugin\Form\EventListener\ShipmentFormEventListener; use Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractTypeExtension; @@ -13,6 +14,13 @@ final class ShipmentTypeExtension extends AbstractTypeExtension { + private $translator; + + public function __construct($translator) + { + $this->translator = $translator; + } + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add( @@ -25,10 +33,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->setParameter('pickupAtStoreAvailable', true); }, 'mapped' => true, + 'required' => false, 'class' => Store::class, 'choice_label' => 'name', ] ); + + $message = $this->translator->trans('locastic_sylius_store_locator_plugin.shipment_method.store_not_null',[],'validators'); + $builder->addEventSubscriber(new ShipmentFormEventListener($message)); } public static function getExtendedTypes(): iterable diff --git a/src/Resources/config/config_pickup_at_store.yml b/src/Resources/config/config_pickup_at_store.yml index 8799595..14ac74f 100644 --- a/src/Resources/config/config_pickup_at_store.yml +++ b/src/Resources/config/config_pickup_at_store.yml @@ -4,6 +4,8 @@ imports: services: locastic_sylius_store_locator_plugin.form.extension.type.shipment: class: Locastic\SyliusStoreLocatorPlugin\Form\Extension\Checkout\ShipmentTypeExtension + arguments: + - '@translator' tags: - { name: form.type_extension, extended_type: Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType } diff --git a/src/Validator/Constraints/IsStorePopulated.php b/src/Validator/Constraints/IsStorePopulated.php deleted file mode 100644 index 46dc285..0000000 --- a/src/Validator/Constraints/IsStorePopulated.php +++ /dev/null @@ -1,21 +0,0 @@ -getMethod()->isPickupAtStore() && $value->getStore() === null) { - $this->context - ->buildViolation($constraint->message) - ->atPath('method') - ->addViolation(); - } - } -} From 3d6e905016dac19c3f2bc8e70645bedd2ed2c400 Mon Sep 17 00:00:00 2001 From: Danijela Mikulicic Date: Wed, 13 Mar 2019 15:27:54 +0100 Subject: [PATCH 4/8] added not selecting store on store pickup shipping method test case --- ...lecting_pick_up_at_store_shipping_method.feature} | 12 ++++++++++++ .../Ui/Shop/Checkout/CheckoutShippingContext.php | 8 ++++++++ .../Behat/Page/Shop/Checkout/SelectShippingPage.php | 6 +++++- .../Shop/Checkout/SelectShippingPageInterface.php | 2 ++ 4 files changed, 27 insertions(+), 1 deletion(-) rename features/checkout/shipping_method/{seeing_pick_up_at_store_shipping_method.feature => selecting_pick_up_at_store_shipping_method.feature} (75%) diff --git a/features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature b/features/checkout/shipping_method/selecting_pick_up_at_store_shipping_method.feature similarity index 75% rename from features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature rename to features/checkout/shipping_method/selecting_pick_up_at_store_shipping_method.feature index 4319b02..6198bec 100644 --- a/features/checkout/shipping_method/seeing_pick_up_at_store_shipping_method.feature +++ b/features/checkout/shipping_method/selecting_pick_up_at_store_shipping_method.feature @@ -24,6 +24,18 @@ Feature: Selecting shipping method with pickup at store When I select "Dragon Store" store location And I complete the shipping step + @ui + Scenario: Selecting store pickup shipping method without store selection + Given I have product "Targaryen T-Shirt" in the cart + And I am at the checkout addressing step + When I specify the email as "jon.snow@example.com" + And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow" + And I complete the addressing step + Then I should be redirected to the shipping step + And I select "pickup at store" shipping method + And I complete the shipping step + Then I should see a validation error + @ui Scenario: I should be able to select other shipping method and not choose store Given I have product "Targaryen T-Shirt" in the cart diff --git a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php index 553ee54..4554d71 100644 --- a/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php +++ b/tests/Behat/Context/Ui/Shop/Checkout/CheckoutShippingContext.php @@ -48,6 +48,14 @@ public function iShouldSeeStoreLocation($storeName) Assert::true($this->selectShippingPage->hasStoreSelector($storeName)); } + /** + * @Then /^I should see a validation error$/ + */ + public function iShouldSeeValidationError() + { + Assert::notNull($this->selectShippingPage->hasValidationError()); + } + /** * @When /^I select "([^"]*)" store location$/ */ diff --git a/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php b/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php index 8f7a5f2..2df4018 100644 --- a/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php +++ b/tests/Behat/Page/Shop/Checkout/SelectShippingPage.php @@ -7,6 +7,11 @@ class SelectShippingPage extends BaseSelectShippingPage implements SelectShippingPageInterface { + public function hasValidationError() + { + return $this->getSession()->getPage()->find('css', '.sylius-validation-error'); + } + /** * {@inheritdoc} */ @@ -40,7 +45,6 @@ public function getSelectedStoreName() { $storeNames = $this->getSession()->getPage()->findAll('css', '.store-select .dropdown option'); - dump($storeNames); /** @var NodeElement $storeName */ foreach ($storeNames as $storeName) { if (null !== $storeName->find('css', ':selected')) { diff --git a/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php b/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php index b647d37..53ffa95 100644 --- a/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php +++ b/tests/Behat/Page/Shop/Checkout/SelectShippingPageInterface.php @@ -6,6 +6,8 @@ interface SelectShippingPageInterface extends BaseSelectShippingPageInterface { + public function hasValidationError(); + public function hasStoreSelector($storeName); public function selectStore($storeName); From 548886272b508a1908bb260a10da68f34f6faef4 Mon Sep 17 00:00:00 2001 From: Danijela Mikulicic Date: Wed, 13 Mar 2019 16:10:02 +0100 Subject: [PATCH 5/8] added store locator index page test case --- .../seeing_store_locator_index_page.feature | 16 +++++++ .../Context/Ui/Shop/Store/StoreContext.php | 48 +++++++++++++++++++ .../Behat/Page/Shop/Store/StoreIndexPage.php | 41 ++++++++++++++++ .../Shop/Store/StoreIndexPageInterface.php | 8 ++++ tests/Behat/Resources/services.yml | 14 +++++- tests/Behat/Resources/suites.yml | 1 + 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 features/checkout/shipping_method/seeing_store_locator_index_page.feature create mode 100644 tests/Behat/Context/Ui/Shop/Store/StoreContext.php create mode 100644 tests/Behat/Page/Shop/Store/StoreIndexPage.php create mode 100644 tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php diff --git a/features/checkout/shipping_method/seeing_store_locator_index_page.feature b/features/checkout/shipping_method/seeing_store_locator_index_page.feature new file mode 100644 index 0000000..ed2230c --- /dev/null +++ b/features/checkout/shipping_method/seeing_store_locator_index_page.feature @@ -0,0 +1,16 @@ +@store +Feature: Seeing store locator index page + As a Customer + I want to be able to see index page with all store locations listed + + Background: + Given the store operates on a single channel in "United States" + Given the store has "Dragon Store" store location + Given the store has "Bunny Store" store location + + @ui + Scenario: Seeing the store locator page + Given I am at the store locator index page + Then I should see the store map + And I should see the "Dragon Store" store location + And I should see the "Bunny Store" store location \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Shop/Store/StoreContext.php b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php new file mode 100644 index 0000000..be205ab --- /dev/null +++ b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php @@ -0,0 +1,48 @@ +storeIndexPage = $storeIndexPage; + } + + /** + * @Given I am at the store locator index page + * @When I go back to store locator index page + */ + public function iAmAtTheStoreLocatorIndexPage() + { + $this->storeIndexPage->open(); + } + + /** + * @Then /^I should see the store map$/ + */ + public function iShouldSeeTheStoreMap() + { + Assert::notNull($this->storeIndexPage->hasStoreMap()); + } + + /** + * @Given /^I should see the "([^"]*)" store location$/ + */ + public function iShouldSeeTheStoreLocation($storeName) + { + Assert::true($this->storeIndexPage->hasStorePreview($storeName)); + } +} \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreIndexPage.php b/tests/Behat/Page/Shop/Store/StoreIndexPage.php new file mode 100644 index 0000000..0425cb9 --- /dev/null +++ b/tests/Behat/Page/Shop/Store/StoreIndexPage.php @@ -0,0 +1,41 @@ +getSession()->getPage()->find('css', '#map'); + + } + + public function hasStorePreview($storeName) + { + $stores = $this->getSession()->getPage()->findAll('css', '.store-location'); + /** @var NodeElement $store */ + + foreach ($stores as $store) { + if (null !== $store->find('css', 'h3 a')) { + $storeTitle = $store->find('css', 'h3 a'); + if($storeTitle->getText() === $storeName){ + return true; + } + } + } + + return false; + } +} \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php b/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php new file mode 100644 index 0000000..b092679 --- /dev/null +++ b/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php @@ -0,0 +1,8 @@ + Date: Thu, 14 Mar 2019 09:43:11 +0100 Subject: [PATCH 6/8] fixed store show page --- src/Resources/views/Shop/Store/show.html.twig | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/Resources/views/Shop/Store/show.html.twig b/src/Resources/views/Shop/Store/show.html.twig index e1feb94..0673610 100644 --- a/src/Resources/views/Shop/Store/show.html.twig +++ b/src/Resources/views/Shop/Store/show.html.twig @@ -7,7 +7,7 @@ {% if store.metaTitle %} {{ store.metaTitle }} {% else %} - {{ store.title }} + {{ store.name }} {% endif %} {% endblock %} @@ -38,45 +38,51 @@
-
-

{{ 'locastic_sylius_store_locator_plugin.ui.address'|trans }} - : {{ store.address }}

-

{{ 'locastic_sylius_store_locator_plugin.ui.contact_email'|trans }} - : {{ store.contactEmail }}

-

- {{ 'locastic_sylius_store_locator_plugin.ui.contact_phone'|trans }} - : {{ store.contactPhone }}

-

- {{ 'locastic_sylius_store_locator_plugin.ui.opening_hours'|trans }} - : {{ store.openingHours|raw }}

- +
+ {% if store.address %} +

{{ 'locastic_sylius_store_locator_plugin.ui.address'|trans }} + : {{ store.address }}

+ {% endif %} + {% if store.contactEmail %} +

{{ 'locastic_sylius_store_locator_plugin.ui.contact_email'|trans }} + : {{ store.contactEmail }}

+ {% endif %} + {% if store.contactPhone %} +

+ {{ 'locastic_sylius_store_locator_plugin.ui.contact_phone'|trans }} + : {{ store.contactPhone }}

+ {% endif %} + {% if store.openingHours %} +

+ {{ 'locastic_sylius_store_locator_plugin.ui.opening_hours'|trans }} + : {{ store.openingHours|raw }}

+ {% endif %}
{{ store.content|raw }}
-
-
- {% if store.images %} -

- {{ 'locastic_sylius_store_locator_plugin.ui.images'|trans }} -

+ {% if store.images|length > 0 %} +

+ {{ 'locastic_sylius_store_locator_plugin.ui.images'|trans }} +

-
- {% for storeImage in store.images %} -
+
+ {% for storeImage in store.images %} +
- {% set imagePath = '/media/image/'~storeImage.path %} - + {% set imagePath = '/media/image/'~storeImage.path %} + -
-

{{ storeImage.type }}

+
+

{{ storeImage.type }}

+
-
- {% endfor %} -
+ {% endfor %} +
{% endif %}
{% endblock %} From b143150f42f47a6ebdb3004dd084deed1c0f6bad Mon Sep 17 00:00:00 2001 From: Danijela Mikulicic Date: Thu, 14 Mar 2019 10:36:00 +0100 Subject: [PATCH 7/8] moved stroe setup to store context, added test scenario for store show page --- .../seeing_store_locator_show_page.feature | 19 ++++ src/Resources/views/Shop/Store/show.html.twig | 4 +- tests/Behat/Context/Setup/ShippingContext.php | 60 ------------ tests/Behat/Context/Setup/StoreContext.php | 91 +++++++++++++++++++ .../Context/Ui/Shop/Store/StoreContext.php | 37 +++++++- .../Shop/Store/StoreIndexPageInterface.php | 2 + tests/Behat/Page/Shop/Store/StoreShowPage.php | 60 ++++++++++++ .../Shop/Store/StoreShowPageInterface.php | 10 ++ tests/Behat/Resources/services.yml | 23 ++++- tests/Behat/Resources/suites.yml | 4 +- 10 files changed, 244 insertions(+), 66 deletions(-) create mode 100644 features/checkout/shipping_method/seeing_store_locator_show_page.feature create mode 100644 tests/Behat/Context/Setup/StoreContext.php create mode 100644 tests/Behat/Page/Shop/Store/StoreShowPage.php create mode 100644 tests/Behat/Page/Shop/Store/StoreShowPageInterface.php diff --git a/features/checkout/shipping_method/seeing_store_locator_show_page.feature b/features/checkout/shipping_method/seeing_store_locator_show_page.feature new file mode 100644 index 0000000..a4e2592 --- /dev/null +++ b/features/checkout/shipping_method/seeing_store_locator_show_page.feature @@ -0,0 +1,19 @@ +@store +Feature: Seeing store locator show page + As a Customer + I want to be able to see store location page + + Background: + Given the store operates on a single channel in "United States" + Given the store has "Dragon Store" store location + Given the store has "Bunny Store" store location + + @ui + Scenario: Seeing the single store locator page + Given I am at the store locator index page + And I should see the "Dragon Store" store location + And I should see the "Bunny Store" store location + And I go to "Bunny Store" store location page + Then I should see the store map + And I should see "Bunny Store" store information + And I should see store images \ No newline at end of file diff --git a/src/Resources/views/Shop/Store/show.html.twig b/src/Resources/views/Shop/Store/show.html.twig index 0673610..ee2f3d4 100644 --- a/src/Resources/views/Shop/Store/show.html.twig +++ b/src/Resources/views/Shop/Store/show.html.twig @@ -45,7 +45,7 @@ : {{ store.address }}

{% endif %} {% if store.contactEmail %} -

{{ 'locastic_sylius_store_locator_plugin.ui.contact_email'|trans }} +

{{ 'locastic_sylius_store_locator_plugin.ui.contact_email'|trans }} : {{ store.contactEmail }}

{% endif %} {% if store.contactPhone %} @@ -54,7 +54,7 @@ : {{ store.contactPhone }}

{% endif %} {% if store.openingHours %} -

+

{{ 'locastic_sylius_store_locator_plugin.ui.opening_hours'|trans }} : {{ store.openingHours|raw }}

{% endif %} diff --git a/tests/Behat/Context/Setup/ShippingContext.php b/tests/Behat/Context/Setup/ShippingContext.php index f568563..06bfcd8 100644 --- a/tests/Behat/Context/Setup/ShippingContext.php +++ b/tests/Behat/Context/Setup/ShippingContext.php @@ -3,13 +3,9 @@ namespace Tests\Locastic\SyliusStoreLocatorPlugin\Behat\Context\Setup; use Behat\Behat\Context\Context; -use Locastic\SyliusStoreLocatorPlugin\Entity\StoreInterface; use Locastic\SyliusStoreLocatorPlugin\Fixture\ShippingMethodFactory; -use Locastic\SyliusStoreLocatorPlugin\Fixture\StoreFactory; -use Locastic\SyliusStoreLocatorPlugin\Repository\StoreRepository; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Addressing\Model\ZoneInterface; -use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ShippingMethodInterface; use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface; @@ -18,11 +14,6 @@ final class ShippingContext implements Context { - /** - * @var StoreRepository - */ - private $storeRepository; - /** * @var SharedStorageInterface */ @@ -33,11 +24,6 @@ final class ShippingContext implements Context */ private $shippingMethodFactory; - /** - * @var StoreFactory - */ - private $storeFactory; - /** * @var ShippingMethodRepositoryInterface */ @@ -45,57 +31,20 @@ final class ShippingContext implements Context /** * ShippingContext constructor. - * @param StoreRepository $storeRepository * @param SharedStorageInterface $sharedStorage * @param ShippingMethodFactory $shippingMethodExampleFactory - * @param StoreFactory $storeFactory * @param ShippingMethodRepositoryInterface $shippingMethodRepository */ public function __construct( - StoreRepository $storeRepository, SharedStorageInterface $sharedStorage, ShippingMethodFactory $shippingMethodExampleFactory, - StoreFactory $storeFactory, ShippingMethodRepositoryInterface $shippingMethodRepository ) { - $this->storeRepository = $storeRepository; $this->sharedStorage = $sharedStorage; $this->shippingMethodFactory = $shippingMethodExampleFactory; - $this->storeFactory = $storeFactory; $this->shippingMethodRepository = $shippingMethodRepository; } - - /** - * @Given /^the store has "([^"]*)" store location$/ - */ - public function theStoreHasStoreLocation($storeName) - { - $this->saveStore($this->storeFactory->create( - [ - 'latitude' => 43.5129188, - 'longitude' => 16.48521519999997, - 'address' => "Lovački put 7, 21000, Split, Croatia", - 'contact_phone' => '+38521782059', - 'contact_email' => 'info@locastic.com', - 'pickup_at_store_available' => true, - 'code' => StringInflector::nameToCode(strtolower($storeName)), - 'translations' => [ - 'en_US' => [ - 'name' => $storeName, - 'slug' => StringInflector::nameToCode(strtolower($storeName)), - 'meta_title' => $storeName, - 'meta_description' => $storeName, - 'meta_keywords' => $storeName, - 'content' => $storeName, - 'opening_hours' => 'Mon-Fri 09-17h', - ], - ], - 'images' => [] - ] - )); - } - /** * @Given /^the store has "([^"]+)" shipping method with enabled store pickup and ("[^"]+") fee$/ */ @@ -121,15 +70,6 @@ public function storeHasShippingMethodWithFeeAndPickupAtStore($shippingMethodNam ); } - /** - * @param StoreInterface $store - */ - private function saveStore(StoreInterface $store) - { - $this->storeRepository->add($store); - $this->sharedStorage->set('store', $store); - } - /** * @return ZoneInterface */ diff --git a/tests/Behat/Context/Setup/StoreContext.php b/tests/Behat/Context/Setup/StoreContext.php new file mode 100644 index 0000000..7e612c6 --- /dev/null +++ b/tests/Behat/Context/Setup/StoreContext.php @@ -0,0 +1,91 @@ +storeRepository = $storeRepository; + $this->storeFactory = $storeFactory; + $this->sharedStorage = $sharedStorage; + } + + /** + * @Given /^the store has "([^"]*)" store location$/ + */ + public function theStoreHasStoreLocation($storeName) + { + $this->saveStore( + $this->storeFactory->create( + [ + 'latitude' => 43.5129188, + 'longitude' => 16.48521519999997, + 'address' => "Lovački put 7, 21000, Split, Croatia", + 'contact_phone' => '+38521782059', + 'contact_email' => 'info@locastic.com', + 'pickup_at_store_available' => true, + 'code' => StringInflector::nameToCode(strtolower($storeName)), + 'translations' => [ + 'en_US' => [ + 'name' => $storeName, + 'slug' => StringInflector::nameToCode(strtolower($storeName)), + 'meta_title' => $storeName, + 'meta_description' => $storeName, + 'meta_keywords' => $storeName, + 'content' => $storeName, + 'opening_hours' => 'Mon-Fri 09-17h', + ], + ], + 'images' => [ + 'dragovode_1' => + [ + 'type' => "Office inside", + 'path' => __DIR__."/../../../Application/app/Resources/fixtures/office_1.jpg", + ], + ], + ] + ) + ); + } + + /** + * @param StoreInterface $store + */ + private function saveStore(StoreInterface $store) + { + $this->storeRepository->add($store); + $this->sharedStorage->set('store', $store); + } +} \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Shop/Store/StoreContext.php b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php index be205ab..1f9fb20 100644 --- a/tests/Behat/Context/Ui/Shop/Store/StoreContext.php +++ b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php @@ -1,8 +1,11 @@ storeIndexPage = $storeIndexPage; + $this->storeShowPage = $storeShowPage; } + /** * @Given I am at the store locator index page * @When I go back to store locator index page @@ -45,4 +56,28 @@ public function iShouldSeeTheStoreLocation($storeName) { Assert::true($this->storeIndexPage->hasStorePreview($storeName)); } + + /** + * @Given /^I go to "([^"]*)" store location page$/ + */ + public function iGoToStoreLocationPage($storeName) + { + $this->storeShowPage->open(['slug' => StringInflector::nameToCode(strtolower($storeName))]); + } + + /** + * @Given /^I should see "([^"]*)" store information$/ + */ + public function iShouldSeeStoreInformation($storeName) + { + Assert::true($this->storeShowPage->hasStoreInformation($storeName)); + } + + /** + * @Given /^I should see store images$/ + */ + public function iShouldSeeStoreImages() + { + Assert::true($this->storeShowPage->hasStoreImage()); + } } \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php b/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php index b092679..cd68600 100644 --- a/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php +++ b/tests/Behat/Page/Shop/Store/StoreIndexPageInterface.php @@ -4,5 +4,7 @@ interface StoreIndexPageInterface { + public function hasStoreMap(); + public function hasStorePreview($storeName); } \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreShowPage.php b/tests/Behat/Page/Shop/Store/StoreShowPage.php new file mode 100644 index 0000000..32ab80d --- /dev/null +++ b/tests/Behat/Page/Shop/Store/StoreShowPage.php @@ -0,0 +1,60 @@ +getSession()->getPage()->find('css', 'h1.header'); + + if ($titleElement->getText() !== $storeName) { + $hasStoreInfo = false; + } + + $infoElements = $this->getSession()->getPage()->findAll('css', '#store-location p'); + + $requiredItemProps = ["address", "email", "telephone", "hours"]; + $existingItemProps = []; + foreach ($infoElements as $infoElement) { + $existingItemProps[] = $infoElement->getAttribute('itemprop'); + } + + $missingItemProps = array_diff($requiredItemProps, $existingItemProps); + if (!empty($missingItemProps)) { + $hasStoreInfo = false; + } + + $descriptionElements = $this->getSession()->getPage()->findAll('css', '#store-location div'); + $existingItemProps = []; + foreach ($descriptionElements as $descriptionElement) { + $existingItemProps[] = $descriptionElement->getAttribute('itemprop'); + } + + if (!in_array('description', $existingItemProps)) { + $hasStoreInfo = false; + } + + return $hasStoreInfo; + + } + + public function hasStoreImage() + { + $imgElement = $this->getSession()->getPage()->find('css', 'img.dimmable'); + + return $imgElement !== null; + } +} \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreShowPageInterface.php b/tests/Behat/Page/Shop/Store/StoreShowPageInterface.php new file mode 100644 index 0000000..38fe26d --- /dev/null +++ b/tests/Behat/Page/Shop/Store/StoreShowPageInterface.php @@ -0,0 +1,10 @@ + Date: Thu, 14 Mar 2019 10:47:58 +0100 Subject: [PATCH 8/8] added test scenario for store show page with only required store info --- .../seeing_store_locator_show_page.feature | 14 +++++++- tests/Behat/Context/Setup/StoreContext.php | 32 +++++++++++++++++ .../Context/Ui/Shop/Store/StoreContext.php | 24 +++++++++++++ tests/Behat/Page/Shop/Store/StoreShowPage.php | 36 +++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/features/checkout/shipping_method/seeing_store_locator_show_page.feature b/features/checkout/shipping_method/seeing_store_locator_show_page.feature index a4e2592..4cbb3da 100644 --- a/features/checkout/shipping_method/seeing_store_locator_show_page.feature +++ b/features/checkout/shipping_method/seeing_store_locator_show_page.feature @@ -7,13 +7,25 @@ Feature: Seeing store locator show page Given the store operates on a single channel in "United States" Given the store has "Dragon Store" store location Given the store has "Bunny Store" store location + Given the store has "Basic Bunny Store" store location with only required info @ui Scenario: Seeing the single store locator page Given I am at the store locator index page And I should see the "Dragon Store" store location And I should see the "Bunny Store" store location + And I should see the "Basic Bunny Store" store location And I go to "Bunny Store" store location page Then I should see the store map And I should see "Bunny Store" store information - And I should see store images \ No newline at end of file + And I should see store images + + @ui + Scenario: Seeing the single store locator page with only required info + Given I am at the store locator index page + And I should see the "Basic Bunny Store" store location + And I go to "Basic Bunny Store" store location page + Then I should see the store map + And I should see "Basic Bunny Store" store title + And I should not see "Basic Bunny Store" store information + And I should not see store images \ No newline at end of file diff --git a/tests/Behat/Context/Setup/StoreContext.php b/tests/Behat/Context/Setup/StoreContext.php index 7e612c6..cacef8d 100644 --- a/tests/Behat/Context/Setup/StoreContext.php +++ b/tests/Behat/Context/Setup/StoreContext.php @@ -80,6 +80,38 @@ public function theStoreHasStoreLocation($storeName) ); } + /** + * @Given /^the store has "([^"]*)" store location with only required info$/ + */ + public function theStoreHasStoreLocationWithOnlyRequiredInfo($storeName) + { + $this->saveStore( + $this->storeFactory->create( + [ + 'latitude' => null, + 'longitude' => null, + 'address' => null, + 'contact_phone' => null, + 'contact_email' => null, + 'pickup_at_store_available' => true, + 'code' => StringInflector::nameToCode(strtolower($storeName)), + 'translations' => [ + 'en_US' => [ + 'name' => $storeName, + 'slug' => StringInflector::nameToCode(strtolower($storeName)), + 'meta_title' => null, + 'meta_description' => null, + 'meta_keywords' => null, + 'content' => null, + 'opening_hours' => null, + ], + ], + 'images' => [], + ] + ) + ); + } + /** * @param StoreInterface $store */ diff --git a/tests/Behat/Context/Ui/Shop/Store/StoreContext.php b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php index 1f9fb20..7466994 100644 --- a/tests/Behat/Context/Ui/Shop/Store/StoreContext.php +++ b/tests/Behat/Context/Ui/Shop/Store/StoreContext.php @@ -80,4 +80,28 @@ public function iShouldSeeStoreImages() { Assert::true($this->storeShowPage->hasStoreImage()); } + + /** + * @Given /^I should not see "([^"]*)" store information$/ + */ + public function iShouldNotSeeStoreInformation($storeName) + { + Assert::true($this->storeShowPage->doesntHaveStoreInformation()); + } + + /** + * @Given /^I should see "([^"]*)" store title$/ + */ + public function iShouldSeeStoreTitle($storeName) + { + Assert::true($this->storeShowPage->hasStoreTitle($storeName)); + } + + /** + * @Given /^I should not see store images$/ + */ + public function iShouldNotSeeStoreImages() + { + Assert::false($this->storeShowPage->hasStoreImage()); + } } \ No newline at end of file diff --git a/tests/Behat/Page/Shop/Store/StoreShowPage.php b/tests/Behat/Page/Shop/Store/StoreShowPage.php index 32ab80d..9260600 100644 --- a/tests/Behat/Page/Shop/Store/StoreShowPage.php +++ b/tests/Behat/Page/Shop/Store/StoreShowPage.php @@ -51,6 +51,42 @@ public function hasStoreInformation($storeName) } + public function hasStoreTitle($storeName) + { + $titleElement = $this->getSession()->getPage()->find('css', 'h1.header'); + + return !($titleElement->getText() !== $storeName); + } + + public function doesntHaveStoreInformation() + { + $hasStoreInfo = false; + + $infoElements = $this->getSession()->getPage()->findAll('css', '#store-location p'); + + $existingItemProps = []; + foreach ($infoElements as $infoElement) { + $existingItemProps[] = $infoElement->getAttribute('itemprop'); + } + + if (!empty($existingItemProps)) { + $hasStoreInfo = true; + } + + $descriptionElements = $this->getSession()->getPage()->findAll('css', '#store-location div'); + $existingItemProps = []; + foreach ($descriptionElements as $descriptionElement) { + $existingItemProps[] = $descriptionElement->getAttribute('itemprop'); + } + + if (in_array('description', $existingItemProps)) { + $hasStoreInfo = true; + } + + return $hasStoreInfo; + + } + public function hasStoreImage() { $imgElement = $this->getSession()->getPage()->find('css', 'img.dimmable');