Updated Customer Cest

This commit is contained in:
Devansh 2021-11-29 17:18:34 +05:30
parent 67ec7bc543
commit 180d6e2fb9
1 changed files with 90 additions and 24 deletions

View File

@ -9,13 +9,50 @@ use Webkul\Customer\Models\CustomerAddress;
class CustomerCest
{
/**
* Faker factory.
*
* @var Faker\Factory
*/
public $faker;
/**
* Address Fields.
*
* @var array
*/
public $fields = [];
/**
* Constructor.
*
* @return void
*/
public function __construct()
{
/**
* Instantiate a european faker factory to have the vat provider available.
*/
$this->faker = Factory::create('at_AT');
}
/**
* Before method.
*
* @param FunctionalTester $I
* @return void
*/
public function _before(FunctionalTester $I): void
{
$I->useDefaultTheme();
}
/**
* Test update customer profile.
*
* @param FunctionalTester $I
* @return void
*/
public function updateCustomerProfile(FunctionalTester $I): void
{
$customer = $I->loginAsCustomer();
@ -36,11 +73,14 @@ class CustomerCest
]);
}
/**
* Update customer address.
*
* @param FunctionalTester $I
* @return void
*/
public function updateCustomerAddress(FunctionalTester $I): void
{
// instantiate a european faker factory to have the vat provider available
$faker = Factory::create('at_AT');
$formCssSelector = '#customer-address-form';
$I->loginAsCustomer();
@ -51,22 +91,13 @@ class CustomerCest
$I->click('Address');
$I->click('Add Address');
$this->fields = [
'company_name' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->company),
'first_name' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->firstName),
'last_name' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->lastName),
'vat_id' => 'INVALIDVAT',
'address1[]' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->streetAddress),
'country' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->countryCode),
'state' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->state),
'city' => preg_replace('/[^A-Za-z0-9 ]/', '', $faker->city),
'postcode' => preg_replace('/[^0-9]/', '', $faker->postcode),
'phone' => $faker->phoneNumber,
];
$this->setFields();
foreach ($this->fields as $key => $value) {
// the following fields are rendered via javascript so we ignore them
if (!in_array($key, [
/**
* The following fields are rendered via javascript so we ignore them.
*/
if (! in_array($key, [
'country',
'state',
])) {
@ -78,15 +109,15 @@ class CustomerCest
$I->wantTo('Ensure that the company_name field is being displayed');
$I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)');
/*
We need to use this css selector to hit the correct <form>. There is another one at the
page header (search).
*/
/**
* We need to use this css selector to hit the correct <form>. There is another one at the
* page header (search).
*/
$I->submitForm($formCssSelector, $this->fields);
$I->seeInSource('The given vat id has a wrong format');
$I->wantTo('enter a valid vat id');
$this->fields['vat_id'] = $faker->vat(false);
$this->fields['vat_id'] = $this->faker->vat(false);
$I->submitForm($formCssSelector, $this->fields);
@ -99,7 +130,7 @@ class CustomerCest
$I->click('Edit');
$oldcompany = $this->fields['company_name'];
$this->fields['company_name'] = preg_replace('/[^A-Za-z0-9 ]/', '', $faker->company);
$this->fields['company_name'] = preg_replace('/[^A-Za-z0-9 ]/', '', $this->faker->company);
$I->submitForm($formCssSelector, $this->fields);
@ -113,7 +144,10 @@ class CustomerCest
}
/**
* @param FunctionalTester $I
* Assert customer address.
*
* @param FunctionalTester $I
* @return void
*/
private function assertCustomerAddress(FunctionalTester $I): void
{
@ -130,4 +164,36 @@ class CustomerCest
'postcode' => $this->fields['postcode'],
]);
}
/**
* Set fields.
*
* @return void
*/
private function setFields()
{
$this->fields = [
'company_name' => $this->cleanField($this->faker->company),
'first_name' => $this->cleanField($this->faker->firstName),
'last_name' => $this->cleanField($this->faker->lastName),
'vat_id' => 'INVALIDVAT',
'address1[]' => $this->cleanField($this->faker->streetAddress),
'country' => $this->cleanField($this->faker->countryCode),
'state' => $this->cleanField($this->faker->state),
'city' => $this->cleanField($this->faker->city),
'postcode' => $this->cleanField($this->faker->postcode),
'phone' => $this->faker->phoneNumber,
];
}
/**
* Clean fields.
*
* @param string $field
* @return string
*/
private function cleanField($field)
{
return preg_replace('/[^A-Za-z0-9 ]/', '', $field);
}
}