extend failing test; add test artifacts in pipeline

This commit is contained in:
Florian Bosdorff 2020-01-22 08:31:20 +01:00
parent 478533ae60
commit 8ee3118597
2 changed files with 67 additions and 42 deletions

View File

@ -54,3 +54,9 @@ jobs:
- name: Execute trigger tests
run: set -e && vendor/bin/codecept run trigger
- name: Persist test artifacts
uses: actions/upload-artifact@v1
with:
name: test_artifacts
path: tests/_output

View File

@ -1,6 +1,8 @@
<?php
namespace Tests\Webkul\Unit\Shop;
use Codeception\Example;
use FunctionalTester;
use Faker\Factory;
use Cart;
@ -10,23 +12,24 @@ class GuestCheckoutCest
private $faker,
$productNoGuestCheckout, $productGuestCheckout;
function _before(FunctionalTester $I) {
function _before(FunctionalTester $I)
{
$this->faker = Factory::create();
$pConfigDefault = [
'productInventory' => ['qty' => $this->faker->randomNumber(2)],
'attributeValues' => [
'status' => true,
'new' => 1,
'productInventory' => ['qty' => $this->faker->randomNumber(2)],
'attributeValues' => [
'status' => true,
'new' => 1,
'guest_checkout' => 0
],
];
$pConfigGuestCheckout = [
'productInventory' => ['qty' => $this->faker->randomNumber(2)],
'attributeValues' => [
'status' => true,
'new' => 1,
'productInventory' => ['qty' => $this->faker->randomNumber(2)],
'attributeValues' => [
'status' => true,
'new' => 1,
'guest_checkout' => 1
],
];
@ -38,53 +41,69 @@ class GuestCheckoutCest
$this->productGuestCheckout->refresh();
}
public function testGuestCheckout(FunctionalTester $I) {
/**
* @param FunctionalTester $I
* @param Example $example
*
* @dataProvider guestCheckoutProvider
*/
public function testGuestCheckout(FunctionalTester $I, Example $example): void
{
$product = ($example['guest_product']) ? $this->productGuestCheckout : $this->productNoGuestCheckout;
$I->amGoingTo('try to add products to cart with guest checkout turned on or off');
$scenarios = [
$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->see($product->name, '//div[@class="product-information"]/div[@class="product-name"]');
$I->click(__('shop::app.products.add-to-cart'),
'//form[input[@name="product_id"][@value="' . $product->id . '"]]/button');
$I->seeInSource(__('shop::app.checkout.cart.item.success'));
$I->amOnRoute('shop.checkout.cart.index');
$I->see('Shopping Cart', '//div[@class="title"]');
$I->makeHtmlSnapshot('guestCheckout_' . $example['globalConfig'] . '_' . $product->getAttribute('guest_checkout'));
$I->see($product->name, '//div[@class="item-title"]');
$I->click(__('shop::app.checkout.cart.proceed-to-checkout'),
'//a[@href="' . route('shop.checkout.onepage.index') . '"]');
$I->seeCurrentRouteIs($example['expectedRoute']);
$cart = Cart::getCart();
$I->assertTrue(Cart::removeItem($cart->items[0]->id));
}
protected function guestCheckoutProvider(): array
{
return [
[
'name' => 'false / false',
'globalConfig' => 0,
'product' => $this->productNoGuestCheckout,
'name' => 'false / false',
'globalConfig' => 0,
'guest_product' => false,
'product' => $this->productNoGuestCheckout,
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'false / true',
'globalConfig' => 0,
'product' => $this->productGuestCheckout,
'name' => 'false / true',
'globalConfig' => 0,
'guest_product' => true,
'product' => $this->productGuestCheckout,
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'true / false',
'globalConfig' => 1,
'product' => $this->productNoGuestCheckout,
'name' => 'true / false',
'globalConfig' => 1,
'guest_product' => false,
'product' => $this->productNoGuestCheckout,
'expectedRoute' => 'customer.session.index'
],
[
'name' => 'true / true',
'globalConfig' => 1,
'product' => $this->productGuestCheckout,
'name' => 'true / true',
'globalConfig' => 1,
'guest_product' => true,
'product' => $this->productGuestCheckout,
'expectedRoute' => 'shop.checkout.onepage.index'
],
];
foreach ($scenarios as $scenario) {
$I->wantTo('test conjunction "' . $scenario['name'] . '" with globalConfig = ' . $scenario['globalConfig'] . ' && product config = ' . $scenario['product']->getAttribute('guest_checkout'));
$I->setConfigData(['catalog.products.guest-checkout.allow-guest-checkout' => $scenario['globalConfig']]);
$I->assertEquals($scenario['globalConfig'], core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout'));
$I->amOnRoute('shop.home.index');
$I->see($scenario['product']->name, '//div[@class="product-information"]/div[@class="product-name"]');
$I->click(__('shop::app.products.add-to-cart'),
'//form[input[@name="product_id"][@value="' . $scenario['product']->id . '"]]/button');
$I->seeInSource(__('shop::app.checkout.cart.item.success'));
$I->amOnRoute('shop.checkout.cart.index');
$I->see('Shopping Cart', '//div[@class="title"]');
$I->makeHtmlSnapshot('guestCheckout_'.$scenario['globalConfig'].'_'.$scenario['product']->getAttribute('guest_checkout'));
$I->see($scenario['product']->name, '//div[@class="item-title"]');
$I->click( __('shop::app.checkout.cart.proceed-to-checkout'), '//a[@href="' . route('shop.checkout.onepage.index') . '"]');
$I->seeCurrentRouteIs($scenario['expectedRoute']);
$cart = Cart::getCart();
$I->assertTrue(Cart::removeItem($cart->items[0]->id));
}
}
}