Skip to content

Commit 0fae435

Browse files
Merge branch 'mto-108' into pr1
2 parents ae45e6b + 991956d commit 0fae435

File tree

6 files changed

+304
-0
lines changed

6 files changed

+304
-0
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ public function getPriceTo($currency = '$')
110110
return $this->getTypePrice('price_to', $currency);
111111
}
112112

113+
/**
114+
* Get currency symbol from price block on the product page.
115+
*
116+
* @return string
117+
*/
118+
public function getCurrencySymbol()
119+
{
120+
$price = $this->getPrice('');
121+
preg_match('`(.*?)\d`', $price, $matches);
122+
return $matches[1];
123+
}
124+
113125
/**
114126
* Get price excluding tax.
115127
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CurrencySymbol\Test\Constraint;
8+
9+
use Magento\Mtf\Fixture\InjectableFixture;
10+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
11+
use Magento\Mtf\Client\BrowserInterface;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
14+
/**
15+
* Check that correct currency symbol displayed on Product Page on Custom Website.
16+
*/
17+
class AssertCurrencySymbolOnProductPageCustomWebsite extends AbstractConstraint
18+
{
19+
/**
20+
* Assert that correct currency symbol displayed on Product Page on Custom Website.
21+
*
22+
* @param InjectableFixture $product,
23+
* @param BrowserInterface $browser
24+
* @param CatalogProductView $catalogProductView
25+
* @param array $currencySymbol
26+
* @return void
27+
*/
28+
public function processAssert(
29+
InjectableFixture $product,
30+
BrowserInterface $browser,
31+
CatalogProductView $catalogProductView,
32+
array $currencySymbol = []
33+
) {
34+
$website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0];
35+
$url = $_ENV['app_frontend_url'] . 'websites/' . $website->getCode() . '/' . $product->getUrlKey() . '.html';
36+
$browser->open($url);
37+
$priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
38+
$symbolOnPage = $priceBlock->getCurrencySymbol();
39+
40+
\PHPUnit_Framework_Assert::assertEquals(
41+
$currencySymbol['customWebsite'],
42+
$symbolOnPage,
43+
'Wrong Currency Symbol is displayed on Product page on Custom website.'
44+
);
45+
}
46+
47+
/**
48+
* Returns a string representation of successful assertion.
49+
*
50+
* @return string
51+
*/
52+
public function toString()
53+
{
54+
return "Correct Currency Symbol displayed on Product page on Custom website.";
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CurrencySymbol\Test\Constraint;
8+
9+
use Magento\Mtf\Fixture\InjectableFixture;
10+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
11+
use Magento\Mtf\Client\BrowserInterface;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
14+
/**
15+
* Check that correct currency symbol displayed on Product Page on Main Website.
16+
*/
17+
class AssertCurrencySymbolOnProductPageMainWebsite extends AbstractConstraint
18+
{
19+
/**
20+
* Assert that correct currency symbol displayed on Product Page on Main Website.
21+
*
22+
* @param InjectableFixture $product,
23+
* @param BrowserInterface $browser
24+
* @param CatalogProductView $catalogProductView
25+
* @param array $currencySymbol
26+
* @return void
27+
*/
28+
public function processAssert(
29+
InjectableFixture $product,
30+
BrowserInterface $browser,
31+
CatalogProductView $catalogProductView,
32+
array $currencySymbol = []
33+
) {
34+
$browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
35+
$priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
36+
$symbolOnPage = $priceBlock->getCurrencySymbol();
37+
38+
\PHPUnit_Framework_Assert::assertEquals(
39+
$currencySymbol['mainWebsite'],
40+
$symbolOnPage,
41+
'Wrong Currency Symbol is displayed on Product page on the Main Website.'
42+
);
43+
}
44+
45+
/**
46+
* Returns a string representation of successful assertion.
47+
*
48+
* @return string
49+
*/
50+
public function toString()
51+
{
52+
return "Correct Currency Symbol displayed on Product page on the Main Website.";
53+
}
54+
}

dev/tests/functional/tests/app/Magento/CurrencySymbol/Test/Repository/ConfigData.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@
6161
</field>
6262
</dataset>
6363

64+
<dataset name="config_currency_custom_website_eur">
65+
<field name="currency/options/allow" xsi:type="array">
66+
<item name="scope" xsi:type="string">currency</item>
67+
<item name="scope_id" xsi:type="number">1</item>
68+
<item name="value" xsi:type="array">
69+
<item name="Euro" xsi:type="string">EUR</item>
70+
</item>
71+
</field>
72+
<field name="currency/options/base" xsi:type="array">
73+
<item name="scope" xsi:type="string">currency</item>
74+
<item name="label" xsi:type="string">Euro</item>
75+
<item name="scope_id" xsi:type="number">1</item>
76+
<item name="value" xsi:type="string">EUR</item>
77+
</field>
78+
<field name="currency/options/default" xsi:type="array">
79+
<item name="scope" xsi:type="string">currency</item>
80+
<item name="label" xsi:type="string">Euro</item>
81+
<item name="scope_id" xsi:type="number">1</item>
82+
<item name="value" xsi:type="string">EUR</item>
83+
</field>
84+
</dataset>
85+
6486
<dataset name="config_base_currency_ch">
6587
<field name="currency/options/allow" xsi:type="array">
6688
<item name="scope" xsi:type="string">currency</item>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CurrencySymbol\Test\TestCase;
8+
9+
use Magento\Store\Test\Fixture\Store;
10+
use Magento\Mtf\TestCase\Injectable;
11+
use Magento\Mtf\TestStep\TestStepFactory;
12+
use Magento\Mtf\Fixture\FixtureFactory;
13+
14+
/**
15+
* Preconditions:
16+
* 1. Change configuration of Main Website.
17+
* 1. Create custom website.
18+
* 2. Create simple product.
19+
* 3. Assign created product to the main and custom websites.
20+
*
21+
* Steps:
22+
* 1. Change currency settings for custom website.
23+
* 2. Perform all asserts.
24+
*
25+
* @group Currency
26+
* @ZephyrId MAGETWO-12941
27+
*/
28+
class EditCurrencyCustomWebsiteTest extends Injectable
29+
{
30+
/**
31+
* Fixture factory.
32+
*
33+
* @var FixtureFactory
34+
*/
35+
private $fixtureFactory;
36+
37+
/**
38+
* Factory for Test Steps.
39+
*
40+
* @var TestStepFactory
41+
*/
42+
private $stepFactory;
43+
44+
/**
45+
* Injection data.
46+
*
47+
* @param FixtureFactory $fixtureFactory
48+
* @param TestStepFactory $stepFactory
49+
* @return array
50+
*/
51+
public function __inject(
52+
FixtureFactory $fixtureFactory,
53+
TestStepFactory $stepFactory
54+
) {
55+
$this->fixtureFactory = $fixtureFactory;
56+
$this->stepFactory = $stepFactory;
57+
}
58+
59+
/**
60+
* Change Currency on Custom Website test.
61+
*
62+
* @param string $configData
63+
* @param array $product
64+
* @param Store $store
65+
* @param array|null $currencies
66+
* @return array
67+
*/
68+
public function test($configData, array $product, Store $store, array $currencies = [])
69+
{
70+
// Preconditions
71+
$this->stepFactory->create(
72+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
73+
['configData' => $configData]
74+
)->run();
75+
76+
$store->persist();
77+
$product = $this->fixtureFactory->createByCode(
78+
$product[0],
79+
['dataset' => $product[1], 'data' => ['website_ids' => [['store' => $store]]]]
80+
);
81+
$product->persist();
82+
$websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites();
83+
84+
// Steps
85+
$configFixture = $this->fixtureFactory->createByCode(
86+
'configData',
87+
[
88+
'data' => [
89+
'currency/options/allow' => [
90+
'value' => $currencies[0]['allowedCurrencies']
91+
],
92+
'currency/options/base' => [
93+
'value' => $currencies[0]['baseCurrency']
94+
],
95+
'currency/options/default' => [
96+
'value' => $currencies[0]['defaultCurrency']
97+
],
98+
'scope' => [
99+
'fixture' => $websites[0],
100+
'scope_type' => 'website',
101+
'website_id' => $websites[0]->getWebsiteId(),
102+
'set_level' => 'website',
103+
]
104+
]
105+
]
106+
);
107+
$configFixture->persist();
108+
109+
return [
110+
'product' => $product,
111+
];
112+
}
113+
114+
/**
115+
* Reverting of currency settings to the default value.
116+
*
117+
* @return void
118+
*/
119+
public function tearDown()
120+
{
121+
$this->stepFactory->create(
122+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
123+
['configData' => 'config_currency_symbols_usd, price_scope_website_rollback']
124+
)->run();
125+
}
126+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\CurrencySymbol\Test\TestCase\EditCurrencyCustomWebsiteTest" summary="Using different currencies on main and custom websites" ticketId="MAGETWO-12941">
10+
<variation name="EditCurrencyCustomWebsiteTestVariation1" summary="Using default USD currency on default website and EUR currency on custom website" ticketId="MAGETWO-12941">
11+
<data name="configData" xsi:type="string">price_scope_website</data>
12+
<data name="product" xsi:type="array">
13+
<item name="0" xsi:type="string">catalogProductSimple</item>
14+
<item name="1" xsi:type="string">default</item>
15+
</data>
16+
<data name="store/dataset" xsi:type="string">custom_store</data>
17+
<data name="currencies" xsi:type="array">
18+
<item name="0" xsi:type="array">
19+
<item name="allowedCurrencies" xsi:type="array">
20+
<item name="0" xsi:type="string">EUR</item>
21+
</item>
22+
<item name="defaultCurrency" xsi:type="string">EUR</item>
23+
<item name="baseCurrency" xsi:type="string">EUR</item>
24+
</item>
25+
</data>
26+
<data name="currencySymbol" xsi:type="array">
27+
<item name="mainWebsite" xsi:type="string">$</item>
28+
<item name="customWebsite" xsi:type="string">€</item>
29+
</data>
30+
<constraint name="Magento\CurrencySymbol\Test\Constraint\AssertCurrencySymbolOnProductPageMainWebsite" />
31+
<constraint name="Magento\CurrencySymbol\Test\Constraint\AssertCurrencySymbolOnProductPageCustomWebsite" />
32+
</variation>
33+
</testCase>
34+
</config>

0 commit comments

Comments
 (0)