sarga/tests/functional/Customer/CustomerCest.php

131 lines
4.1 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-01-10 10:23:31 +00:00
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
2020-05-09 10:38:20 +00:00
use FunctionalTester;
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('/');
2020-10-19 10:13:58 +00:00
// $I->click('Profile');
// $I->click('Edit');
2020-10-19 10:25:41 +00:00
// $I->selectOption('gender', 'Other');
2020-10-19 10:01:10 +00:00
// $I->click('Update Profile');
2020-01-10 10:23:31 +00:00
2020-10-19 10:50:06 +00:00
// $I->dontSeeInSource('The old password does not match.');
// $I->seeInSource('Profile updated successfully.');
2020-01-10 10:23:31 +00:00
2020-10-19 11:00:33 +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
{
2020-06-11 12:23:34 +00:00
// Instantiate a european faker factory to have the vat provider available
$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('/');
2020-10-19 10:01:10 +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) {
2020-05-08 11:41:13 +00:00
// the following fields are rendered via javascript so we ignore them:
2020-01-10 10:23:31 +00:00
if (! in_array($key, [
'country',
'state',
])) {
$selector = 'input[name="' . $key . '"]';
2020-10-19 10:13:58 +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');
2020-10-19 10:25:41 +00:00
// $I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)');
2020-01-10 10:23:31 +00:00
// we need to use this css selector to hit the correct <form>. There is another one at the
// page header (search)
2020-10-19 10:50:06 +00:00
// $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
2020-10-19 10:50:06 +00:00
// $I->submitForm($formCssSelector, $this->fields);
2020-01-10 10:23:31 +00:00
2020-10-19 10:50:06 +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');
2020-10-19 12:38: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
2020-10-19 10:50:06 +00:00
// $I->submitForm($formCssSelector, $this->fields);
2020-01-10 10:23:31 +00:00
2020-10-19 10:50:06 +00:00
// $I->seeInSource('Address updated successfully.');
2020-01-10 10:23:31 +00:00
$I->dontSeeRecord(CustomerAddress::class, [
'company_name' => $oldcompany,
]);
2020-10-19 12:19:41 +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
{
2020-10-19 12:30:05 +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
}
}