sarga/tests/functional/Shop/GuestCheckoutCest.php

111 lines
4.2 KiB
PHP
Raw Normal View History

2020-01-17 13:42:47 +00:00
<?php
namespace Tests\Functional\Shop;
2020-01-17 13:42:47 +00:00
use Faker\Factory;
2021-02-26 12:59:31 +00:00
use FunctionalTester;
use Codeception\Example;
use Webkul\Core\Helpers\Laravel5Helper;
2020-01-17 13:42:47 +00:00
class GuestCheckoutCest
{
2020-06-11 12:23:34 +00:00
private $productNoGuestCheckout, $productGuestCheckout;
2020-01-17 13:42:47 +00:00
function _before(FunctionalTester $I)
{
2020-06-11 12:23:34 +00:00
$I->useDefaultTheme();
2020-01-17 13:42:47 +00:00
2020-06-11 12:23:34 +00:00
$faker = Factory::create();
2020-01-17 13:42:47 +00:00
$pConfigDefault = [
2020-06-11 12:23:34 +00:00
'productInventory' => ['qty' => $faker->numberBetween(1, 1000)],
'attributeValues' => [
'status' => true,
'new' => 1,
2020-01-17 13:42:47 +00:00
'guest_checkout' => 0
],
];
$pConfigGuestCheckout = [
2020-06-11 12:23:34 +00:00
'productInventory' => ['qty' => $faker->numberBetween(1, 1000)],
'attributeValues' => [
'status' => true,
'new' => 1,
2020-01-17 13:42:47 +00:00
'guest_checkout' => 1
],
];
2020-02-04 17:13:09 +00:00
$this->productNoGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigDefault);
2020-01-17 13:42:47 +00:00
$this->productNoGuestCheckout->refresh();
2020-02-04 17:13:09 +00:00
$this->productGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigGuestCheckout);
2020-01-17 13:42:47 +00:00
$this->productGuestCheckout->refresh();
}
/**
* @param FunctionalTester $I
* @param Example $example
*
* @dataProvider guestCheckoutProvider
*/
public function testGuestCheckout(FunctionalTester $I, Example $example): void
{
2021-02-26 12:59:31 +00:00
// $product = ($example['guest_product']) ? $this->productGuestCheckout : $this->productNoGuestCheckout;
2021-02-26 12:59:31 +00:00
// $I->amGoingTo('try to add products to cart with guest checkout turned on or off');
2020-01-17 13:42:47 +00:00
2021-02-26 12:59:31 +00:00
// $I->wantTo('test conjunction "' . $example['name'] . '" with globalConfig = ' . $example['globalConfig'] . ' && product config = ' . $product->getAttribute('guest_checkout'));
// $I->setConfigData(['catalog.products.guest-checkout.allow-guest-checkout' => $example['globalConfig']]);
// $I->assertEquals($example['globalConfig'],
// core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout'));
// $I->amOnRoute('shop.home.index');
// $I->sendAjaxPostRequest('/checkout/cart/add/' . $product->id, [
// '_token' => session('_token'),
// 'product_id' => $product->id,
// 'quantity' => 1
// ]);
2021-02-26 12:59:31 +00:00
// $I->amOnRoute('shop.checkout.cart.index');
2020-10-19 10:01:10 +00:00
// $I->see('Shopping Cart', '//div[@class="title"]');
2021-02-26 12:59:31 +00:00
// $I->makeHtmlSnapshot('guestCheckout_' . $example['globalConfig'] . '_' . $product->getAttribute('guest_checkout'));
2020-10-19 10:01:10 +00:00
// $I->see($product->name, '//div[@class="item-title"]');
2020-10-19 10:25:41 +00:00
// $I->click(__('shop::app.checkout.cart.proceed-to-checkout'),
// '//a[@href="' . route('shop.checkout.onepage.index') . '"]');
2020-10-19 10:50:06 +00:00
// $I->seeCurrentRouteIs($example['expectedRoute']);
2021-02-26 12:59:31 +00:00
// $cart = cart()->getCart();
// $I->assertTrue(cart()->removeItem($cart->items[0]->id));
}
protected function guestCheckoutProvider(): array
{
return [
2020-01-17 13:42:47 +00:00
[
'name' => 'false / false',
'globalConfig' => 0,
'guest_product' => false,
'product' => $this->productNoGuestCheckout,
2020-01-17 13:42:47 +00:00
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'false / true',
'globalConfig' => 0,
'guest_product' => true,
'product' => $this->productGuestCheckout,
2020-01-17 13:42:47 +00:00
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'true / false',
'globalConfig' => 1,
'guest_product' => false,
'product' => $this->productNoGuestCheckout,
2020-01-17 13:42:47 +00:00
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'true / true',
'globalConfig' => 1,
'guest_product' => true,
'product' => $this->productGuestCheckout,
2020-01-17 13:42:47 +00:00
'expectedRoute' => 'shop.checkout.onepage.index'
],
];
}
}