/**
  * Create product
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     Factory::getApp()->magentoBackendLoginUser();
     $createProductPage = Factory::getPageFactory()->getCatalogProductNew();
     $createProductPage->open(['type' => $fixture->getDataConfig()['create_url_params']['type'], 'set' => $fixture->getDataConfig()['create_url_params']['set']]);
     $createProductPage->getProductForm()->fill($fixture);
     $createProductPage->getFormPageActions()->save();
     $createProductPage->getMessagesBlock()->assertSuccessMessage();
 }
Beispiel #2
0
 /**
  * Post request for creating simple product
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null;
     $data = $this->prepareData($fixture, $prefix);
     return ['id' => $this->createProduct($data, $config)];
 }
 /**
  * Assert that duplicated product is found by sku and has correct product type, product template,
  * product status disabled and out of stock
  *
  * @param FixtureInterface $product
  * @param CatalogProductIndex $productGrid
  * @return void
  */
 public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid)
 {
     $config = $product->getDataConfig();
     $filter = ['name' => $product->getName(), 'visibility' => $product->getVisibility(), 'status' => 'Disabled', 'sku' => $product->getSku() . '-1', 'type' => ucfirst($config['create_url_params']['type']) . ' Product', 'price_to' => number_format($product->getPrice(), 2)];
     $productGrid->open()->getProductGrid()->search($filter);
     $filter['price_to'] = '$' . $filter['price_to'];
     \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter, false), 'Product duplicate is absent in Products grid.');
 }
 /**
  * Page initialization
  *
  * @param FixtureInterface $fixture
  * @return void
  */
 public function init(FixtureInterface $fixture)
 {
     $dataConfig = $fixture->getDataConfig();
     $params = isset($dataConfig['create_url_params']) ? $dataConfig['create_url_params'] : array();
     foreach ($params as $paramName => $paramValue) {
         $this->_url .= '/' . $paramName . '/' . $paramValue;
     }
 }
Beispiel #5
0
 /**
  * Get cart item block
  *
  * @param FixtureInterface $product
  * @return \Magento\Checkout\Test\Block\Cart\CartItem
  */
 public function getCartItem(FixtureInterface $product)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     $cartItem = null;
     if ($this->hasRender($typeId)) {
         $cartItem = $this->callRender($typeId, 'getCartItem', ['product' => $product]);
     } else {
         $cartItemBlock = $this->_rootElement->find(sprintf($this->cartItemByProductName, $product->getName()), Locator::SELECTOR_XPATH);
         $cartItem = $this->blockFactory->create('Magento\\Checkout\\Test\\Block\\Cart\\CartItem', ['element' => $cartItemBlock]);
     }
     return $cartItem;
 }
 /**
  * Click on "Save" button
  *
  * @param FixtureInterface|null $product [optional]
  * @return void
  */
 public function save(FixtureInterface $product = null)
 {
     $typeId = null;
     if ($product) {
         $dataConfig = $product->getDataConfig();
         $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     }
     if ($this->hasRender($typeId)) {
         $this->callRender($typeId, 'save', ['product' => $product]);
     } else {
         $this->_rootElement->find($this->saveButton)->click();
         $this->waitForElementNotVisible($this->loader, Locator::SELECTOR_XPATH);
         $this->waitForElementNotVisible($this->loaderOld, Locator::SELECTOR_XPATH);
     }
 }
Beispiel #7
0
 /**
  * Post request for creating bundle product
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return mixed|string
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null;
     $data = $this->_prepareData($fixture->getData('fields'), $prefix);
     if ($fixture->getData('category_id')) {
         $data['product']['category_ids'] = $fixture->getData('category_id');
     }
     $url = $this->_getUrl($config);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Beispiel #8
0
 /**
  * Fill in the option specified for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     /** @var CatalogProductSimple $product */
     if ($this->hasRender($typeId)) {
         $this->callRender($typeId, 'fillOptions', ['product' => $product]);
     } else {
         $optionsCheckoutData = [];
         if ($product instanceof InjectableFixture) {
             /** @var CatalogProductSimple $product */
             $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : [];
             $checkoutData = $product->getCheckoutData();
             $productCheckoutData = isset($checkoutData['custom_options']) ? $checkoutData['custom_options'] : [];
             $optionsCheckoutData = $this->prepareCheckoutData($customOptions, $productCheckoutData);
         }
         $this->getCustomOptionsBlock()->fillCustomOptions($optionsCheckoutData);
     }
 }
 /**
  * Fill the product form
  *
  * @param FixtureInterface $product
  * @param Element|null $element [optional]
  * @param FixtureInterface|null $category [optional]
  * @return FormTabs
  */
 public function fill(FixtureInterface $product, Element $element = null, FixtureInterface $category = null)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     if ($this->hasRender($typeId)) {
         $renderArguments = ['product' => $product, 'element' => $element, 'category' => $category];
         $this->callRender($typeId, 'fill', $renderArguments);
     } else {
         $tabs = $this->getFieldsByTabs($product);
         if (null === $category && $product instanceof DataFixture) {
             $categories = $product->getCategories();
             $category = reset($categories);
         }
         if ($category) {
             $tabs['product-details']['category_ids']['value'] = $category instanceof InjectableFixture ? $category->getName() : $category->getCategoryName();
         }
         $this->showAdvancedSettings();
         $this->fillTabs($tabs, $element);
     }
     return $this;
 }
Beispiel #10
0
 /**
  * Create category
  *
  * @param FixtureInterface $fixture [optional]
  * @return int|null
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $parentCategory = $fixture->getData('category_path/input_value');
     $url = $this->_getUrl($config, $parentCategory);
     $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null;
     $params = $this->_prepareData($fixture->getData('fields'), $prefix);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $params);
     $response = $curl->read();
     $curl->close();
     preg_match("~.+\\/id\\/(\\d+)\\/.+~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
 /**
  * POST request for creating downloadable product
  *
  * @param FixtureInterface $fixture [optional]
  * @return int id of created product
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $this->getUrl($config), '1.0', [], $this->prepareData($fixture->getData('fields'), isset($config['input_prefix']) ? $config['input_prefix'] : null));
     $response = $curl->read();
     $curl->close();
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return $matches[1];
 }