sarga/tests/functional/Customer/CustomerCest.php

134 lines
4.0 KiB
PHP
Raw Normal View History

2020-01-10 10:23:31 +00:00
<?php
2020-05-09 10:38:20 +00:00
namespace Tests\Functional\Customer;
2020-06-11 12:23:34 +00:00
use Faker\Factory;
2020-05-09 10:38:20 +00:00
use FunctionalTester;
2021-04-13 13:35:41 +00:00
use Webkul\Customer\Models\Customer;
2021-04-13 11:58:51 +00:00
use Webkul\Customer\Models\CustomerAddress;
2020-01-10 10:23:31 +00:00
class CustomerCest
{
2020-01-14 09:49:22 +00:00
public $fields = [];
2020-01-10 10:23:31 +00:00
2020-06-11 12:23:34 +00:00
public function _before(FunctionalTester $I): void
{
$I->useDefaultTheme();
}
2020-05-08 11:41:13 +00:00
public function updateCustomerProfile(FunctionalTester $I): void
2020-01-10 10:23:31 +00:00
{
2020-01-14 09:49:22 +00:00
$customer = $I->loginAsCustomer();
2020-01-10 10:23:31 +00:00
$I->amOnPage('/');
2021-04-13 11:58:51 +00:00
$I->click('Profile');
$I->click('Edit');
$I->selectOption('gender', 'Other');
$I->click('Update Profile');
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
$I->dontSeeInSource('The old password does not match.');
$I->seeInSource('Profile updated successfully.');
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
$I->seeRecord(Customer::class, [
'id' => $customer->id,
'gender' => 'Other',
]);
2020-01-10 10:23:31 +00:00
}
2020-05-08 11:41:13 +00:00
public function updateCustomerAddress(FunctionalTester $I): void
2020-01-10 10:23:31 +00:00
{
2021-04-13 11:58:51 +00:00
// instantiate a european faker factory to have the vat provider available
2020-06-11 12:23:34 +00:00
$faker = Factory::create('at_AT');
2020-01-10 10:23:31 +00:00
$formCssSelector = '#customer-address-form';
2020-01-10 10:23:31 +00:00
$I->loginAsCustomer();
2020-01-10 10:23:31 +00:00
$I->amOnPage('/');
2021-04-13 11:58:51 +00:00
$I->click('Profile');
$I->click('Address');
$I->click('Add Address');
2020-01-10 10:23:31 +00:00
2020-01-14 09:49:22 +00:00
$this->fields = [
2020-01-10 10:23:31 +00:00
'company_name' => $faker->company,
2020-01-31 05:06:13 +00:00
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
2020-01-14 12:17:52 +00:00
'vat_id' => 'INVALIDVAT',
2020-01-10 10:23:31 +00:00
'address1[]' => $faker->streetAddress,
'country' => $faker->countryCode,
'state' => $faker->state,
'city' => $faker->city,
'postcode' => $faker->postcode,
'phone' => $faker->phoneNumber,
];
2020-01-14 09:49:22 +00:00
foreach ($this->fields as $key => $value) {
2021-04-13 11:58:51 +00:00
// the following fields are rendered via javascript so we ignore them
if (!in_array($key, [
2020-01-10 10:23:31 +00:00
'country',
'state',
])) {
$selector = 'input[name="' . $key . '"]';
2021-04-13 11:58:51 +00:00
$I->fillField($selector, $value);
2020-01-10 10:23:31 +00:00
}
}
$I->wantTo('Ensure that the company_name field is being displayed');
2021-04-13 11:58:51 +00:00
$I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)');
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
/*
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');
2020-01-10 13:07:58 +00:00
2020-01-14 12:17:52 +00:00
$I->wantTo('enter a valid vat id');
$this->fields['vat_id'] = $faker->vat(false);
2020-01-10 13:07:58 +00:00
2021-04-13 11:58:51 +00:00
$I->submitForm($formCssSelector, $this->fields);
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
$I->seeInSource('Address have been successfully added.');
2020-01-10 10:23:31 +00:00
2020-01-14 09:49:22 +00:00
$this->assertCustomerAddress($I);
2020-01-10 10:23:31 +00:00
$I->wantTo('Update the created customer address again');
2021-04-13 11:58:51 +00:00
$I->click('Edit');
2020-01-10 10:23:31 +00:00
2020-01-14 09:49:22 +00:00
$oldcompany = $this->fields['company_name'];
$this->fields['company_name'] = $faker->company;
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
$I->submitForm($formCssSelector, $this->fields);
2020-01-10 10:23:31 +00:00
2021-04-13 11:58:51 +00:00
$I->seeInSource('Address updated successfully.');
2020-01-10 10:23:31 +00:00
$I->dontSeeRecord(CustomerAddress::class, [
'company_name' => $oldcompany,
]);
2021-04-13 11:58:51 +00:00
$this->assertCustomerAddress($I);
2020-01-14 09:49:22 +00:00
}
/**
2020-05-08 11:41:13 +00:00
* @param FunctionalTester $I
2020-01-14 09:49:22 +00:00
*/
private function assertCustomerAddress(FunctionalTester $I): void
{
2021-04-13 11:58:51 +00:00
$I->seeRecord(CustomerAddress::class, [
'company_name' => $this->fields['company_name'],
'first_name' => $this->fields['first_name'],
'last_name' => $this->fields['last_name'],
'vat_id' => $this->fields['vat_id'],
'address1' => $this->fields['address1[]'],
'country' => $this->fields['country'],
'state' => $this->fields['state'],
'city' => $this->fields['city'],
'phone' => $this->fields['phone'],
'postcode' => $this->fields['postcode'],
]);
2020-01-10 10:23:31 +00:00
}
2021-04-13 11:58:51 +00:00
}