Address File Reverted

This commit is contained in:
Devansh 2022-02-10 14:26:16 +05:30
parent 5e1c8203ee
commit 85e509f562
4 changed files with 143 additions and 49 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace Actions;
trait CleanAction
{
/**
* Clean all fields.
*
* @param array $fields
* @return array
*/
public function cleanAllFields(array $fields)
{
return collect($fields)->map(function ($field, $key) {
return $this->cleanField($field);
})->toArray();
}
/**
* Clean field.
*
* @param string $field
* @return string
*/
public function cleanField($field)
{
return preg_replace('/[^A-Za-z0-9 ]/', '', $field);
}
}

View File

@ -1,6 +1,7 @@
<?php <?php
use Actions\CartAction; use Actions\CartAction;
use Actions\CleanAction;
use Actions\ProductAction; use Actions\ProductAction;
use Actions\ProductActionContract; use Actions\ProductActionContract;
use Laravel\Sanctum\Sanctum; use Laravel\Sanctum\Sanctum;
@ -24,7 +25,7 @@ use Webkul\Customer\Models\Customer;
*/ */
class ApiTester extends \Codeception\Actor implements ProductActionContract class ApiTester extends \Codeception\Actor implements ProductActionContract
{ {
use _generated\ApiTesterActions, CartAction, ProductAction; use _generated\ApiTesterActions, CartAction, CleanAction, ProductAction;
/** /**
* Sanctum authenticated customer. * Sanctum authenticated customer.
@ -115,28 +116,4 @@ class ApiTester extends \Codeception\Actor implements ProductActionContract
return $idAndToken[1]; return $idAndToken[1];
} }
/**
* Clean all fields.
*
* @param array $fields
* @return array
*/
public function cleanAllFields(array $fields)
{
return collect($fields)->map(function ($field, $key) {
return $this->cleanField($field);
})->toArray();
}
/**
* Clean field.
*
* @param string $field
* @return string
*/
public function cleanField($field)
{
return preg_replace('/[^A-Za-z0-9 ]/', '', $field);
}
} }

View File

@ -0,0 +1,108 @@
<?php
namespace Tests\Functional\Admin\Customer;
use Actions\CleanAction;
use FunctionalTester;
use Webkul\Customer\Models\Customer;
class AddressCest
{
use CleanAction;
/**
* Test address index page.
*
* @param FunctionalTester $I
* @return void
*/
public function testIndex(FunctionalTester $I): void
{
$customer = $I->have(Customer::class);
$I->loginAsAdmin();
$I->amOnAdminRoute('admin.customer.edit', [$customer->id]);
$I->seeCurrentRouteIs('admin.customer.edit');
$I->sendAjaxGetRequest(route('admin.customer.addresses.index', $customer->id));
$I->seeResponseCodeIsSuccessful();
}
/**
* Test create address page.
*
* @param FunctionalTester $I
* @return void
*/
public function testCreate(FunctionalTester $I): void
{
$customer = $I->have(Customer::class);
$I->loginAsAdmin();
$I->amOnAdminRoute('admin.customer.edit', [$customer->id]);
$I->click(__('admin::app.customers.addresses.create-btn-title'), '//*[contains(@class, "page-content")]');
$I->seeCurrentRouteIs('admin.customer.addresses.create');
$I->click(__('admin::app.customers.addresses.save-btn-title'), '//*[contains(@class, "page-action")]');
$I->seeFormHasErrors();
// To Do (@devansh-webkul): Simulate this...
// $addressData = $this->generateAddressData($I);
// $this->fillForm($I, $addressData);
// $I->click(__('admin::app.customers.addresses.save-btn-title'), '//*[contains(@class, "page-action")]');
// $I->dontSeeFormErrors();
// $I->seeCurrentRouteIs('admin.customer.addresses.index');
// $I->seeRecord(Customer::class, $addressData);
}
/**
* Generate address data.
*
* @param FunctionalTester $I
* @return void
*/
private function generateAddressData(FunctionalTester $I)
{
return $this->cleanAllFields([
'first_name' => $I->fake()->firstName,
'last_name' => $I->fake()->lastName,
'address1' => $I->fake()->streetAddress,
'country' => $I->fake()->countryCode,
'state' => $I->fake()->word,
'city' => $I->fake()->city,
'postcode' => $I->fake()->postcode,
'phone' => $I->fake()->phoneNumber,
]);
}
/**
* Fill form data.
*
* @param FunctionalTester $I
* @param array $addressData
* @return void
*/
private function fillForm(FunctionalTester $I, array $addressData)
{
$I->fillField('first_name', $addressData['first_name']);
$I->fillField('last_name', $addressData['last_name']);
$I->fillField('address1[]', $addressData['address1']);
$I->fillField('city', $addressData['city']);
$I->selectOption('country', $addressData['country']);
$I->selectOption('state', $addressData['state']);
$I->fillField('postcode', $addressData['postcode']);
$I->fillField('phone', $addressData['phone']);
}
}

View File

@ -2,6 +2,7 @@
namespace Tests\Functional\Customer; namespace Tests\Functional\Customer;
use Actions\CleanAction;
use Faker\Factory; use Faker\Factory;
use FunctionalTester; use FunctionalTester;
use Webkul\Customer\Models\Customer; use Webkul\Customer\Models\Customer;
@ -9,6 +10,8 @@ use Webkul\Customer\Models\CustomerAddress;
class CustomerCest class CustomerCest
{ {
use CleanAction;
/** /**
* Faker factory. * Faker factory.
* *
@ -186,28 +189,4 @@ class CustomerCest
'phone' => $this->faker->phoneNumber, 'phone' => $this->faker->phoneNumber,
]); ]);
} }
/**
* Clean all fields.
*
* @param array $fields
* @return array
*/
private function cleanAllFields(array $fields)
{
return collect($fields)->map(function ($field, $key) {
return $this->cleanField($field);
})->toArray();
}
/**
* Clean fields.
*
* @param string $field
* @return string
*/
private function cleanField($field)
{
return preg_replace('/[^A-Za-z0-9 ]/', '', $field);
}
} }