Skip to content

Commit

Permalink
MAGETWO-56941: CLONE - CLONE - [Github] Allowed countries for custome…
Browse files Browse the repository at this point in the history
…r address in admin using storeview configuration #2946
  • Loading branch information
Sergey Kovalenko committed Aug 23, 2016
1 parent 3fa291e commit 674dc4d
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Addresses extends Tab
*/
protected $addressSelector = "//li[address[contains(.,'%s')]]";

protected $countriesSelector = "//*/select[@name='address[new_%d][country_id]']/option";

/**
* Delete Address button.
*
Expand Down Expand Up @@ -240,6 +242,34 @@ protected function isVisibleCustomerAddress($addressNumber)
return $addressTab->isVisible();
}

/**
* Retrieve list of all countries
* @param int $addressNumber
* @return array
*/
public function getCountriesList($addressNumber)
{
$this->openCustomerAddress($addressNumber);
/** @var SimpleElement $element */
$options = $this->_rootElement->getElements(
sprintf($this->countriesSelector, $addressNumber - 1),
Locator::SELECTOR_XPATH
);
$data = [];
/** @var SimpleElement $option */
foreach ($options as $option) {
if ($option->isVisible()) {
$value = $option->getValue();

if ($value != "") {
$data[] = $value;
}
}
}

return $data;
}

/**
* Click delete customer address button.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Test\Constraint;

use Magento\Customer\Test\Fixture\Customer;
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexNew;
use Magento\Mtf\Constraint\AbstractConstraint;

/**
* Assert required fields on customer form.
*/
class AssertChangingWebsiteChangeCountries extends AbstractConstraint
{
/**
* Assert required fields on customer form.
*
* @param CustomerIndexNew $customerNewPage
* @param array $expectedRequiredFields
* @return void
*/
public function processAssert(CustomerIndexNew $customerIndexNew, Customer $customer, \Magento\Customer\Test\Fixture\Address $address, $expectedList)
{
$customerIndexNew->getCustomerForm()
->openTab('account_information');
$customerIndexNew->getCustomerForm()->fillCustomer($customer);
$customerIndexNew->getCustomerForm()
->openTab('addresses');
$tab = $customerIndexNew->getCustomerForm()
->getTab('addresses');
$countriesList = $tab->getCountriesList(1);
sort($countriesList);
sort($expectedList);
\PHPUnit_Framework_Assert::assertEquals(
$countriesList,
$expectedList,
'Wrong country list is displayed.'
);
}

/**
* Return string representation of object.
*
* @return string
*/
public function toString()
{
return 'All required fields on customer form are highlighted.';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

namespace Magento\Customer\Test\TestCase;

use Magento\Config\Test\Fixture\ConfigData;
use Magento\Customer\Test\Constraint\AssertChangingWebsiteChangeCountries;
use Magento\Framework\App\ObjectManager;
use Magento\Mtf\Fixture\FixtureFactory;
use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Mtf\TestCase\Injectable;
use Magento\Customer\Test\Fixture\Address;
use Magento\Customer\Test\Fixture\Customer;
Expand Down Expand Up @@ -38,6 +43,15 @@ class CreateCustomerBackendEntityTest extends Injectable
*/
protected $customer;

/**
* @var Address
*/
private $address;


/** @var array */
private $allowedCountriesData = [];

/**
* Customer index page.
*
Expand All @@ -52,6 +66,9 @@ class CreateCustomerBackendEntityTest extends Injectable
*/
protected $pageCustomerIndexNew;

/** @var FixtureFactory */
private $fixtureFactory;

/**
* Inject customer pages.
*
Expand All @@ -61,10 +78,12 @@ class CreateCustomerBackendEntityTest extends Injectable
*/
public function __inject(
CustomerIndex $pageCustomerIndex,
CustomerIndexNew $pageCustomerIndexNew
CustomerIndexNew $pageCustomerIndexNew,
\Magento\Mtf\Fixture\FixtureFactory $fixtureFactory
) {
$this->pageCustomerIndex = $pageCustomerIndex;
$this->pageCustomerIndexNew = $pageCustomerIndexNew;
$this->fixtureFactory = $fixtureFactory;
}

/**
Expand All @@ -75,12 +94,143 @@ public function __inject(
* @param Address $address
* @return void
*/
public function test(Customer $customer, $customerAction, Address $address = null)
{
// Steps
public function test(
Customer $customer,
$customerAction,
Address $address = null,
array $steps = [],
array $beforeActionCallback = []
) {
///Process initialize steps
foreach ($steps as $methodName => $stepData) {
if (method_exists($this, $methodName)) {
call_user_func_array([$this, $methodName], $stepData);
}
}

$this->pageCustomerIndex->open();
$this->pageCustomerIndex->getPageActionsBlock()->addNew();
$this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($customer, $address);
$this->address = $address;
$this->customer = $customer;

foreach ($beforeActionCallback as $methodName) {
if (method_exists($this, $methodName)) {
call_user_func([$this, $methodName]);
}
}

$this->pageCustomerIndexNew->getPageActionsBlock()->$customerAction();
}

/**
* Assert that allowed countries renders in correct way.
* @return void
*/
private function assertAllowedCountries()
{
/** @var \Magento\Customer\Test\Constraint\AssertChangingWebsiteChangeCountries $assert */
$assert = $this->objectManager->get(
\Magento\Customer\Test\Constraint\AssertChangingWebsiteChangeCountries::class
);

foreach ($this->allowedCountriesData as $dataPerWebsite) {
$customerWithWebsite = $this->fixtureFactory->createByCode(
'customer',
[
'data' => [
'website_id' => $dataPerWebsite['website']->getName()
]
]
);
$assert->processAssert(
$this->pageCustomerIndexNew,
$customerWithWebsite,
$this->address,
$dataPerWebsite['countries']
);
}

$this->pageCustomerIndexNew->getCustomerForm()->openTab('account_information');
$this->pageCustomerIndexNew->getCustomerForm()->fillCustomer($this->customer);
$this->pageCustomerIndexNew->getCustomerForm()->openTab('addresses');
$this->pageCustomerIndexNew->getCustomerForm()->getTab('addresses')->updateAddresses($this->address);
}

/**
* @return \Magento\Store\Test\Fixture\Website
*/
private function createWebsiteFixture()
{
/** @var \Magento\Store\Test\Fixture\Website $websiteFixture */
$websiteFixture = $this->fixtureFactory->createByCode('website', ['dataset' => 'custom_website']);
$websiteFixture->persist();
$storeGroupFixture = $this->fixtureFactory->createByCode(
'storeGroup',
[
'data' => [
'website_id' => [
'fixture' => $websiteFixture
],
'root_category_id' => [
'dataset' => 'default_category'
],
'name' => 'Store_Group_%isolation%',
]
]
);
$storeGroupFixture->persist();
/** @var \Magento\Store\Test\Fixture\Store $storeFixture */
$storeFixture = $this->fixtureFactory->createByCode(
'store',
[
'data' => [
'website_id' => $websiteFixture->getWebsiteId(),
'group_id' => [
'fixture' => $storeGroupFixture
],
'is_active' => true,
'name' => 'Store_%isolation%',
'code' => 'store_%isolation%'
]
]
);
$storeFixture->persist();

return $websiteFixture;
}


/**
* @param array $countryList
*/
private function configureAllowedCountries(array $countryList = [])
{
foreach ($countryList as $countries) {
$websiteFixture = $this->createWebsiteFixture();
/** @var FixtureInterface $configFixture */
$configFixture = $this->fixtureFactory->createByCode(
'configData',
[
'data' => [
'general/country/allow' => [
'value' => $countries
],
'scope' => [
'fixture' => $websiteFixture,
'scope_type' => 'website',
'website_id' => $websiteFixture->getWebsiteId(),
'set_level' => 'website',
]
]
]
);

$configFixture->persist();
$this->allowedCountriesData[] = [
'website' => $websiteFixture,
'countries' => explode(",", $countries)
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,31 @@
</data>
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerBackendRequiredFields" />
</variation>
<variation name="CreateCustomerBackendEntityTestVariation10" summary="Create customer with 2 websites and with different allowed countries.">
<data name="customerAction" xsi:type="string">save</data>
<data name="customer/data/website_id" xsi:type="string">Main Website</data>
<data name="customer/data/group_id/dataset" xsi:type="string">General</data>
<data name="customer/data/firstname" xsi:type="string">John%isolation%</data>
<data name="customer/data/lastname" xsi:type="string">Doe%isolation%</data>
<data name="customer/data/email" xsi:type="string">JohnDoe%isolation%@example.com</data>
<data name="address/data/company" xsi:type="string">Magento</data>
<data name="address/data/country_id" xsi:type="string">Bangladesh</data>
<data name="address/data/street" xsi:type="string">Chmielna 113</data>
<data name="address/data/city" xsi:type="string">Bielsko-Biala</data>
<data name="address/data/postcode" xsi:type="string">43-310</data>
<data name="address/data/telephone" xsi:type="string">799885616</data>
<data name="steps" xsi:type="array">
<item name="configureAllowedCountries" xsi:type="array">
<item name="countries" xsi:type="array">
<item name="0" xsi:type="string">AS,BM</item>
<item name="1" xsi:type="string">BD,BB,AF</item>
</item>
</item>
</data>
<data name="beforeActionCallback" xsi:type="array">
<item name="assertAllowedCountries" xsi:type="string">assertAllowedCountries</item>
</data>
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerSuccessSaveMessage" />
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function __construct(FixtureFactory $fixtureFactory, array $params, array
}
$this->storeGroup = $storeGroup;
$this->data = $storeGroup->getWebsiteId() . "/" . $storeGroup->getName();
} elseif (isset($data['fixture'])) {
$this->storeGroup = $data['fixture'];
$this->data = $this->storeGroup->getWebsiteId() . "/" . $this->storeGroup->getName();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function __construct(FixtureFactory $fixtureFactory, array $params, array
}
$this->website = $website;
$this->data = $website->getName();
} elseif (isset($data['fixture'])) {
$this->website = $data['fixture'];
$this->data = $this->website->getName();
}
}

Expand Down

0 comments on commit 674dc4d

Please sign in to comment.