diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 07d695d42..fc353e670 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -837,7 +837,7 @@ class Cart */ public function hasError() { - if (!$this->getCart()) { + if (! $this->getCart()) { return true; } diff --git a/packages/Webkul/Core/src/Helpers/Laravel5Helper.php b/packages/Webkul/Core/src/Helpers/Laravel5Helper.php index f2309bc56..051cdeab2 100644 --- a/packages/Webkul/Core/src/Helpers/Laravel5Helper.php +++ b/packages/Webkul/Core/src/Helpers/Laravel5Helper.php @@ -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), ])); + } /** diff --git a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php index 541787a87..261a913ba 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php @@ -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(); diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php index 4a1ab9406..18a68fb7a 100644 --- a/tests/_support/FunctionalTester.php +++ b/tests/_support/FunctionalTester.php @@ -115,13 +115,17 @@ 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, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + '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'), ]); } } diff --git a/tests/functional/Checkout/Order/OrderCest.php b/tests/functional/Checkout/Order/OrderCest.php index 146523ed2..ed92c952d 100644 --- a/tests/functional/Checkout/Order/OrderCest.php +++ b/tests/functional/Checkout/Order/OrderCest.php @@ -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(); - $I->prepareCart(); + $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', + ]); } - } \ No newline at end of file