Skip to content

Commit

Permalink
Merge pull request #102 from magento-qmt/develop
Browse files Browse the repository at this point in the history
[Mavericks] Re-factor product end-to-end tests
  • Loading branch information
Dmytro Aponasenko committed Feb 19, 2015
2 parents a9e59f8 + 27d5cfa commit deefb61
Show file tree
Hide file tree
Showing 428 changed files with 4,733 additions and 9,173 deletions.
9 changes: 5 additions & 4 deletions dev/tests/functional/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
**/var
/composer.lock
/vendor
/generated
/var
/config/*
/generated
/lib/Magento/Mtf/Util/Generate/testcase.xml
/vendor
!/config/application.yml.dist
!/config/handler.yml.dist
!/config/isolation.yml.dist
!/config/server.yml.dist
phpunit.xml
/lib/Magento/Mtf/Util/Generate/testcase.xml
credentials.xml
2 changes: 1 addition & 1 deletion dev/tests/functional/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"magento/mtf": "1.0.0-rc17",
"magento/mtf": "1.0.0-rc18",
"php": "~5.5.0|~5.6.0",
"phpunit/phpunit": "4.1.0",
"phpunit/phpunit-selenium": ">=1.2",
Expand Down
27 changes: 27 additions & 0 deletions dev/tests/functional/credentials.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<replace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/magento/mtf/Magento/Mtf/Fixture/InjectableFixture/etc/replace.xsd">

<field path="section/carriers_dhl_id/value" value="" />
<field path="section/carriers_dhl_password/value" value="" />
<field path="section/carriers_dhl_account/value" value="" />

<field path="section/carriers_fedex_account/value" value="" />
<field path="section/carriers_fedex_meter_number/value" value="" />
<field path="section/carriers_fedex_key/value" value="" />
<field path="section/carriers_fedex_password/value" value="" />

<field path="section/carriers_ups_password/value" value="" />
<field path="section/carriers_ups_username/value" value="" />
<field path="section/carriers_ups_access_license_number/value" value="" />
<field path="section/carriers_ups_shipper_number/value" value="" />

<field path="section/carriers_usps_userid/value" value="" />
<field path="section/carriers_usps_password/value" value="" />
</replace>
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,62 @@
use Magento\Mtf\Client\Locator;

/**
* Class OptgroupselectElement
* Typified element class for option group selectors
* Typified element class for option group selectors.
*/
class OptgroupselectElement extends SelectElement
{
/**
* Option group selector
* Option locator.
*
* @var string
*/
protected $optionByIndex = './/option';

/**
* Option group selector.
*
* @var string
*/
protected $optGroup = 'optgroup[option[contains(.,"%s")]]';

/**
* Get the value of form element
* Option group locator.
*
* @var string
*/
protected $optionGroupValue = ".//optgroup[@label = '%s']/option[text() = '%s']";

/**
* Get the value of form element.
*
* @return string
* @throws \Exception
*/
public function getValue()
{
$this->eventManager->dispatchEvent(['get_value'], [(string)$this->getAbsoluteSelector()]);
$selectedLabel = trim(parent::getValue());

$selectedLabel = '';
$labels = $this->getElements($this->optionByIndex, Locator::SELECTOR_XPATH);
foreach ($labels as $label) {
if ($label->isSelected()) {
$selectedLabel = $label->getText();
break;
}
}
if ($selectedLabel == '') {
throw new \Exception('Selected value has not been found in optgroup select.');
}

$element = $this->find(sprintf($this->optGroup, $selectedLabel), Locator::SELECTOR_XPATH);
$value = trim($element->getAttribute('label'), chr(0xC2) . chr(0xA0));
$value .= '/' . $selectedLabel;

return $value;
}

/**
* Select value in dropdown which has option groups
* Select value in dropdown which has option groups.
*
* @param string $value
* @return void
Expand All @@ -46,6 +73,8 @@ public function setValue($value)
{
$this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
list($group, $option) = explode('/', $value);
parent::setOptionGroupValue($group, $option);
$xpath = sprintf($this->optionGroupValue, $group, $option);
$option = $this->find($xpath, Locator::SELECTOR_XPATH);
$option->click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*/
class SelectstoreElement extends SelectElement
{
/**
* Option locator
*
* @var string
*/
protected $optionByIndex = './/optgroup/option[%d]';

/**
* Store option group selector.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function setValue($value)
$this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);

$this->clear();

if ($value == '') {
return;
}
foreach (str_split($value) as $symbol) {
$input = $this->find($this->suggest);
$input->click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function addBlockToFactory(array $item)
$params = "\$element, \$driver = null, \$config = []";

$this->factoryContent .= "\n /**\n";
$this->factoryContent .= " * @return \\{$item['class']}\n";
$this->factoryContent .= " * @return {$item['class']}\n";
$this->factoryContent .= " */\n";
$this->factoryContent .= " public function get{$methodNameSuffix}({$params})\n";
$this->factoryContent .= " {";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function addFixtureToFactory($item)

$this->factoryContent .= "\n";
$this->factoryContent .= " /**\n";
$this->factoryContent .= " * @return \\{$item['class']}\n";
$this->factoryContent .= " * @return {$item['class']}\n";
$this->factoryContent .= " */\n";
$this->factoryContent .= " public function get{$methodNameSuffix}(array \$placeholders = [])\n";
$this->factoryContent .= " {";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function _addPageToFactory($item)
$fallbackComment = $this->_buildFallbackComment($item);

$this->factoryContent .= "\n /**\n";
$this->factoryContent .= " * @return \\{$item['class']}\n";
$this->factoryContent .= " * @return {$item['class']}\n";
$this->factoryContent .= " */\n";
$this->factoryContent .= " public function get{$methodNameSuffix}()\n";
$this->factoryContent .= " {";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function _addToFactory($item)
$fallbackComment = $this->_buildFallbackComment($item);

$this->factoryContent .= "\n /**\n";
$this->factoryContent .= " * @return \\{$item['class']}\n";
$this->factoryContent .= " * @return {$item['class']}\n";
$this->factoryContent .= " */\n";
$this->factoryContent .= " public function get{$methodNameSuffix}(array \$defaultConfig = [], "
. "array \$defaultData = [])\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getCollection(array $fixture)
{
$type = $fixture['type'];
$method = $type . 'Collection';
if (!method_exists($this, $method)) {
if (!method_exists($this, $method) || empty($fixture['collection'])) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

namespace Magento\Mtf\Util\Protocol\CurlTransport;

use Magento\Customer\Test\Fixture\CustomerInjectable;
use Magento\Customer\Test\Fixture\Customer;
use Magento\Mtf\Util\Protocol\CurlInterface;
use Magento\Mtf\Util\Protocol\CurlTransport;

/**
* Class FrontendDecorator
* Curl transport on frontend
*/
class FrontendDecorator implements CurlInterface
Expand Down Expand Up @@ -48,9 +47,9 @@ class FrontendDecorator implements CurlInterface
* Constructor
*
* @param CurlTransport $transport
* @param CustomerInjectable $customer
* @param Customer $customer
*/
public function __construct(CurlTransport $transport, CustomerInjectable $customer)
public function __construct(CurlTransport $transport, Customer $customer)
{
$this->transport = $transport;
$this->authorize($customer);
Expand All @@ -59,11 +58,11 @@ public function __construct(CurlTransport $transport, CustomerInjectable $custom
/**
* Authorize customer on frontend
*
* @param CustomerInjectable $customer
* @param Customer $customer
* @throws \Exception
* @return void
*/
protected function authorize(CustomerInjectable $customer)
protected function authorize(Customer $customer)
{
$url = $_ENV['app_frontend_url'] . 'customer/account/login/';
$this->transport->write(CurlInterface::POST, $url);
Expand Down Expand Up @@ -117,6 +116,8 @@ protected function initCookies()
* @param array $headers
* @param array $params
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function write($method, $url, $httpVer = '1.1', $headers = [], $params = [])
{
Expand Down
1 change: 1 addition & 0 deletions dev/tests/functional/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<env name="module_whitelist" value="Magento_Install" />
<env name="report_file_name" value="test-cases-report.xml"/>
<env name="basedir" value="var/log" />
<env name="credentials_file_path" value="./credentials.xml.dist" />
</php>

</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,12 @@ public function getOptions(FixtureInterface $product = null)
*/
public function fillOptions(FixtureInterface $product)
{
if ($product instanceof InjectableFixture) {
/** @var \Magento\Bundle\Test\Fixture\BundleProduct $product */
$checkoutData = $product->getCheckoutData();
$bundleCheckoutData = isset($checkoutData['options']['bundle_options'])
? $checkoutData['options']['bundle_options']
: [];
} else {
// TODO: Removed after refactoring(removed) old product fixture.
/** @var \Magento\Bundle\Test\Fixture\BundleFixed $product */
$bundleCheckoutData = $product->getSelectionData();
}
/** @var \Magento\Bundle\Test\Fixture\BundleProduct $product */
$checkoutData = $product->getCheckoutData();
$bundleCheckoutData = isset($checkoutData['options']['bundle_options'])
? $checkoutData['options']['bundle_options']
: [];

if (!$this->getBundleBlock()->isVisible()) {
$this->clickCustomize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Magento\Bundle\Test\Block\Catalog\Product\View\Type;

use Magento\Bundle\Test\Fixture\Bundle as BundleDataFixture;
use Magento\Bundle\Test\Fixture\BundleProduct;
use Magento\Catalog\Test\Page\Product\CatalogProductView;
use Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option;
Expand Down Expand Up @@ -93,15 +92,9 @@ public function addToCart(BundleProduct $product, CatalogProductView $catalogPro
*/
public function getOptions(FixtureInterface $product)
{
if ($product instanceof InjectableFixture) {
/** @var BundleProduct $product */
$bundleSelections = $product->getBundleSelections();
$bundleOptions = isset($bundleSelections['bundle_options']) ? $bundleSelections['bundle_options'] : [];
} else {
// TODO: Removed after refactoring(removed) old product fixture.
/** @var BundleDataFixture $product */
$bundleOptions = $product->getBundleOptions();
}
/** @var BundleProduct $product */
$bundleSelections = $product->getBundleSelections();
$bundleOptions = isset($bundleSelections['bundle_options']) ? $bundleSelections['bundle_options'] : [];

$listFormOptions = $this->getListOptions();
$formOptions = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,31 @@

namespace Magento\Bundle\Test\Constraint;

use Magento\Bundle\Test\Fixture\BundleProduct;
use Magento\Catalog\Test\Fixture\Category;
use Magento\Bundle\Test\Fixture\BundleProduct;
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
use Magento\Cms\Test\Page\CmsIndex;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Catalog\Test\Constraint\AssertProductInCategory;
use Magento\Mtf\Fixture\FixtureInterface;

/**
* Check bundle product on the category page.
*/
class AssertBundleInCategory extends AbstractConstraint
class AssertBundleInCategory extends AssertProductInCategory
{
/* tags */
const SEVERITY = 'low';
/* end tags */

/**
* Check bundle product on the category page.
*
* @param CatalogCategoryView $catalogCategoryView
* @param CmsIndex $cmsIndex
* @param BundleProduct $product
* @param Category $category
* @return void
*/
public function processAssert(
CatalogCategoryView $catalogCategoryView,
CmsIndex $cmsIndex,
BundleProduct $product,
Category $category
) {
//Open category view page
$cmsIndex->open();
$cmsIndex->getTopmenu()->selectCategoryByName($category->getName());

//Process asserts
$this->assertPrice($product, $catalogCategoryView);
}

/**
* Verify product price on category view page.
*
* @param BundleProduct $bundle
* @param FixtureInterface $bundle
* @param CatalogCategoryView $catalogCategoryView
* @return void
*/
protected function assertPrice(BundleProduct $bundle, CatalogCategoryView $catalogCategoryView)
protected function assertPrice(FixtureInterface $bundle, CatalogCategoryView $catalogCategoryView)
{
/** @var BundleProduct $bundle */
$priceData = $bundle->getDataFieldConfig('price')['source']->getPreset();
//Price from/to verification
$priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ protected function assertPrice(
? $originalProduct->getPriceType()
: $product->getPriceType();
$catalogProductView->getViewBlock()->addToCart($product);
$catalogProductView->getMessagesBlock()->waitSuccessMessage();
$checkoutCartView->open();
$cartItem = $checkoutCartView->getCartBlock()->getCartItem($product);
$specialPrice = 0;
if (isset($bundleData['group_price'])) {
Expand Down
Loading

0 comments on commit deefb61

Please sign in to comment.