/** * Apply set up configuration profile. * * @return void */ public function apply() { parent::apply(); if (file_exists(dirname(dirname(dirname(MTF_BP))) . '/app/etc/config.php')) { $this->objectManager->create('\\Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $this->config])->run(); } }
/** * Assert order is not visible in customer account on frontend * * @param OrderInjectable $order * @param Customer $customer * @param ObjectManager $objectManager * @param CustomerAccountIndex $customerAccountIndex * @param OrderHistory $orderHistory * @param string $status * @return void */ public function processAssert(OrderInjectable $order, Customer $customer, ObjectManager $objectManager, CustomerAccountIndex $customerAccountIndex, OrderHistory $orderHistory, $status) { $filter = ['id' => $order->getId(), 'status' => $status]; $customerLogin = $objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer]); $customerLogin->run(); $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); \PHPUnit_Framework_Assert::assertFalse($orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), 'Order with following data \'' . implode(', ', $filter) . '\' is present in Orders block on frontend.'); }
/** * Assert that order is present in Orders grid on frontend. * * @param OrderInjectable $order * @param Customer $customer * @param ObjectManager $objectManager * @param CustomerAccountIndex $customerAccountIndex * @param OrderHistory $orderHistory * @param string $status * @param string $orderId * @param string|null $statusToCheck * @return void */ public function processAssert(OrderInjectable $order, Customer $customer, ObjectManager $objectManager, CustomerAccountIndex $customerAccountIndex, OrderHistory $orderHistory, $status, $orderId = '', $statusToCheck = null) { $filter = ['id' => $order->hasData('id') ? $order->getId() : $orderId, 'status' => $statusToCheck === null ? $status : $statusToCheck]; $objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); $errorMessage = implode(', ', $filter); \PHPUnit_Framework_Assert::assertTrue($orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), 'Order with following data \'' . $errorMessage . '\' is absent in Orders block on frontend.'); }
/** * Review order contents and place order. * * @return array */ public function run() { $this->orderReviewExpress->getReviewBlock()->selectShippingMethod($this->shipping); foreach ($this->prices as $priceName => $value) { $assertName = 'Assert' . ucfirst($priceName) . 'OrderReview'; $assert = $this->objectManager->create('Magento\\Checkout\\Test\\Constraint\\' . $assertName); $assert->processAssert($this->checkoutOnepage, $value); } $this->orderReviewExpress->getReviewBlock()->placeOrder(); return ['orderId' => $this->checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId()]; }
/** * Fill customer addresses and proceed to next step. * * @return void */ public function run() { $addresses = $this->customer->getDataFieldConfig('address')['source']->getAddresses(); $bindings = []; foreach ($this->products as $key => $product) { $productName = $product->getName(); $addressRender = $this->objectManager->create(\Magento\Customer\Test\Block\Address\Renderer::class, ['address' => $addresses[$key], 'type' => 'oneline']); $bindings[$productName] = $addressRender->render(); } $this->addresses->getAddressesBlock()->selectAddresses($bindings); }
/** * Run a Mtf application * * @param $applicationName * @param array $arguments * @return mixed * @throws \DomainException */ public function run($applicationName, array $arguments = []) { try { if (!$this->_locator) { $locatorFactory = new \Magento\Mtf\ObjectManagerFactory(); $this->_locator = $locatorFactory->create(); } return $this->_locator->create($applicationName, $arguments)->launch(); } catch (\Exception $exception) { $message = "Error happened during application run.\n"; $message .= $exception->getMessage(); throw new \DomainException($message); } }
/** * @inheritdoc * * @return array */ public function run() { $this->objectManager->create(\Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class, ['customer' => $this->customer])->run(); $this->customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Credit Cards'); $myCreditCardsBlock = $this->myCreditCardsPage->getCreditCardsBlock(); $creditCardData = $this->creditCard->getData(); $creditCardNumber = preg_grep('/([a-z]+)_number/', array_flip($creditCardData)); $lastFourDigits = substr(key($creditCardNumber), -4, 4); $availableCreditCards = $myCreditCardsBlock->getCreditCards(); if (key_exists($lastFourDigits, $availableCreditCards)) { $myCreditCardsBlock->deleteCreditCard($availableCreditCards[$lastFourDigits]); } $this->assertCreditCardDeletedMessage->processAssert($this->myCreditCardsPage); return ['deletedCreditCard' => $lastFourDigits]; }
/** * initialize data */ protected function _initData() { /** @var \Magento\Mtf\System\Config $systemConfig */ $systemConfig = ObjectManager::getInstance()->create('Magento\\Mtf\\System\\Config'); $superAdminPassword = $systemConfig->getConfigParam('application/backend_user_credentials/password'); $this->_data = ['fields' => ['email' => ['value' => '*****@*****.**'], 'firstname' => ['value' => 'firstname%isolation%'], 'lastname' => ['value' => 'lastname%isolation%'], 'password' => ['value' => '%password%'], 'password_confirmation' => ['value' => '%password%'], 'roles' => ['value' => ['1']], 'username' => ['value' => 'admin%isolation%'], 'current_password' => ['value' => $superAdminPassword]]]; }
/** * Process checkout. * * @param string $checkoutMethod * @param Address $billingAddress * @param array $shipping * @param array $payment * @return void */ protected function processCheckout($checkoutMethod, Address $billingAddress, array $shipping, array $payment) { $this->objectManager->create('Mage\\Checkout\\Test\\TestStep\\SelectCheckoutMethodStep', ['checkoutMethod' => $checkoutMethod])->run(); $this->objectManager->create('Mage\\Checkout\\Test\\TestStep\\FillBillingInformationStep', ['billingAddress' => $billingAddress])->run(); $this->objectManager->create('Mage\\Checkout\\Test\\TestStep\\FillShippingMethodStep', ['shipping' => $shipping])->run(); $this->objectManager->create('Mage\\Checkout\\Test\\TestStep\\SelectPaymentMethodStep', ['payment' => $payment])->run(); }
/** * Create products. * * @param array $products * @return array */ protected function createProducts(array $products) { $resultProduct = []; foreach ($products as $key => $product) { $resultProduct[$key] = $this->objectManager->create('Mage\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => implode(',', $product)])->run()['products']; } return $resultProduct; }
/** * 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.'); }
/** * @construct * @param array $params * @param string $data */ public function __construct(array $params, $data = '') { $this->params = $params; /** @var \Magento\Mtf\Config\DataInterface $systemConfig */ if ($data == '%current_password%') { $systemConfig = ObjectManager::getInstance()->create('Magento\\Mtf\\Config\\DataInterface'); $data = $systemConfig->get('application/0/backendPassword/0/value'); } $this->data = $data; }
/** * @constructor * @param array $params * @param array $data */ public function __construct(array $params, array $data = []) { $this->params = $params; $this->products = isset($data['products']) ? $data['products'] : []; foreach ($this->products as $product) { $classItem = 'Magento\\' . $this->getModuleName($product) . '\\Test\\Fixture\\Cart\\Item'; $item = ObjectManager::getInstance()->create($classItem, ['product' => $product]); $this->data[] = $item; } }
/** * Prepare data * * @param array $viewsReport * @return array */ protected function prepareData(array $viewsReport) { foreach ($viewsReport as $key => $reportFilter) { if (in_array($key, $this->dateFields)) { $date = ObjectManager::getInstance()->create('\\Magento\\Backend\\Test\\Fixture\\Source\\Date', ['params' => [], 'data' => ['pattern' => $reportFilter]]); $viewsReport[$key] = $date->getData(); } } return $viewsReport; }
/** * Open backend page and log in if needed. * * @param array $params * @return $this */ public function open(array $params = []) { $systemConfig = ObjectManager::getInstance()->create('Magento\\Mtf\\Config\\DataInterface'); $admin = ['username' => ['value' => $systemConfig->get('application/0/backendLogin/0/value')], 'password' => ['value' => $systemConfig->get('application/0/backendPassword/0/value')]]; $this->adminAuthLogin = ObjectManager::getInstance()->create('Mage\\Adminhtml\\Test\\Page\\AdminAuthLogin'); $this->dashboard = ObjectManager::getInstance()->create('Mage\\Adminhtml\\Test\\Page\\Adminhtml\\Dashboard'); if (!$this->dashboard->getAdminPanelHeader()->isVisible()) { $this->loginSuperAdmin($admin); } return parent::open($params); }
/** * Prepare data * * @param array $customersReport * @return array */ protected function prepareData(array $customersReport) { foreach ($customersReport as $name => $reportFilter) { if ($name === 'report_period') { continue; } $date = ObjectManager::getInstance()->create('\\Magento\\Backend\\Test\\Fixture\\Source\\Date', ['params' => [], 'data' => ['pattern' => $reportFilter]]); $customersReport[$name] = $date->getData(); } return $customersReport; }
/** * Review order contents and place order. * * @return array */ public function run() { $this->orderReviewExpress->getReviewBlock()->selectShippingMethod($this->shipping); foreach ($this->prices as $priceName => $value) { $assertName = 'Assert' . ucfirst($priceName) . 'OrderReview'; $assert = $this->objectManager->create('Magento\\Checkout\\Test\\Constraint\\' . $assertName); $assert->processAssert($this->checkoutOnepage, $value); } $this->orderReviewExpress->getReviewBlock()->placeOrder(); $order = $this->fixtureFactory->createByCode('orderInjectable', ['data' => ['entity_id' => ['products' => $this->products]]]); return ['orderId' => $this->checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId(), 'order' => $order]; }
/** * Click delete customer address button. * * @param Address $addressToDelete * @return $this */ public function deleteCustomerAddress(Address $addressToDelete) { $addressRenderer = $this->objectManager->create(\Magento\Customer\Test\Block\Address\Renderer::class, ['address' => $addressToDelete, 'type' => 'html']); $addressToDelete = $addressRenderer->render(); $dataList = explode("\n", $addressToDelete); $dataList = implode("') and contains(.,'", $dataList); $this->_rootElement->find(sprintf($this->addressSelector, $dataList), Locator::SELECTOR_XPATH)->find($this->deleteAddress)->click(); $element = $this->browser->find($this->confirmModal); /** @var \Magento\Ui\Test\Block\Adminhtml\Modal $modal */ $modal = $this->blockFactory->create(\Magento\Ui\Test\Block\Adminhtml\Modal::class, ['element' => $element]); $modal->acceptAlert(); return $this; }
/** * 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); }
/** * Verify Terms and Conditions checkbox is absent on checkout page. * * @param ObjectManager $objectManager * @param $products * @param CheckoutOnepage $checkoutOnepage * @param $shipping * @param $payment * @param CheckoutAgreement $agreement * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function processAssert(ObjectManager $objectManager, $products, CheckoutOnepage $checkoutOnepage, $shipping, $payment, CheckoutAgreement $agreement) { $shippingAddressData = ['shippingAddress' => ['dataSet' => 'US_address_1']]; $productsData = ['products' => $products]; $shippingMethodData = ['shipping' => $shipping]; $paymentData = ['payment' => $payment]; $products = $objectManager->create('Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', $productsData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\AddProductsToTheCartStep', $products)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\ProceedToCheckoutStep')->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\FillShippingAddressStep', $shippingAddressData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\FillShippingMethodStep', $shippingMethodData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\SelectPaymentMethodStep', $paymentData)->run(); \PHPUnit_Framework_Assert::assertFalse($checkoutOnepage->getAgreementReview()->checkAgreement($agreement), 'Checkout Agreement \'' . $agreement->getName() . '\' is present in the Place order step.'); }
/** * Set integration data to configuration file. * * @param Integration $integration * @return void */ protected function setConfiguration(Integration $integration) { $fileConfig = MTF_BP . '/etc/config.xml'; $dom = new \DOMDocument(); if (!file_exists($fileConfig)) { copy(MTF_BP . '/etc/config.xml.dist', $fileConfig); } $dom->load($fileConfig); $webapiToken = (new \DOMXPath($dom))->query('//config/handler/webapi/token')->item(0); if ($webapiToken) { $webapiToken->nodeValue = $integration->getToken(); } else { $webapi = (new \DOMXPath($dom))->query('//config/handler/webapi')->item(0); $webapi->appendChild($dom->createElement('token', $integration->getToken())); } $dom->save($fileConfig); $this->configuration = $this->objectManager->create('Magento\\Mtf\\Config\\DataInterface'); }
/** * Find element on the page * * @param string $selector * @param string $strategy * @param string $type = select|multiselect|checkbox|null OR custom class with full namespace * @param ElementInterface $context * @return ElementInterface * @throws \Exception */ public function find($selector, $strategy = Locator::SELECTOR_CSS, $type = null, ElementInterface $context = null) { $locator = new Locator($selector, $strategy); $this->eventManager->dispatchEvent(['find'], [__METHOD__, $locator]); $className = 'Magento\\Mtf\\Client\\ElementInterface'; if (null !== $type) { if (strpos($type, '\\') === false) { $type = ucfirst(strtolower($type)); if (class_exists('Magento\\Mtf\\Client\\Element\\' . $type . 'Element')) { $className = 'Magento\\Mtf\\Client\\Element\\' . $type . 'Element'; } } else { if (!class_exists($type) && !interface_exists($type)) { throw new \Exception(sprintf('Requested interface or class "%s" does not exists!', $type)); } $className = $type; } } return $this->objectManager->create($className, ['driver' => $this, 'locator' => $locator, 'context' => $context]); }
/** * 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 ObjectManager $objectManager * @param string $products * @param CheckoutOnepage $checkoutOnepage * @param CheckoutOnepageSuccess $checkoutOnepageSuccess * @param AssertOrderSuccessPlacedMessage $assertOrderSuccessPlacedMessage * @param array $shipping * @param array $payment * @param CheckoutAgreement $agreement * @return void */ public function processAssert(ObjectManager $objectManager, $products, CheckoutOnepage $checkoutOnepage, CheckoutOnepageSuccess $checkoutOnepageSuccess, AssertOrderSuccessPlacedMessage $assertOrderSuccessPlacedMessage, $shipping, $payment, CheckoutAgreement $agreement) { $paymentBlock = $checkoutOnepage->getPaymentBlock(); $shippingAddressData = ['shippingAddress' => ['dataSet' => 'US_address_1']]; $productsData = ['products' => $products]; $shippingMethodData = ['shipping' => $shipping]; $paymentData = ['payment' => $payment]; $products = $objectManager->create('Magento\\Catalog\\Test\\TestStep\\CreateProductsStep', $productsData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\AddProductsToTheCartStep', $products)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\ProceedToCheckoutStep')->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\FillShippingAddressStep', $shippingAddressData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\FillShippingMethodStep', $shippingMethodData)->run(); $objectManager->create('Magento\\Checkout\\Test\\TestStep\\SelectPaymentMethodStep', $paymentData)->run(); $paymentBlock->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', $agreement); $paymentBlock->getSelectedPaymentMethodBlock()->clickPlaceOrder(); $assertOrderSuccessPlacedMessage->processAssert($checkoutOnepageSuccess); }
/** * Add products to cart * * @param array $products * @return void */ protected function addToCart(array $products) { $addToCartStep = ObjectManager::getInstance()->create('Magento\\Checkout\\Test\\TestStep\\AddProductsToTheCartStep', ['products' => $products]); $addToCartStep->run(); }
/** * Delete all tax rules after test. * * @return void */ public static function tearDownAfterClass() { ObjectManager::getInstance()->create('Mage\\Tax\\Test\\TestStep\\DeleteAllTaxRulesStep')->run(); }
/** * Prepare test suite and apply application state. * * @return AppState */ public function prepareSuite() { $this->init(); return $this->objectManager->create('Magento\\Mtf\\TestSuite\\AppState'); }
/** * Login customer to frontend. * * @param Customer $customer * @return void */ public function loginCustomer(Customer $customer) { $loginCustomerOnFrontendStep = ObjectManager::getInstance()->create('Mage\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer]); $loginCustomerOnFrontendStep->run(); }
/** * Create a new category and retrieve category fixture * * @param string $key * @return mixed */ protected function getCategory($key) { if (!isset($this->categories[$key])) { $category = ObjectManager::getInstance()->create('\\Magento\\Catalog\\Test\\Fixture\\Category', ['dataSet' => 'default_subcategory']); $category->persist(); $this->categories[$key] = $category; } return $this->categories[$key]; }
/** * Create products. * * @param string $products * @return array */ protected function createProducts($products) { return $this->objectManager->create('Mage\\Catalog\\Test\\TestStep\\CreateProductsStep', ['products' => $products])->run(); }
/** * Add products to wish list. * * @param array $products * @param bool $configure [optional] * @return void */ protected function addToWishlist(array $products, $configure = false) { $this->objectManager->create('Magento\\Wishlist\\Test\\TestStep\\AddProductsToWishlistStep', ['products' => $products, 'configure' => $configure])->run(); }