Skip to content

Commit

Permalink
Merge pull request #272 from magento-qmt/develop
Browse files Browse the repository at this point in the history
[Mavericks] Re-factor end-to-end tests and maintain functional tests
  • Loading branch information
Aponasenko, Dmytro(daponasenko) committed May 5, 2015
2 parents ade3933 + 18a38a2 commit 99dca3e
Show file tree
Hide file tree
Showing 79 changed files with 1,865 additions and 697 deletions.
314 changes: 203 additions & 111 deletions dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class ListProduct extends Block
*/
protected $productItem = './/*[contains(@class,"product-item-link") and normalize-space(text())="%s"]/ancestor::li';

/**
* Locator for product item link.
*
* @var string
*/
protected $productItemLink = '.product-item-link';

/**
* Sorter dropdown selector.
*
Expand All @@ -46,6 +53,23 @@ public function getProductItem(FixtureInterface $product)
);
}

/**
* Get product names list.
*
* @return array
*/
public function getProductNames()
{
$itemLinks = $this->_rootElement->getElements($this->productItemLink);
$productNames = [];

foreach ($itemLinks as $itemLink) {
$productNames[] = trim($itemLink->getText());
}

return $productNames;
}

/**
* Get all terms used in sort.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Magento\Catalog\Test\Handler\Category;

use Magento\Catalog\Test\Fixture\Category;
use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Mtf\Handler\Curl as AbstractCurl;
use Magento\Mtf\Util\Protocol\CurlInterface;
Expand Down Expand Up @@ -58,20 +59,24 @@ class Curl extends AbstractCurl implements CategoryInterface
*
* @param FixtureInterface|null $fixture [optional]
* @return array
* @throws \Exception
*/
public function persist(FixtureInterface $fixture = null)
{
$data = $this->prepareData($fixture);

$url = $_ENV['app_backend_url'] . 'catalog/category/save/store/0/parent/' . $data['general']['parent_id'] . '/';
$curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
$curl->write(CurlInterface::POST, $url, '1.0', [], $data);
$response = $curl->read();
$curl->close();

if (!strpos($response, 'data-ui-id="messages-message-success"')) {
$this->_eventManager->dispatchEvent(['curl_failed'], [$response]);
throw new \Exception('Category creation by curl handler was not successful!');
}

preg_match('#http://.+/id/(\d+).+store/#m', $response, $matches);
$id = isset($matches[1]) ? (int)$matches[1] : null;

return ['id' => $id];
}

Expand All @@ -83,12 +88,16 @@ public function persist(FixtureInterface $fixture = null)
*/
protected function prepareData(FixtureInterface $fixture)
{
$data['general'] = $this->replaceMappingData($fixture->getData());
$data['is_anchor'] = isset($data['is_anchor']) ? $data['is_anchor'] : 0;
$data = ['general' => $this->replaceMappingData($fixture->getData())];
$data['general']['is_anchor'] = isset($data['general']['is_anchor']) ? $data['general']['is_anchor'] : 0;

if ($fixture->hasData('landing_page')) {
$data['general']['landing_page'] = $this->getBlockId($fixture->getLandingPage());
}

$data['category_products'] = $this->prepareCategoryProducts($fixture);
unset($data['general']['category_products']);

$diff = array_diff($this->dataUseConfig, array_keys($data['general']));
if (!empty($diff)) {
$data['use_config'] = $diff;
Expand All @@ -97,6 +106,28 @@ protected function prepareData(FixtureInterface $fixture)
return $data;
}

/**
* Prepare category products data for curl.
*
* @param FixtureInterface $category
* @return array
*/
protected function prepareCategoryProducts(FixtureInterface $category)
{
$categoryProducts = [];
$defaultPosition = 0;

/** @var Category $category */
if ($category->hasData('category_products')) {
$products = $category->getDataFieldConfig('category_products')['source']->getProducts();
foreach ($products as $product) {
$categoryProducts[$product->getId()] = $defaultPosition;
}
}

return json_encode($categoryProducts);
}

/**
* Getting block id by name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd">
<page name="CatalogCategoryView" area="Category" mca="catalog/category/view" module="Magento_Catalog">
<block name="titleBlock" class="Magento\Theme\Test\Block\Html\Title" locator=".page-title-wrapper h1.page-title .base" strategy="css selector"/>
<block name="layeredNavigationBlock" class="Magento\LayeredNavigation\Test\Block\Navigation" locator=".block.filter" strategy="css selector"/>
<block name="widgetView" class="Magento\Widget\Test\Block\WidgetView" locator=".widget" strategy="css selector"/>
<block name="viewBlock" class="Magento\Catalog\Test\Block\Category\View" locator="#maincontent" strategy="css selector"/>
<block name="listProductBlock" class="Magento\Catalog\Test\Block\Product\ListProduct" locator=".products.wrapper.grid" strategy="css selector"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@
</field>
</dataset>

<dataset name="product_20_dollar">
<field name="attribute_set_id" xsi:type="array">
<item name="dataSet" xsi:type="string">default</item>
</field>
<field name="name" xsi:type="string">product_20_dollar %isolation%</field>
<field name="sku" xsi:type="string">sku_product_20_dollar_%isolation%</field>
<field name="is_virtual" xsi:type="string">No</field>
<field name="weight" xsi:type="string">1</field>
<field name="quantity_and_stock_status" xsi:type="array">
<item name="qty" xsi:type="string">1000</item>
<item name="is_in_stock" xsi:type="string">In Stock</item>
</field>
<field name="price" xsi:type="array">
<item name="value" xsi:type="string">20</item>
</field>
<field name="tax_class_id" xsi:type="array">
<item name="dataSet" xsi:type="string">taxable_goods</item>
</field>
<field name="website_ids" xsi:type="array">
<item name="0" xsi:type="string">Main Website</item>
</field>
<field name="visibility" xsi:type="string">Catalog, Search</field>
<field name="url_key" xsi:type="string">product-20-dollar-%isolation%</field>
</dataset>

<dataset name="product_with_url_key">
<field name="name" xsi:type="string">Simple Product %isolation%</field>
<field name="sku" xsi:type="string">sku_simple_product_%isolation%</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<data name="category/data/available_product_listing_config" xsi:type="string">Yes</data>
<data name="category/data/default_product_listing_config" xsi:type="string">Yes</data>
<data name="category/data/use_config_price_range" xsi:type="string">Yes</data>
<data name="category/data/category_products_data/preset" xsi:type="string">default</data>
<data name="category/data/category_products/dataSet" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForm" />
Expand Down Expand Up @@ -97,7 +96,6 @@
<data name="category/data/default_sort_by" xsi:type="string">Price</data>
<data name="category/data/use_config_price_range" xsi:type="string">No</data>
<data name="category/data/layered_navigation_price_step" xsi:type="string">50</data>
<data name="category/data/category_products_data/preset" xsi:type="string">default</data>
<data name="category/data/category_products/dataSet" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForm" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ abstract class AbstractCatalogRuleEntityTest extends Injectable
*/
protected $adminCache;

/**
* Fixture CatalogRule.
*
* @var array
*/
protected $catalogRules = [];

/**
* Fixture factory.
*
Expand Down Expand Up @@ -80,12 +73,6 @@ public function __inject(
*/
public function tearDown()
{
foreach ($this->catalogRules as $catalogRule) {
$filter = ['name' => $catalogRule->getName()];
$this->catalogRuleIndex->open();
$this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
$this->catalogRuleNew->getFormPageActions()->delete();
}
$this->catalogRules = [];
$this->objectManager->create('\Magento\CatalogRule\Test\TestStep\DeleteAllCatalogRulesStep')->run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
use Magento\Catalog\Test\Fixture\CatalogProductSimple;

/**
* Test Creation for Apply several CatalogPriceRuleEntity
*
* Test Flow:
* Preconditions:
* 1. Execute before each variation:
* - Delete all active catalog price rules
* - Create catalog price rule from dataSet using Curl
* 1. Execute before each variation:
* - Delete all active catalog price rules
* - Create catalog price rule from dataSet using Curl
*
* Steps:
* 1. Apply all created rules
* 2. Create simple product
* 3. Perform all assertions
* 1. Apply all created rules.
* 2. Create simple product.
* 3. Perform all assertions.
*
* @group Catalog_Price_Rules_(MX)
* @ZephyrId MAGETWO-24780
Expand All @@ -32,7 +30,7 @@ class ApplySeveralCatalogPriceRuleEntityTest extends AbstractCatalogRuleEntityTe
/* end tags */

/**
* Apply several catalog price rules
* Apply several catalog price rules.
*
* @param array $catalogRulesOriginal
* @return array
Expand All @@ -44,15 +42,15 @@ public function testApplySeveralCatalogPriceRules(array $catalogRulesOriginal)
if ($catalogPriceRule == '-') {
continue;
}
$this->catalogRules[$key] = $this->fixtureFactory->createByCode(
$catalogRules[$key] = $this->fixtureFactory->createByCode(
'catalogRule',
['dataSet' => $catalogPriceRule]
);
$this->catalogRules[$key]->persist();
$catalogRules[$key]->persist();

$filter = [
'name' => $this->catalogRules[$key]->getName(),
'rule_id' => $this->catalogRules[$key]->getId(),
'name' => $catalogRules[$key]->getName(),
'rule_id' => $catalogRules[$key]->getId(),
];
$this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
$this->catalogRuleNew->getFormPageActions()->saveAndApply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
use Magento\CatalogRule\Test\Fixture\CatalogRule;

/**
* Test Creation for Create CatalogPriceRuleEntity
*
* Test Flow:
* Steps:
* 1. Log in as default admin user.
* 2. Go to Marketing > Catalog Price Rules
* 3. Press "+" button to start create new catalog price rule
* 4. Fill in all data according to data set
* 5. Save rule
* 6. Perform appropriate assertions
* 2. Go to Marketing > Catalog Price Rules.
* 3. Press "+" button to start create new catalog price rule.
* 4. Fill in all data according to data set.
* 5. Save rule.
* 6. Perform appropriate assertions.
*
* @group Catalog_Price_Rules_(MX)
* @ZephyrId MAGETWO-24341
Expand All @@ -42,8 +40,5 @@ public function testCreateCatalogPriceRule(CatalogRule $catalogPriceRule)
$this->catalogRuleIndex->getGridPageActions()->addNew();
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule);
$this->catalogRuleNew->getFormPageActions()->save();

// Prepare data for tear down
$this->catalogRules[] = $catalogPriceRule;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
use Magento\Customer\Test\Fixture\CustomerGroupInjectable;

/**
* Test Coverage for Create Catalog Rule
*
* Test Flow:
* Steps:
* 1. Log in as default admin user.
* 2. Go to Marketing > Catalog Price Rules
* 3. Press "+" button to start create new catalog price rule
* 4. Fill in all data according to data set
* 5. Save rule
* 6. Apply newly created catalog rule
* 7. Create simple product
* 8. Clear cache
* 9. Perform all assertions
* 2. Go to Marketing > Catalog Price Rules.
* 3. Press "+" button to start create new catalog price rule.
* 4. Fill in all data according to data set.
* 5. Save rule.
* 6. Apply newly created catalog rule.
* 7. Create simple product.
* 8. Clear cache.
* 9. Perform all assertions.
*
* @ticketId MAGETWO-23036
*/
Expand All @@ -37,7 +35,7 @@ class CreateCatalogRuleTest extends AbstractCatalogRuleEntityTest
/* end tags */

/**
* Create Catalog Price Rule
* Create Catalog Price Rule.
*
* @param CatalogRule $catalogPriceRule
* @param Customer $customer
Expand Down Expand Up @@ -70,9 +68,6 @@ public function testCreate(
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace);
$this->catalogRuleNew->getFormPageActions()->save();

// Prepare data for tear down
$this->catalogRules[] = $catalogPriceRule;

// Apply Catalog Price Rule
$this->catalogRuleIndex->getGridPageActions()->applyRules();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
use Magento\CatalogRule\Test\Fixture\CatalogRule;

/**
* Test Creation for UpdateCatalogPriceRuleEntity
*
* Test Flow:
* Preconditions:
* 1. Catalog Price Rule is created
* 1. Catalog Price Rule is created.
*
* Steps:
* 1. Login to backend
* 2. Navigate to MARKETING > Catalog Price Rules
* 3. Click Catalog Price Rule from grid
* 4. Edit test value(s) according to dataSet
* 5. Click 'Save'/ 'Apply' button
* 6. Create simple product with category
* 7. Perform all asserts
* 1. Login to backend.
* 2. Navigate to MARKETING > Catalog Price Rules.
* 3. Click Catalog Price Rule from grid.
* 4. Edit test value(s) according to dataSet.
* 5. Click 'Save'/ 'Apply' button.
* 6. Create simple product with category.
* 7. Perform all asserts.
*
* @group Catalog_Price_Rules_(MX)
* @ZephyrId MAGETWO-25187
Expand All @@ -37,7 +35,7 @@ class UpdateCatalogPriceRuleEntityTest extends AbstractCatalogRuleEntityTest
/* end tags */

/**
* Update catalog price rule
* Update catalog price rule.
*
* @param CatalogRule $catalogPriceRule
* @param CatalogRule $catalogPriceRuleOriginal
Expand Down Expand Up @@ -81,9 +79,6 @@ public function testUpdateCatalogPriceRule(
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace);
$this->catalogRuleNew->getFormPageActions()->$saveAction();

// Prepare data for tear down
$this->catalogRules[] = $catalogPriceRule;

// Create simple product with category
$productSimple->persist();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct(
public function run()
{
$this->catalogRuleIndex->open();
$this->catalogRuleIndex->getCatalogRuleGrid()->resetFilter();
while ($this->catalogRuleIndex->getCatalogRuleGrid()->isFirstRowVisible()) {
$this->catalogRuleIndex->getCatalogRuleGrid()->openFirstRow();
$this->catalogRuleNew->getFormPageActions()->delete();
Expand Down
Loading

0 comments on commit 99dca3e

Please sign in to comment.