/**
  * Add products to the cart
  *
  * @return void
  */
 public function run()
 {
     // Ensure that shopping cart is empty
     $this->checkoutCart->open()->getCartBlock()->clearShoppingCart();
     foreach ($this->products as $product) {
         $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
         $this->catalogProductView->getViewBlock()->addToCart($product);
         $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
     }
 }
Ejemplo n.º 2
0
 /**
  * Assert prices on the product view page and shopping cart page.
  *
  * @param BundleProduct $product
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCartView
  * @param BundleProduct $originalProduct [optional]
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function assertPrice(BundleProduct $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCartView, BundleProduct $originalProduct = null)
 {
     $customerGroup = 'NOT LOGGED IN';
     $bundleData = $product->getData();
     $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType();
     $catalogProductView->getViewBlock()->addToCart($product);
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCartView->open();
     $cartItem = $checkoutCartView->getCartBlock()->getCartItem($product);
     $specialPrice = 0;
     if (isset($bundleData['group_price'])) {
         $specialPrice = $bundleData['group_price'][array_search($customerGroup, $bundleData['group_price'])]['price'] / 100;
     }
     $optionPrice = [];
     $fillData = $product->getCheckoutData();
     foreach ($fillData['options']['bundle_options'] as $key => $data) {
         $subProductPrice = 0;
         foreach ($bundleData['bundle_selections']['products'][$key] as $productKey => $itemProduct) {
             if (strpos($itemProduct->getName(), $data['value']['name']) !== false) {
                 $data['value']['key'] = $productKey;
                 $subProductPrice = $itemProduct->getPrice();
             }
         }
         $optionPrice[$key]['price'] = $this->productPriceType == 'Fixed' ? number_format($bundleData['bundle_selections']['bundle_options'][$key]['assigned_products'][$data['value']['key']]['data']['selection_price_value'], 2) : number_format($subProductPrice, 2);
     }
     foreach ($optionPrice as $index => $item) {
         $item['price'] -= $item['price'] * $specialPrice;
         \PHPUnit_Framework_Assert::assertEquals(number_format($item['price'], 2), $cartItem->getPriceBundleOptions($index + 1), 'Bundle item ' . ($index + 1) . ' options on frontend don\'t equal to fixture.');
     }
     $sumOptionsPrice = $product->getDataFieldConfig('price')['source']->getPriceData()['cart_price'];
     $subTotal = number_format($cartItem->getPrice(), 2);
     \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.');
 }
 /**
  * Fill options get price and add to cart
  *
  * @param CatalogProductSimple $product
  * @param array $actualPrices
  * @return array
  */
 protected function addToCart(CatalogProductSimple $product, $actualPrices)
 {
     $this->catalogProductView->getViewBlock()->fillOptions($product);
     $actualPrices['product_page_price'] = $this->catalogProductView->getViewBlock()->getPriceBlock()->getPrice();
     $this->catalogProductView->getViewBlock()->clickAddToCart();
     $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
     return $actualPrices;
 }
 /**
  * Add products to compare list
  *
  * @param array $products
  * @return void
  */
 protected function addProducts(array $products)
 {
     foreach ($products as $itemProduct) {
         $this->browser->open($_ENV['app_frontend_url'] . $itemProduct->getUrlKey() . '.html');
         $this->catalogProductView->getViewBlock()->clickAddToCompare();
         $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
     }
 }
 /**
  * Assertion that the product is correctly displayed in cart
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @param BrowserInterface $browser
  * @param CheckoutCart $checkoutCart
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, FixtureInterface $product, BrowserInterface $browser, CheckoutCart $checkoutCart)
 {
     // Add product to cart
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->fillOptions($product);
     $catalogProductView->getViewBlock()->clickAddToCart();
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     // Check price
     $this->assertOnShoppingCart($product, $checkoutCart);
 }
 /**
  * Assertion that the product is correctly displayed in cart
  *
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param ConfigurableProduct $product
  * @return void
  */
 public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, ConfigurableProduct $product)
 {
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->addToCart($product);
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCart->open();
     $checkoutData = $product->getCheckoutData();
     $price = $checkoutCart->getCartBlock()->getCartItem($product)->getPrice();
     \PHPUnit_Framework_Assert::assertEquals($checkoutData['cartItem']['price'], $price, 'Product price in shopping cart is not correct.');
 }
 /**
  * Fill options get price and add to cart
  *
  * @param CatalogProductSimple $product
  * @param array $actualPrices
  * @return array
  */
 protected function addToCart(CatalogProductSimple $product, array $actualPrices)
 {
     $viewBlock = $this->catalogProductView->getViewBlock();
     $priceBlock = $this->catalogProductView->getWeeeViewBlock()->getPriceBlock();
     $viewBlock->fillOptions($product);
     $actualPrices['product_page_price'] = $priceBlock->getPrice();
     $actualPrices['product_page_fpt'] = $priceBlock->getFptPrice();
     $actualPrices['product_page_fpt_total'] = $priceBlock->getFinalPrice();
     $viewBlock->clickAddToCart();
     $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
     return $actualPrices;
 }
 /**
  * Add products to cart.
  *
  * @param array $productQuantity
  * @return void
  */
 protected function addProductsToCart(array $productQuantity)
 {
     foreach ($productQuantity as $product => $quantity) {
         if ($quantity > 0) {
             $categoryName = $this->{$product}->getCategoryIds()[0];
             $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
             $this->catalogCategoryView->getListProductBlock()->getProductItem($this->{$product})->open();
             $this->catalogProductView->getViewBlock()->setQtyAndClickAddToCart($quantity);
             $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
         }
     }
 }
 /**
  * Assert that product is not displayed in cross-sell section.
  *
  * @param BrowserInterface $browser
  * @param CatalogProductSimple $product
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param InjectableFixture[]|null $promotedProducts
  * @return void
  */
 public function processAssert(BrowserInterface $browser, CatalogProductSimple $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, array $promotedProducts = null)
 {
     if (!$promotedProducts) {
         $promotedProducts = $product->hasData('cross_sell_products') ? $product->getDataFieldConfig('cross_sell_products')['source']->getProducts() : [];
     }
     $checkoutCart->open();
     $checkoutCart->getCartBlock()->clearShoppingCart();
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->addToCart($product);
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCart->open();
     foreach ($promotedProducts as $promotedProduct) {
         \PHPUnit_Framework_Assert::assertFalse($checkoutCart->getCrosssellBlock()->getProductItem($promotedProduct)->isVisible(), 'Product \'' . $promotedProduct->getName() . '\' is exist in cross-sell section.');
     }
 }
Ejemplo n.º 10
0
 /**
  * Place order and verify there is no checkbox Terms and Conditions.
  *
  * @param FixtureFactory $fixtureFactory
  * @param ObjectManager $objectManager
  * @param string $product
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param CheckoutOnepage $checkoutOnepage
  * @param CheckoutAgreement $agreement
  * @param array $shipping
  * @param array $payment
  * @return void
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function processAssert(FixtureFactory $fixtureFactory, ObjectManager $objectManager, $product, BrowserInterface $browser, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, CheckoutOnepage $checkoutOnepage, CheckoutAgreement $agreement, $shipping, $payment)
 {
     $createProductsStep = $objectManager->create('Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => $product]);
     $product = $createProductsStep->run();
     $billingAddress = $fixtureFactory->createByCode('address', ['dataset' => 'default']);
     $browser->open($_ENV['app_frontend_url'] . $product['products'][0]->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->clickAddToCartButton();
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCart->open();
     $checkoutCart->getCartBlock()->getOnepageLinkBlock()->proceedToCheckout();
     $checkoutOnepage->getLoginBlock()->clickContinue();
     $checkoutOnepage->getBillingBlock()->fill($billingAddress);
     $checkoutOnepage->getBillingBlock()->clickContinue();
     $checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($shipping);
     $checkoutOnepage->getShippingMethodBlock()->clickContinue();
     $checkoutOnepage->getPaymentBlock()->selectPaymentMethod($payment);
     \PHPUnit_Framework_Assert::assertFalse($checkoutOnepage->getAgreementReview()->checkAgreement($agreement), 'Checkout Agreement \'' . $agreement->getName() . '\' is present in the Place order step.');
 }
Ejemplo n.º 11
0
 /**
  * Assert product MAP related data in Shopping Cart.
  *
  * @param CmsIndex $cmsIndex
  * @param CatalogCategoryView $catalogCategoryView
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, InjectableFixture $product)
 {
     /** @var CatalogProductSimple $product */
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
     $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
     if ($product->hasData('checkout_data')) {
         $catalogProductView->getViewBlock()->addToCart($product);
     } else {
         $catalogProductView->getMsrpViewBlock()->openMapBlock();
         $catalogProductView->getMsrpViewBlock()->getMapBlock()->addToCart();
     }
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCart->open();
     $productPrice = $product->hasData('checkout_data') ? $product->getCheckoutData()['cartItem']['price'] : $product->getPrice();
     $unitPrice = $checkoutCart->getCartBlock()->getCartItem($product)->getPrice();
     \PHPUnit_Framework_Assert::assertEquals($productPrice, $unitPrice, 'Incorrect unit price is displayed in Cart');
 }
 /**
  * Update Shopping Cart
  *
  * @param CatalogProductSimple $product
  * @return array
  */
 public function test(CatalogProductSimple $product)
 {
     // Preconditions
     $product->persist();
     $this->checkoutCart->getCartBlock()->clearShoppingCart();
     // Steps
     $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $productView = $this->catalogProductView->getViewBlock();
     $productView->fillOptions($product);
     $productView->setQty(1);
     $productView->clickAddToCart();
     $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $qty = $product->getCheckoutData()['qty'];
     $this->checkoutCart->open();
     $this->checkoutCart->getCartBlock()->getCartItem($product)->setQty($qty);
     $this->checkoutCart->getCartBlock()->updateShoppingCart();
     $cart['data']['items'] = ['products' => [$product]];
     return ['cart' => $this->fixtureFactory->createByCode('cart', $cart)];
 }
Ejemplo n.º 13
0
 /**
  * Check that checkbox is present on the last checkout step - Order Review.
  * Check that after Place order without click on checkbox "Terms and Conditions" order was not successfully placed.
  * Check that after clicking on "Terms and Conditions" checkbox and "Place Order" button success place order message
  * appears.
  *
  * @param FixtureFactory $fixtureFactory
  * @param ObjectManager $objectManager
  * @param string $product
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param CheckoutOnepage $checkoutOnepage
  * @param CheckoutOnepageSuccess $checkoutOnepageSuccess
  * @param AssertOrderSuccessPlacedMessage $assertOrderSuccessPlacedMessage
  * @param array $shipping
  * @param array $payment
  * @return void
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function processAssert(FixtureFactory $fixtureFactory, ObjectManager $objectManager, $product, BrowserInterface $browser, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, CheckoutOnepage $checkoutOnepage, CheckoutOnepageSuccess $checkoutOnepageSuccess, AssertOrderSuccessPlacedMessage $assertOrderSuccessPlacedMessage, $shipping, $payment)
 {
     $createProductsStep = $objectManager->create('Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => $product]);
     $product = $createProductsStep->run();
     $billingAddress = $fixtureFactory->createByCode('address', ['dataset' => 'default']);
     $browser->open($_ENV['app_frontend_url'] . $product['products'][0]->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->clickAddToCartButton();
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCart->open();
     $checkoutCart->getCartBlock()->getOnepageLinkBlock()->proceedToCheckout();
     $checkoutOnepage->getLoginBlock()->clickContinue();
     $checkoutOnepage->getBillingBlock()->fill($billingAddress);
     $checkoutOnepage->getBillingBlock()->clickContinue();
     $checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($shipping);
     $checkoutOnepage->getShippingMethodBlock()->clickContinue();
     $checkoutOnepage->getPaymentBlock()->selectPaymentMethod($payment);
     $checkoutOnepage->getPaymentBlock()->getSelectedPaymentMethodBlock()->clickPlaceOrder();
     \PHPUnit_Framework_Assert::assertEquals(self::NOTIFICATION_MESSAGE, $checkoutOnepage->getAgreementReview()->getNotificationMassage(), 'Notification required message of Terms and Conditions is absent.');
     $checkoutOnepage->getAgreementReview()->setAgreement('Yes');
     $checkoutOnepage->getAgreementReview()->placeOrder();
     $assertOrderSuccessPlacedMessage->processAssert($checkoutOnepageSuccess);
 }
 /**
  * Assert that specified prices are actual on category, product and cart pages.
  *
  * @param InjectableFixture $product
  * @param array $prices
  * @param int $qty
  * @param CmsIndex $cmsIndex
  * @param CatalogCategoryView $catalogCategoryView
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param FixtureFactory $fixtureFactory
  * @return void
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function processAssert(InjectableFixture $product, array $prices, $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, FixtureFactory $fixtureFactory)
 {
     $this->cmsIndex = $cmsIndex;
     $this->catalogCategoryView = $catalogCategoryView;
     $this->catalogProductView = $catalogProductView;
     $this->checkoutCart = $checkoutCart;
     $actualPrices = [];
     //Assertion steps
     $productCategory = $product->getCategoryIds()[0];
     $this->openCategory($productCategory);
     $actualPrices = $this->getCategoryPrices($product, $actualPrices);
     $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
     $catalogProductView->getViewBlock()->fillOptions($product);
     $actualPrices = $this->getProductPagePrices($actualPrices);
     $catalogProductView->getViewBlock()->clickAddToCart();
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $actualPrices = $this->getCartPrices($product, $actualPrices);
     $actualPrices = $this->getTotals($actualPrices);
     //Prices verification
     $message = 'Prices from dataset should be equal to prices on frontend';
     \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message);
 }
 /**
  * Assert success message is presented on page
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     $successMessage = sprintf(self::SUCCESS_MESSAGE, $product->getName());
     $actualMessage = $catalogProductView->getMessagesBlock()->getSuccessMessages();
     \PHPUnit_Framework_Assert::assertEquals($successMessage, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . $successMessage . "\nActual: " . $actualMessage);
 }
Ejemplo n.º 16
0
 /**
  * 1. Creating product simple with custom tax product class
  * 2. Log In as customer
  * 3. Add product to shopping cart
  * 4. Estimate Shipping and Tax
  * 5. Implementation assert
  *
  * @param FixtureFactory $fixtureFactory
  * @param TaxRule $taxRule
  * @param Customer $customer
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param Address $address
  * @param array $shipping
  * @param BrowserInterface $browser
  * @param TaxRule $initialTaxRule
  * @return void
  */
 public function processAssert(FixtureFactory $fixtureFactory, TaxRule $taxRule, Customer $customer, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, Address $address, array $shipping, BrowserInterface $browser, TaxRule $initialTaxRule = null)
 {
     $this->initialTaxRule = $initialTaxRule;
     $this->taxRule = $taxRule;
     $this->checkoutCart = $checkoutCart;
     $this->shipping = $shipping;
     if ($this->initialTaxRule !== null) {
         $this->taxRuleCode = $this->taxRule->hasData('code') ? $this->taxRule->getCode() : $this->initialTaxRule->getCode();
     } else {
         $this->taxRuleCode = $this->taxRule->getCode();
     }
     // Creating simple product with custom tax class
     /** @var \Magento\Tax\Test\Fixture\TaxClass $taxProductClass */
     $taxProductClass = $taxRule->getDataFieldConfig('tax_product_class')['source']->getFixture()[0];
     $this->productSimple = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_100_dollar_for_tax_rule', 'data' => ['tax_class_id' => ['tax_product_class' => $taxProductClass]]]);
     $this->productSimple->persist();
     // Customer login
     $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run();
     // Clearing shopping cart and adding product to shopping cart
     $checkoutCart->open()->getCartBlock()->clearShoppingCart();
     $browser->open($_ENV['app_frontend_url'] . $this->productSimple->getUrlKey() . '.html');
     $catalogProductView->getViewBlock()->clickAddToCart();
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     // Estimate Shipping and Tax
     $checkoutCart->open();
     $checkoutCart->getShippingBlock()->openEstimateShippingAndTax();
     $checkoutCart->getShippingBlock()->fill($address);
     $checkoutCart->getShippingBlock()->clickGetQuote();
     $checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
     $this->assert();
 }
 /**
  * Assert that specified prices are actual on category, product and cart pages.
  *
  * @param InjectableFixture $product
  * @param array $prices
  * @param int $qty
  * @param CmsIndex $cmsIndex
  * @param CatalogCategoryView $catalogCategoryView
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCart
  * @param FixtureFactory $fixtureFactory
  * @return void
  */
 public function processAssert(InjectableFixture $product, array $prices, $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, FixtureFactory $fixtureFactory)
 {
     $this->cmsIndex = $cmsIndex;
     $this->catalogCategoryView = $catalogCategoryView;
     $this->catalogProductView = $catalogProductView;
     $this->checkoutCart = $checkoutCart;
     //Preconditions
     $address = $fixtureFactory->createByCode('address', ['dataset' => 'US_address_NY']);
     $shipping = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed'];
     $actualPrices = [];
     //Assertion steps
     $productCategory = $product->getCategoryIds()[0];
     $this->openCategory($productCategory);
     $actualPrices = $this->getCategoryPrices($product, $actualPrices);
     $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
     $catalogProductView->getViewBlock()->fillOptions($product);
     $actualPrices = $this->getProductPagePrices($actualPrices);
     $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($qty);
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $this->checkoutCart->open();
     $this->fillEstimateBlock($address, $shipping);
     $actualPrices = $this->getCartPrices($product, $actualPrices);
     $actualPrices = $this->getTotals($actualPrices);
     //Prices verification
     $message = 'Prices from dataset should be equal to prices on frontend.';
     \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message);
 }
 /**
  * Assert message is appeared on "Compare Products" page.
  *
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView)
 {
     $actualMessage = $catalogProductView->getMessagesBlock()->getSuccessMessages();
     \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_MESSAGE, $actualMessage, 'Wrong success message is displayed.' . "\nExpected: " . self::SUCCESS_MESSAGE . "\nActual: " . $actualMessage);
 }