finish testCheckoutAsCustomer

This commit is contained in:
Herbert Maschke 2020-03-02 09:08:51 +01:00
parent 781d360ce7
commit 895978e600
5 changed files with 118 additions and 24 deletions

View File

@ -101,7 +101,8 @@ class Laravel5Helper extends Laravel5
'company_name' => $faker->company,
]);
if (isset($options['payment_method']) && $options['payment_method'] === 'free_of_charge') {
if (isset($options['payment_method'])
&& $options['payment_method'] === 'free_of_charge') {
$grand_total = '0.0000';
$base_grand_total = '0.0000';
} else {
@ -122,11 +123,10 @@ class Laravel5Helper extends Laravel5
$cartAddress = $I->have(CartAddress::class, ['cart_id' => $cart->id]);
if (isset($options['product_type'])) {
$type = $options['product_type'];
} else {
$type = 'virtual';
$type = 'simple';
}
$generatedCartItems = rand(3, 10);
@ -166,7 +166,11 @@ class Laravel5Helper extends Laravel5
* @return \Webkul\Product\Models\Product
* @part ORM
*/
public function haveProduct(int $productType, array $configs = [], array $productStates = []): Product
public function haveProduct(
int $productType,
array $configs = [],
array $productStates = []
): Product
{
$I = $this;
@ -218,9 +222,13 @@ class Laravel5Helper extends Laravel5
*
* @return \Webkul\Product\Models\Product
*/
private function haveSimpleProduct(array $configs = [], array $productStates = []): Product
private function haveSimpleProduct(
array $configs = [],
array $productStates = []
): Product
{
$I = $this;
if (! in_array('simple', $productStates)) {
$productStates = array_merge($productStates, ['simple']);
}
@ -299,10 +307,13 @@ class Laravel5Helper extends Laravel5
private function createInventory(int $productId, array $inventoryConfig = []): void
{
$I = $this;
$I->have(ProductInventory::class, array_merge($inventoryConfig, [
'product_id' => $productId,
'inventory_source_id' => 1,
'qty' => random_int(100, 666),
]));
}
/**

View File

@ -57,12 +57,14 @@ class OnepageController extends Controller
*/
public function index()
{
if (! auth()->guard('customer')->check() && ! core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout')) {
if (! auth()->guard('customer')->check()
&& ! core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout')) {
return redirect()->route('customer.session.index');
}
if (Cart::hasError())
if (Cart::hasError()) {
return redirect()->route('shop.checkout.cart.index');
}
$cart = Cart::getCart();

View File

@ -115,11 +115,15 @@ class FunctionalTester extends \Codeception\Actor
{
foreach ($data as $key => $value) {
if (DB::table('core_config')->where('code', '=', $key)->exists()) {
DB::table('core_config')->where('code', '=', $key)->update(['value' => $value]);
DB::table('core_config')
->where('code', '=', $key)
->update(['value' => $value]);
} else {
DB::table('core_config')->insert([
'code' => $key,
'value' => $value,
'channel_code' => null,
'locale_code' => null,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);

View File

@ -4,27 +4,104 @@ namespace Tests\Functional\Checkout\Cart;
use FunctionalTester;
use Cart;
use Codeception\Example;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Checkout\Models\CartAddress;
class OrderCest
{
/**
* @param \FunctionalTester $I
*
* @example {"isGuest": true}
*
* @example {"isGuest": false}
*/
public function testCheckout(FunctionalTester $I, Example $example)
public function testCheckoutAsCustomer(FunctionalTester $I)
{
if (! $example['isGuest']) {
$I->loginAsCustomer();
$customer = $I->loginAsCustomer();
$mocks = $I->prepareCart([
'customer' => $customer,
]);
// assert that checkout can be reached and generate csrf token.
$I->amOnRoute('shop.checkout.onepage.index');
// simulate the entering of the address(es):
$I->sendAjaxPostRequest(route('shop.checkout.save-address'), [
'_token' => csrf_token(),
'billing' => [
'address1' => ['900 Nobel Parkway'],
'city' => 'Quia et cillum rerum',
'company_name' => 'Davis and Best Plc',
'country' => 'TN',
'email' => 'kularynefo@mailinator.com',
'first_name' => 'Maggie',
'last_name' => 'Paul',
'phone' => '+1 (995) 347-2667',
'postcode' => '16239',
'save_as_address' => true,
'state' => 'Aperiam a eligendi a',
'use_for_shipping' => true,
],
'shipping' => [
'address1' => ['900 Nobel Parkway'],
'city' => 'Quia et cillum rerum',
'company_name' => 'Davis and Best Plc',
'country' => 'TN',
'email' => 'kularynefo@mailinator.com',
'first_name' => 'Maggie',
'last_name' => 'Paul',
'phone' => '+1 (995) 347-2667',
'postcode' => '16239',
'save_as_address' => true,
'state' => 'Aperiam a eligendi a',
'use_for_shipping' => true,
],
]);
$I->seeResponseCodeIsSuccessful();
$I->seeRecord(CartAddress::class, [
'city' => 'Quia et cillum rerum',
'company_name' => 'Davis and Best Plc',
'country' => 'TN',
'email' => 'kularynefo@mailinator.com',
'first_name' => 'Maggie',
'last_name' => 'Paul',
'phone' => '+1 (995) 347-2667',
'postcode' => '16239',
]);
$I->sendAjaxPostRequest(route('shop.checkout.save-shipping'), [
'_token' => csrf_token(),
'shipping_method' => 'free_free',
]);
$I->seeResponseCodeIsSuccessful();
$I->sendAjaxPostRequest(route('shop.checkout.save-payment'), [
'_token' => csrf_token(),
'payment' => [
'method' => 'cashondelivery',
],
]);
$I->seeResponseCodeIsSuccessful();
// simulate click on the 'place order' button at the last step:
$I->sendAjaxPostRequest(route('shop.checkout.save-order'),
['_token' => csrf_token()]
);
$I->seeResponseCodeIsSuccessful();
$I->seeRecord(OrderAddress::class, [
'city' => 'Quia et cillum rerum',
'company_name' => 'Davis and Best Plc',
'country' => 'TN',
'email' => 'kularynefo@mailinator.com',
'first_name' => 'Maggie',
'last_name' => 'Paul',
'phone' => '+1 (995) 347-2667',
'postcode' => '16239',
]);
}
$I->prepareCart();
}
}