示例#1
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $attributesData = $product->getConfigurableAttributesData()['attributes_data'];
         $matrix = $product->getConfigurableAttributesData()['matrix'];
         $checkoutOptions = $product->getCheckoutData()['options']['configurable_options'];
         $optionsDetails = [];
         $matrixKey = [];
         $optionsPrice = 0;
         foreach ($checkoutOptions as $checkoutOption) {
             $titleKey = $checkoutOption['title'];
             $valueKey = $checkoutOption['value'];
             $attributeName = $attributesData[$titleKey]['frontend_label'];
             $optionLabel = $attributesData[$titleKey]['options'][$valueKey]['label'];
             $optionsDetails[] = "{$attributeName}{$optionLabel}";
             $matrixKey[] = "{$titleKey}:{$valueKey}";
             $optionsPrice += $attributesData[$titleKey]['options'][$valueKey]['pricing_value'];
         }
         $optionsDetails = implode(' ', $optionsDetails);
         $matrixKey = implode(' ', $matrixKey);
         $productDisplay = $productName . 'SKU: ' . $matrix[$matrixKey]['sku'] . $optionsDetails;
     } else {
         $productDisplay = $productName . 'SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->escapeCurrency($this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText());
 }
 /**
  * Assert that video is not displayed in admin panel.
  *
  * @param CatalogProductIndex $productGrid
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CatalogProductIndex $productGrid, InjectableFixture $product)
 {
     $filter = ['sku' => $product->getSku()];
     $productGrid->open();
     $productGrid->getProductGrid()->search($filter);
     $src = $productGrid->getProductGrid()->getBaseImageSource();
     \PHPUnit_Framework_Assert::assertTrue(strpos($src, '/placeholder/') !== false, 'Product image is displayed in product grid when it should not');
 }
 /**
  * Assert that video data received from external service is correct.
  *
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductEdit $editProductPage
  * @param InjectableFixture $product
  * @param array $video
  * @return void
  */
 public function processAssert(CatalogProductIndex $productGrid, CatalogProductEdit $editProductPage, InjectableFixture $product, array $video)
 {
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $editProductPage->getProductForm()->openSection('images-and-videos');
     $imagesTab = $editProductPage->getProductForm()->getSection('images-and-videos');
     $result = $imagesTab->clickFirstVideo()->getVideoDialog()->validate($video);
     \PHPUnit_Framework_Assert::assertTrue($result, 'Video data received from external service is not correct.');
 }
 /**
  * Get associated items for grouped product.
  *
  * @param InjectableFixture $product
  * @return array
  */
 protected function getAssociatedItems(InjectableFixture $product)
 {
     $cartItems = [];
     /** @var GroupedProduct $product */
     $associatedProducts = $product->getDataFieldConfig('associated')['source']->getProducts();
     foreach ($associatedProducts as $product) {
         $cartItems[$product->getSku()] = parent::getCartItem($product);
     }
     return $cartItems;
 }
 /**
  * Check whether the attribute is mandatory.
  *
  * @param CatalogProductIndex $catalogProductIndex
  * @param CatalogProductEdit $catalogProductEdit
  * @param CatalogProductAttribute $attribute
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CatalogProductIndex $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, InjectableFixture $product)
 {
     $catalogProductIndex->open()->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $productForm = $catalogProductEdit->getProductForm();
     $productForm->getAttributeElement($attribute)->setValue('');
     $catalogProductEdit->getFormPageActions()->save();
     $failedAttributes = $productForm->getRequireNoticeAttributes($product);
     $actualMessage = $failedAttributes['product-details'][$attribute->getFrontendLabel()];
     \PHPUnit_Framework_Assert::assertEquals(self::REQUIRE_MESSAGE, $actualMessage, 'JS error notice on product edit page is not equal to expected.');
 }
 /**
  * Assert that configurable options available on configurable product Edit form on backend.
  *
  * @param CatalogProduct $catalogProductIndex
  * @param CatalogProductEdit $catalogProductEdit
  * @param CatalogProductAttribute $attribute
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CatalogProduct $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, InjectableFixture $product)
 {
     $options = $attribute->getOptions();
     $attributeOptionsFromFixture = [];
     foreach ($options as $option) {
         $attributeOptionsFromFixture[] = $option['admin'];
     }
     $catalogProductIndex->open()->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $productForm = $catalogProductEdit->getProductForm();
     $attributeOptions = $productForm->getAttributeElement($attribute)->getValues();
     \PHPUnit_Framework_Assert::assertEquals($attributeOptionsFromFixture, $attributeOptions);
 }
 /**
  * Assert form data equals fixture data.
  *
  * @param InjectableFixture $product
  * @param CatalogProduct $productGrid
  * @param CatalogProductEdit $productPage
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProduct $productGrid, CatalogProductEdit $productPage)
 {
     $this->catalogProductEdit = $productPage;
     $filter = ['sku' => $product->getSku()];
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen($filter);
     $productData = $product->getData();
     $fixtureData = $this->prepareFixtureData($productData, $this->sortFields);
     $formData = $this->prepareFormData($productPage->getProductForm()->getData($product), $this->sortFields);
     $error = $this->verifyData($fixtureData, $formData);
     \PHPUnit_Framework_Assert::assertTrue(empty($error), $error);
 }
 /**
  * Check whether the attribute is mandatory.
  *
  * @param CatalogProductIndex $catalogProductIndex
  * @param CatalogProductEdit $catalogProductEdit
  * @param CatalogProductAttribute $attribute
  * @param InjectableFixture $product
  * @param string $sectionName
  * @return void
  */
 public function processAssert(CatalogProductIndex $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, InjectableFixture $product, $sectionName)
 {
     $catalogProductIndex->open()->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $productForm = $catalogProductEdit->getProductForm();
     if (!$productForm->checkAttributeLabel($attribute)) {
         $productForm->openSection($sectionName);
     }
     $productForm->getAttributeElement($attribute)->setValue('');
     $catalogProductEdit->getFormPageActions()->save();
     $validationErrors = $productForm->getSection($sectionName)->getValidationErrors();
     $actualMessage = isset($validationErrors[$attribute->getFrontendLabel()]) ? $validationErrors[$attribute->getFrontendLabel()] : '';
     \PHPUnit_Framework_Assert::assertEquals(self::REQUIRE_MESSAGE, $actualMessage, 'JS error notice on product edit page is not equal to expected.');
 }
 /**
  * Assert all product attribute options on product creation form.
  *
  * @param InjectableFixture $product
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductAttribute $attribute
  * @param CatalogProductEdit $productEdit
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProductIndex $productGrid, CatalogProductAttribute $attribute, CatalogProductEdit $productEdit)
 {
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $attributeOptions = $attribute->getOptions();
     $options[] = $attribute->getFrontendLabel();
     foreach ($attributeOptions as $option) {
         $options[] = $option['admin'];
     }
     $productAttributeOptions = $productEdit->getProductForm()->getAttributeElement($attribute)->getText();
     $productOptions = explode("\n", $productAttributeOptions);
     $diff = array_diff($options, $productOptions);
     \PHPUnit_Framework_Assert::assertTrue(empty($diff), "Products attribute options are absent on product form: " . implode(', ', $diff));
 }
示例#10
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $configurableAttributes = $product->getConfigurableAttributes();
         $productOptions = $product->getCheckoutData()['options']['configurable_options'];
         $checkoutOption = reset($productOptions);
         $attributeKey = $checkoutOption['title'];
         $optionKey = $checkoutOption['value'];
         $attributeValue = $configurableAttributes[$attributeKey]['label']['value'];
         $optionValue = $configurableAttributes[$attributeKey][$optionKey]['option_label']['value'];
         $productDisplay = $productName . ' SKU: ' . $product->getVariationSku($checkoutOption);
         $productDisplay .= ' ' . $attributeValue . ' ' . $optionValue;
     } else {
         $productDisplay = $productName . ' SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText();
 }
 /**
  * Verify product displaying on frontend.
  *
  * @param InjectableFixture $product
  * @return array
  */
 protected function isNotDisplayingOnFrontendAssert(InjectableFixture $product)
 {
     $errors = [];
     //Check that product is not available by url
     $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     if ($this->catalogProductView->getViewBlock()->isVisible()) {
         $errors[] = '- product view block is visible in product page.';
     }
     //Check that product can't be found
     $this->cmsIndex->open()->getSearchBlock()->search($product->getSku());
     if ($this->catalogSearchResult->getListProductBlock()->isProductVisible($product)) {
         $errors[] = '- successful product search.';
     }
     //Check that product is not available in category page
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $this->category->getName();
     $this->cmsIndex->open()->getTopmenu()->selectCategory($categoryName);
     $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product);
     $bottomToolBar = $this->catalogCategoryView->getBottomToolbar();
     while (!$isProductVisible && $bottomToolBar->nextPage()) {
         $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product);
     }
     if ($isProductVisible) {
         $errors[] = "- product with name '{$product->getName()}' is found in this category.";
     }
     return $errors;
 }
 /**
  * Assert that created attribute is displayed on product form.
  *
  * @param InjectableFixture $product
  * @param CatalogProduct $productGrid
  * @param CatalogProductEdit $productEdit
  * @param CatalogProductAttribute $attribute
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProduct $productGrid, CatalogProductEdit $productEdit, CatalogProductAttribute $attribute)
 {
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     \PHPUnit_Framework_Assert::assertTrue($productEdit->getProductForm()->checkAttributeLabel($attribute->getData()), "Product Attribute is absent on Product form.");
 }
 /**
  * Open products on backend.
  *
  * @return void
  */
 public function run()
 {
     $this->catalogProductIndex->open();
     $this->catalogProductIndex->getProductGrid()->searchAndOpen(['sku' => $this->product->getSku()]);
 }
 /**
  * Assert that product cannot be found via Quick Search using searchable product attributes.
  *
  * @param CatalogsearchResult $catalogSearchResult
  * @param CmsIndex $cmsIndex
  * @param InjectableFixture $product
  * @return void
  */
 public function processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, InjectableFixture $product)
 {
     $cmsIndex->open();
     $cmsIndex->getSearchBlock()->search($product->getSku());
     \PHPUnit_Framework_Assert::assertFalse($catalogSearchResult->getListProductBlock()->isProductVisible($product), 'Product was found by SKU.');
 }
 /**
  * Check product on product grid.
  *
  * @param InjectableFixture $product
  * @param CatalogProduct $productGrid
  * @return void
  */
 public function assert(InjectableFixture $product, CatalogProduct $productGrid)
 {
     $filter = ['sku' => $product->getSku(), 'name' => $product->getName()];
     \PHPUnit_Framework_Assert::assertFalse($productGrid->getProductGrid()->isRowVisible($filter), "Product with sku {$filter['sku']} and name {$filter['name']} is present in Products grid.");
 }
 /**
  * Prepare filter for product grid.
  *
  * @return array
  */
 protected function prepareFilter()
 {
     $filter = ['type' => $this->getProductType(), 'sku' => $this->product->getSku(), 'status' => $this->product->getStatus()];
     return $filter;
 }
 /**
  * Add appurtenant products and save product.
  *
  * @param InjectableFixture $product
  * @param array $appurtenantData
  * @return void
  */
 protected function addAppurtenantProducts(InjectableFixture $product, array $appurtenantData)
 {
     $this->productGrid->open();
     $this->productGrid->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
     $form = $this->editProductPage->getProductForm();
     $form->openTab($this->tabName);
     $appurtenantTab = $form->getTabElement($this->tabName);
     $appurtenantData[$this->appurtenantType['formIndex']]['value'] = $this->prepareData($appurtenantData[$this->appurtenantType['formIndex']]['value']);
     $appurtenantTab->fillFormTab($appurtenantData);
     $this->editProductPage->getFormPageActions()->save();
 }
 /**
  * Return sku of product.
  *
  * @param InjectableFixture $product
  * @return string
  */
 protected function getItemSku(InjectableFixture $product)
 {
     return $product->getSku();
 }
 /**
  * Get product sku.
  *
  * @param InjectableFixture $product
  * @return string
  */
 public function getProductSku(InjectableFixture $product)
 {
     return $product->getSku();
 }