/** * Assert that deleted attribute can't be added to attribute set on Product Page via Add Attribute control. * * @param CatalogProductAttribute $productAttribute * @param CatalogProductIndex $productGrid * @param CatalogProductNew $newProductPage * @return void */ public function processAssert(CatalogProductAttribute $productAttribute, CatalogProductIndex $productGrid, CatalogProductNew $newProductPage) { $productGrid->open(); $productGrid->getGridPageActionBlock()->addProduct('simple'); $newProductPage->getFormPageActions()->addNewAttribute(); $filter = ['label' => $productAttribute->getFrontendLabel()]; \PHPUnit_Framework_Assert::assertFalse($newProductPage->getProductForm()->getAttributesSearchGrid()->isRowVisible($filter), 'Attribute \'' . $productAttribute->getFrontendLabel() . '\' is found in Attributes grid.'); }
/** * Checking not exist attribute in search result. * * @param CatalogProductAttribute $productAttribute * @return bool */ public function isExistAttributeInSearchResult($productAttribute) { $this->find($this->actionToggle)->click(); $this->find($this->suggest)->setValue($productAttribute->getFrontendLabel()); $this->waitResult(); $attributeSelector = sprintf($this->searchArrtibute, $productAttribute->getFrontendLabel()); return $this->find($this->searchResult)->find($attributeSelector, Locator::SELECTOR_XPATH)->isVisible(); }
/** * Delete product attribute step. * * @return void */ public function run() { $filter = $this->attribute->hasData('attribute_code') ? ['attribute_code' => $this->attribute->getAttributeCode()] : ['frontend_label' => $this->attribute->getFrontendLabel()]; $this->catalogProductAttributeIndex->open(); if ($this->catalogProductAttributeIndex->getGrid()->isRowVisible($filter)) { $this->catalogProductAttributeIndex->getGrid()->searchAndOpen($filter); $this->catalogProductAttributeNew->getPageActions()->delete(); } }
/** * Assert check whether the attribute is used to create a configurable products * * @param CatalogProductAttribute $productAttribute * @param CatalogProductAttribute $attribute * @param CatalogProductIndex $productGrid * @param FixtureFactory $fixtureFactory * @param CatalogProductNew $newProductPage */ public function processAssert(CatalogProductAttribute $attribute, CatalogProductIndex $productGrid, FixtureFactory $fixtureFactory, CatalogProductNew $newProductPage, CatalogProductAttribute $productAttribute = null) { $this->attribute = !is_null($productAttribute) ? $productAttribute : $attribute; $productGrid->open(); $productGrid->getGridPageActionBlock()->addProduct('configurable'); $productConfigurable = $fixtureFactory->createByCode('catalogProductConfigurable', ['dataSet' => 'default', 'data' => ['configurable_attributes_data' => ['preset' => 'one_variation', 'attributes' => [$this->attribute]]]]); $productBlockForm = $newProductPage->getForm(); $productBlockForm->fill($productConfigurable); \PHPUnit_Framework_Assert::assertTrue($newProductPage->getForm()->findAttribute($this->attribute->getFrontendLabel()), "Product attribute is absent on the product page."); }
/** * Checking not exist attribute in search result * * @param CatalogProductAttribute $productAttribute * @return bool */ public function isExistAttributeInSearchResult($productAttribute) { $this->find($this->actionToggle)->click(); $this->find($this->suggest)->setValue($productAttribute->getFrontendLabel()); $this->waitResult(); if ($this->find($this->searchResult)->getText() == $productAttribute->getFrontendLabel()) { return true; } return false; }
/** * Check whether the attribute is unique. * * @param CatalogProductIndex $catalogProductIndex * @param CatalogProductEdit $catalogProductEdit * @param CatalogProductAttribute $attribute * @param CatalogProductSimple $product, * @param FixtureFactory $fixtureFactory * @throws \Exception * @return void */ public function processAssert(CatalogProductIndex $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, CatalogProductSimple $product, FixtureFactory $fixtureFactory) { $simpleProduct = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_with_category_with_anchor', 'data' => ['attribute_set_id' => ['attribute_set' => $product->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()], 'custom_attribute' => $attribute]]); $catalogProductIndex->open()->getGridPageActionBlock()->addProduct('simple'); $productForm = $catalogProductEdit->getProductForm(); $productForm->fill($simpleProduct); $catalogProductEdit->getFormPageActions()->save(); $failedAttributes = $productForm->getRequireNoticeAttributes($simpleProduct); $actualMessage = isset($failedAttributes['product-details'][$attribute->getFrontendLabel()]) ? $failedAttributes['product-details'][$attribute->getFrontendLabel()] : null; \PHPUnit_Framework_Assert::assertEquals(sprintf(self::UNIQUE_MESSAGE, $attribute->getFrontendLabel()), $actualMessage, 'JS error notice on product edit page is not equal to expected.'); }
/** * Check whether the attribute filter is displayed on the frontend in Layered navigation. * * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param CmsIndex $cmsIndex * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, InjectableFixture $product, CatalogProductAttribute $attribute, CmsIndex $cmsIndex, FixtureFactory $fixtureFactory) { $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_with_category_with_anchor', 'data' => ['category_ids' => ['presets' => null, 'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]]]])->persist(); $cmsIndex->open()->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogCategoryView->getLayeredNavigationBlock()->getFilters()), 'Attribute is absent in layered navigation on category page.'); }
/** * Check whether attribute is displayed in the advanced search form on the frontend. * * @param CatalogProductAttribute $attribute * @param AdvancedSearch $advancedSearch * @return void */ public function processAssert(CatalogProductAttribute $attribute, AdvancedSearch $advancedSearch) { $advancedSearch->open(); $formLabels = $advancedSearch->getForm()->getFormlabels(); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $formLabels), 'Attribute is absent on advanced search form.'); }
/** * Assert that product attribute can be used on promo rules conditions. * * @param CatalogRuleIndex $catalogRuleIndex * @param CatalogRuleNew $catalogRuleNew * @param CatalogProductAttribute $attribute * @return void */ public function processAssert(CatalogRuleIndex $catalogRuleIndex, CatalogRuleNew $catalogRuleNew, CatalogProductAttribute $attribute) { $catalogRuleIndex->open(); $catalogRuleIndex->getGridPageActions()->addNew(); $catalogRuleNew->getEditForm()->openTab('conditions'); \PHPUnit_Framework_Assert::assertTrue($catalogRuleNew->getEditForm()->isAttributeInConditions($attribute->getFrontendLabel()), 'Product attribute can\'t be used on promo rules conditions.'); }
/** * Assert that deleted attribute can't be used for Products' Export * * @param AdminExportIndex $exportIndex * @param CatalogProductAttribute $attribute * @param ImportExport $export * @return void */ public function processAssert(AdminExportIndex $exportIndex, CatalogProductAttribute $attribute, ImportExport $export) { $exportIndex->open(); $exportIndex->getExportForm()->fill($export); $filter = ['attribute_code' => $attribute->getAttributeCode()]; \PHPUnit_Framework_Assert::assertFalse($exportIndex->getFilterExport()->isRowVisible($filter), 'Attribute \'' . $attribute->getFrontendLabel() . '\' is present in Filter export grid'); }
/** * Check whether there is an opportunity to compare products using given attribute. * * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param BrowserInterface $browser * @param CatalogProductView $catalogProductView * @param CatalogProductCompare $catalogProductCompare */ public function processAssert(InjectableFixture $product, CatalogProductAttribute $attribute, BrowserInterface $browser, CatalogProductView $catalogProductView, CatalogProductCompare $catalogProductCompare) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); $catalogProductView->getViewBlock()->clickAddToCompare(); $catalogProductCompare->open(); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogProductCompare->getCompareProductsBlock()->getComparableAttributes()), 'Attribute is absent on product compare page.'); }
/** * Check if attribute value contains tag. * * @param CatalogProductAttribute $attribute * @return bool */ public function hasHtmlTagInAttributeValue(CatalogProductAttribute $attribute) { $data = $attribute->getData(); $defaultValue = preg_grep('/^default_value/', array_keys($data)); $selector = $this->resolveHtmlStructure($data[array_shift($defaultValue)]); $element = $this->getProductAttributes()[$attribute->getFrontendLabel()]; return $this->checkHtmlTagStructure($element, $selector)->isVisible(); }
/** * Run DeleteProductAttributeEntity test. * * @param CatalogProductAttribute $attribute * @param CatalogProductAttributeIndex $attributeIndex * @param CatalogProductAttributeNew $attributeNew * @return void */ public function testDeleteProductAttribute(CatalogProductAttribute $attribute, CatalogProductAttributeIndex $attributeIndex, CatalogProductAttributeNew $attributeNew) { //Precondition $attribute->persist(); //Steps $attributeIndex->open(); $attributeIndex->getGrid()->searchAndOpen(['frontend_label' => $attribute->getFrontendLabel()]); $attributeNew->getPageActions()->delete(); }
/** * Assert that after save a attribute set on edit product set page displays: * 1. Correct attribute set name in Attribute set name field passed from fixture * 2. Created Product Attribute (if was added) * * @param CatalogProductSetIndex $productSet * @param CatalogProductSetEdit $productSetEdit * @param CatalogAttributeSet $attributeSet * @param CatalogProductAttribute $productAttribute * @return void */ public function processAssert(CatalogProductSetIndex $productSet, CatalogProductSetEdit $productSetEdit, CatalogAttributeSet $attributeSet, CatalogProductAttribute $productAttribute = null) { $filterAttribute = ['set_name' => $attributeSet->getAttributeSetName()]; $productSet->open(); $productSet->getGrid()->searchAndOpen($filterAttribute); \PHPUnit_Framework_Assert::assertEquals($filterAttribute['set_name'], $productSetEdit->getAttributeSetEditBlock()->getAttributeSetName(), 'Attribute Set not found' . "\nExpected: " . $filterAttribute['set_name'] . "\nActual: " . $productSetEdit->getAttributeSetEditBlock()->getAttributeSetName()); if ($productAttribute !== null) { $attributeLabel = $productAttribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue($productSetEdit->getAttributeSetEditBlock()->checkProductAttribute($attributeLabel), "Product Attribute is absent on Attribute Set Groups"); } }
/** * Assert that deleted attribute can't be added to attribute set on Product Page via Add Attribute control. * * @param CatalogProductAttribute $productAttribute * @param ConfigurableProduct $assertProduct * @param CatalogProductIndex $productGrid * @param CatalogProductNew $newProductPage * @return void */ public function processAssert(CatalogProductAttribute $productAttribute, ConfigurableProduct $assertProduct, CatalogProductIndex $productGrid, CatalogProductNew $newProductPage) { $productGrid->open(); $productGrid->getGridPageActionBlock()->addProduct('simple'); /** @var VariationsTab $variationsTab */ $newProductPage->getProductForm()->fill($assertProduct); $variationsTab = $newProductPage->getProductForm()->getSection(self::TAB_VARIATIONS); $variationsTab->createConfigurations(); $attributesGrid = $variationsTab->getAttributeBlock()->getAttributesGrid(); \PHPUnit_Framework_Assert::assertFalse($attributesGrid->isRowVisible(['frontend_label' => $productAttribute->getFrontendLabel()]), "Product attribute found in Attribute Search form."); }
/** * Checking not exist configurable attribute in search result * * @param CatalogProductAttribute $productAttribute * @return bool */ public function isExistAttributeInSearchResult(CatalogProductAttribute $productAttribute) { $attribute = $productAttribute->getFrontendLabel(); $searchResult = $this->find($this->searchResult); $this->find($this->suggest)->setValue($attribute); if (!$searchResult->isVisible()) { return false; } if ($searchResult->getText() == $attribute) { return true; } return false; }
/** * Assert check whether the attribute is used to create a configurable products. * * @param CatalogProductAttribute $attribute * @param ConfigurableProduct $assertProduct * @param CatalogProductIndex $productGrid * @param CatalogProductNew $newProductPage */ public function processAssert(CatalogProductAttribute $attribute, ConfigurableProduct $assertProduct, CatalogProductIndex $productGrid, CatalogProductNew $newProductPage) { $productGrid->open(); $productGrid->getGridPageActionBlock()->addProduct('configurable'); $productBlockForm = $newProductPage->getProductForm(); $productBlockForm->fill($assertProduct); $productBlockForm->openTab('variations'); /** @var \Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Tab\Variations\Config $variationsTab */ $variationsTab = $productBlockForm->getTab('variations'); $variationsTab->createConfigurations(); $attributesGrid = $variationsTab->getAttributeBlock()->getAttributesGrid(); \PHPUnit_Framework_Assert::assertTrue($attributesGrid->isRowVisible(['frontend_label' => $attribute->getFrontendLabel()]), "Product attribute is absent on the product page."); }
/** * 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)); }
/** * Check if attribute is available in conditions. * * @param CatalogProductAttribute $attribute * @return bool */ public function isAttributeInConditions(CatalogProductAttribute $attribute) { $this->_rootElement->find($this->addButton)->click(); return $this->_rootElement->find(sprintf($this->conditionFormat, $attribute->getFrontendLabel()), Locator::SELECTOR_XPATH)->isVisible(); }
/** * Assert that after deleted product attribute cannot be found by attribute code. * * @param CatalogProductAttributeIndex $attributeIndex * @param CatalogProductAttribute $attribute * @return void */ public function processAssert(CatalogProductAttributeIndex $attributeIndex, CatalogProductAttribute $attribute) { $filter = ['attribute_code' => $attribute->getAttributeCode()]; $attributeIndex->open(); \PHPUnit_Framework_Assert::assertFalse($attributeIndex->getGrid()->isRowVisible($filter), 'Attribute \'' . $attribute->getFrontendLabel() . '\' is present in Attribute grid.'); }
/** * Look on the scope of product attribute in the grid. * * @param CatalogProductAttributeIndex $catalogProductAttributeIndex * @param CatalogProductAttribute $attribute * @return void */ public function processAssert(CatalogProductAttributeIndex $catalogProductAttributeIndex, CatalogProductAttribute $attribute) { $filter = ['frontend_label' => $attribute->getFrontendLabel(), 'is_global' => $attribute->getIsGlobal()]; \PHPUnit_Framework_Assert::assertTrue($catalogProductAttributeIndex->open()->getGrid()->isRowVisible($filter), 'Attribute is not global.'); }
/** * Check out if the attribute in the navigation bar on the search results page in Layered navigation. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, InjectableFixture $product, CatalogProductAttribute $attribute) { $cmsIndex->open()->getSearchBlock()->search($product->getName()); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogCategoryView->getLayeredNavigationBlock()->getFilters()), 'Attribute is absent in layered navigation on search page.'); }
/** * Checking exist configurable attribute in search result * * @param CatalogProductAttribute $productAttribute * @return bool */ public function isExistAttributeInSearchResult(CatalogProductAttribute $productAttribute) { return $this->isExistValueInSearchResult($productAttribute->getFrontendLabel()); }
/** * Checking not exist attribute in search result. * * @param CatalogProductAttribute $productAttribute * @return bool */ public function isExistAttributeInSearchResult($productAttribute) { $this->find($this->topPage, Locator::SELECTOR_XPATH)->hover(); $this->find($this->actionToggle)->click(); return $this->isExistValueInSearchResult($productAttribute->getFrontendLabel()); }
/** * Check whether the attribute is visible on the frontend. * * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param CatalogProductView $catalogProductView * @param BrowserInterface $browser * @return void */ public function processAssert(InjectableFixture $product, CatalogProductAttribute $attribute, CatalogProductView $catalogProductView, BrowserInterface $browser) { $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); \PHPUnit_Framework_Assert::assertTrue(in_array($attribute->getFrontendLabel(), $catalogProductView->getAdditionalInformationBlock()->getAttributeLabels()), 'Attribute is not visible on product page in additional info block on frontend.'); }
/** * Get default attribute code according to attribute label. * * @param CatalogProductAttribute $attribute * @return string */ protected function createAttributeCode(CatalogProductAttribute $attribute) { $label = $attribute->getFrontendLabel(); return strtolower(preg_replace('@[\\W\\s]+@', '_', $label)); }
/** * Assert that attribute present in sort dropdown on search results page on frontend. * * @param CmsIndex $cmsIndex * @param CatalogsearchResult $catalogsearchResult * @param CatalogProductAttribute $attribute * @param InjectableFixture $product * @return void */ public function processAssert(CmsIndex $cmsIndex, CatalogsearchResult $catalogsearchResult, CatalogProductAttribute $attribute, InjectableFixture $product) { $cmsIndex->open()->getSearchBlock()->search($product->getName()); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogsearchResult->getListProductBlock()->getSortByValues()), 'Attribute is absent in sort dropdown on search results page on frontend.'); }