From c71fa83b8419feeb48c3faab427e251389c03549 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Tue, 13 Apr 2021 17:28:51 +0530 Subject: [PATCH] Test Case Portion 1 --- .github/workflows/ci.yml | 27 ++++-- composer.json | 64 +++++++------- .../Admin/Catalog/AttributeFamilyCest.php | 1 - .../Admin/Customer/CustomerCest.php | 2 - .../functional/Admin/Customer/GroupsCest.php | 2 - .../Customer/NewsletterSubscriptionCest.php | 1 - .../functional/Admin/Customer/ReviewCest.php | 2 - tests/functional/Admin/Sales/RefundCest.php | 1 - .../functional/Admin/Sales/ShipmentsCest.php | 1 - .../functional/CartRule/CartRuleCopyCest.php | 1 - .../CartRule/CartRuleCreateCest.php | 10 +-- tests/functional/Checkout/Cart/CartCest.php | 7 +- tests/functional/Checkout/Order/OrderCest.php | 17 ++-- tests/functional/Customer/CustomerCest.php | 87 ++++++++++--------- 14 files changed, 110 insertions(+), 113 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87066af6f..616d69f07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,13 +27,13 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Setup php + - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} extensions: curl, gd, intl, mbstring, openssl, pdo, pdo_mysql, tokenizer, zip - - name: Set environment + - name: Set Environment run: | set -e sed -i "s|^\(DB_HOST=\s*\).*$|\1127.0.0.1|" .env.testing @@ -41,24 +41,33 @@ jobs: printf "the complete .env.testing ...\n\n" cat .env.testing - - name: Composer install + - name: Composer Install run: | set -e composer install --no-cache - - name: Migrate database + - name: Migrate Database run: set -e && php artisan migrate --env=testing - - name: Execute unit tests + - name: Seed Database + run: set -e && php artisan db:seed --env=testing + + - name: Vendor Publish + run: set -e && php artisan vendor:publish --all --force --env=testing + + - name: Optimize Stuffs + run: set -e && php artisan optimize --env=testing + + - name: Execute Unit Tests run: set -e && vendor/bin/codecept run unit - - name: Execute functional tests - run: set -e && vendor/bin/codecept run functional + - name: Execute Functional Tests + run: set -e && vendor/bin/codecept run tests/functional/Checkout/Cart/CartCest.php - - name: Execute trigger tests + - name: Execute Trigger Tests run: set -e && vendor/bin/codecept run trigger - - name: Persist test artifacts + - name: Persist Test Artifacts uses: actions/upload-artifact@v1 if: always() with: diff --git a/composer.json b/composer.json index dafaaa3ed..0d398b8e0 100755 --- a/composer.json +++ b/composer.json @@ -72,38 +72,38 @@ "bagisto/laravel-discount": "v0.1.0" }, "autoload": { - "psr-4": { - "App\\": "app/", - "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/", - "Webkul\\User\\": "packages/Webkul/User/src", - "Webkul\\Admin\\": "packages/Webkul/Admin/src", - "Webkul\\Ui\\": "packages/Webkul/Ui/src", - "Webkul\\Category\\": "packages/Webkul/Category/src", - "Webkul\\Checkout\\": "packages/Webkul/Checkout/src", - "Webkul\\Attribute\\": "packages/Webkul/Attribute/src", - "Webkul\\Shop\\": "packages/Webkul/Shop/src", - "Webkul\\Core\\": "packages/Webkul/Core/src", - "Webkul\\Customer\\": "packages/Webkul/Customer/src", - "Webkul\\Inventory\\": "packages/Webkul/Inventory/src", - "Webkul\\Product\\": "packages/Webkul/Product/src", - "Webkul\\Theme\\": "packages/Webkul/Theme/src", - "Webkul\\Shipping\\": "packages/Webkul/Shipping/src", - "Webkul\\Payment\\": "packages/Webkul/Payment/src", - "Webkul\\Paypal\\": "packages/Webkul/Paypal/src", - "Webkul\\Sales\\": "packages/Webkul/Sales/src", - "Webkul\\Tax\\": "packages/Webkul/Tax/src", - "Webkul\\API\\": "packages/Webkul/API", - "Webkul\\CatalogRule\\": "packages/Webkul/CatalogRule/src", - "Webkul\\CartRule\\": "packages/Webkul/CartRule/src", - "Webkul\\Rule\\": "packages/Webkul/Rule/src", - "Webkul\\CMS\\": "packages/Webkul/CMS/src", - "Webkul\\Velocity\\": "packages/Webkul/Velocity/src", - "Webkul\\BookingProduct\\": "packages/Webkul/BookingProduct/src", - "Webkul\\SocialLogin\\": "packages/Webkul/SocialLogin/src", - "Webkul\\DebugBar\\": "packages/Webkul/DebugBar/src", - "Webkul\\Marketing\\": "packages/Webkul/Marketing/src" - } + "psr-4": { + "App\\": "app/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/", + "Webkul\\User\\": "packages/Webkul/User/src", + "Webkul\\Admin\\": "packages/Webkul/Admin/src", + "Webkul\\Ui\\": "packages/Webkul/Ui/src", + "Webkul\\Category\\": "packages/Webkul/Category/src", + "Webkul\\Checkout\\": "packages/Webkul/Checkout/src", + "Webkul\\Attribute\\": "packages/Webkul/Attribute/src", + "Webkul\\Shop\\": "packages/Webkul/Shop/src", + "Webkul\\Core\\": "packages/Webkul/Core/src", + "Webkul\\Customer\\": "packages/Webkul/Customer/src", + "Webkul\\Inventory\\": "packages/Webkul/Inventory/src", + "Webkul\\Product\\": "packages/Webkul/Product/src", + "Webkul\\Theme\\": "packages/Webkul/Theme/src", + "Webkul\\Shipping\\": "packages/Webkul/Shipping/src", + "Webkul\\Payment\\": "packages/Webkul/Payment/src", + "Webkul\\Paypal\\": "packages/Webkul/Paypal/src", + "Webkul\\Sales\\": "packages/Webkul/Sales/src", + "Webkul\\Tax\\": "packages/Webkul/Tax/src", + "Webkul\\API\\": "packages/Webkul/API", + "Webkul\\CatalogRule\\": "packages/Webkul/CatalogRule/src", + "Webkul\\CartRule\\": "packages/Webkul/CartRule/src", + "Webkul\\Rule\\": "packages/Webkul/Rule/src", + "Webkul\\CMS\\": "packages/Webkul/CMS/src", + "Webkul\\Velocity\\": "packages/Webkul/Velocity/src", + "Webkul\\BookingProduct\\": "packages/Webkul/BookingProduct/src", + "Webkul\\SocialLogin\\": "packages/Webkul/SocialLogin/src", + "Webkul\\DebugBar\\": "packages/Webkul/DebugBar/src", + "Webkul\\Marketing\\": "packages/Webkul/Marketing/src" + } }, "autoload-dev": { "psr-4": { diff --git a/tests/functional/Admin/Catalog/AttributeFamilyCest.php b/tests/functional/Admin/Catalog/AttributeFamilyCest.php index 60a20db72..f99f5ec90 100644 --- a/tests/functional/Admin/Catalog/AttributeFamilyCest.php +++ b/tests/functional/Admin/Catalog/AttributeFamilyCest.php @@ -2,7 +2,6 @@ namespace Tests\Functional\Admin\Catalog; - use FunctionalTester; use Webkul\Attribute\Models\AttributeFamily; diff --git a/tests/functional/Admin/Customer/CustomerCest.php b/tests/functional/Admin/Customer/CustomerCest.php index 4a806624f..22946ff56 100644 --- a/tests/functional/Admin/Customer/CustomerCest.php +++ b/tests/functional/Admin/Customer/CustomerCest.php @@ -2,11 +2,9 @@ namespace Tests\Functional\Admin\Customer; - use FunctionalTester; use Webkul\Customer\Models\Customer; - class CustomerCest { public function testIndex(FunctionalTester $I): void diff --git a/tests/functional/Admin/Customer/GroupsCest.php b/tests/functional/Admin/Customer/GroupsCest.php index 22db609e2..57b2af12d 100644 --- a/tests/functional/Admin/Customer/GroupsCest.php +++ b/tests/functional/Admin/Customer/GroupsCest.php @@ -2,11 +2,9 @@ namespace Tests\Functional\Admin\Customer; - use FunctionalTester; use Webkul\Customer\Models\CustomerGroup; - class GroupsCest { public function testIndex(FunctionalTester $I): void diff --git a/tests/functional/Admin/Customer/NewsletterSubscriptionCest.php b/tests/functional/Admin/Customer/NewsletterSubscriptionCest.php index 50dbb4438..0605216f9 100644 --- a/tests/functional/Admin/Customer/NewsletterSubscriptionCest.php +++ b/tests/functional/Admin/Customer/NewsletterSubscriptionCest.php @@ -2,7 +2,6 @@ namespace Tests\Functional\Admin\Customer; - use FunctionalTester; use Webkul\Core\Models\SubscribersList; diff --git a/tests/functional/Admin/Customer/ReviewCest.php b/tests/functional/Admin/Customer/ReviewCest.php index a2c08e42d..aa2e775d2 100644 --- a/tests/functional/Admin/Customer/ReviewCest.php +++ b/tests/functional/Admin/Customer/ReviewCest.php @@ -2,12 +2,10 @@ namespace Tests\Functional\Admin\Customer; - use FunctionalTester; use Webkul\Core\Helpers\Laravel5Helper; use Webkul\Product\Models\ProductReview; - class ReviewCest { public function testIndex(FunctionalTester $I): void diff --git a/tests/functional/Admin/Sales/RefundCest.php b/tests/functional/Admin/Sales/RefundCest.php index c9fbc943c..af211b7d9 100644 --- a/tests/functional/Admin/Sales/RefundCest.php +++ b/tests/functional/Admin/Sales/RefundCest.php @@ -2,7 +2,6 @@ namespace Tests\Functional\Admin\Sales; - use FunctionalTester; use Webkul\Sales\Models\Refund; diff --git a/tests/functional/Admin/Sales/ShipmentsCest.php b/tests/functional/Admin/Sales/ShipmentsCest.php index 541598868..bddb41cb0 100644 --- a/tests/functional/Admin/Sales/ShipmentsCest.php +++ b/tests/functional/Admin/Sales/ShipmentsCest.php @@ -2,7 +2,6 @@ namespace Tests\Functional\Admin\Sales; - use FunctionalTester; use Webkul\Sales\Models\Shipment; diff --git a/tests/functional/CartRule/CartRuleCopyCest.php b/tests/functional/CartRule/CartRuleCopyCest.php index 7b6c5281d..96a0e8e6c 100644 --- a/tests/functional/CartRule/CartRuleCopyCest.php +++ b/tests/functional/CartRule/CartRuleCopyCest.php @@ -8,7 +8,6 @@ use Webkul\CartRule\Models\CartRule; class CartRuleCopyCest { - public function testCartRuleCopy(FunctionalTester $I) { $I->loginAsAdmin(); diff --git a/tests/functional/CartRule/CartRuleCreateCest.php b/tests/functional/CartRule/CartRuleCreateCest.php index e10207a64..efde8330e 100644 --- a/tests/functional/CartRule/CartRuleCreateCest.php +++ b/tests/functional/CartRule/CartRuleCreateCest.php @@ -7,21 +7,20 @@ use Webkul\CartRule\Models\CartRule; class CartRuleCreateCest { - public function testCartRuleCreation(FunctionalTester $I) { $I->loginAsAdmin(); $I->amOnAdminRoute('admin.cart-rules.index'); - // we are dealing with vue.js so we can not do classical form filling + // we are dealing with `Vue.js` so we can not do classical form filling $I->sendAjaxPostRequest(route('admin.cart-rules.store'), [ '_token' => csrf_token(), 'name' => 'Demo Cart Rule', - // the following fields are important to send with the POST request: - 'starts_from' => '', - 'ends_till' => '', + // the following fields are important to send with the POST request + 'starts_from' => '', + 'ends_till' => '', 'use_auto_generation' => 0, 'coupon_type' => 0, // no coupon @@ -43,6 +42,5 @@ class CartRuleCreateCest ]); $I->seeResponseCodeIsSuccessful(); - } } diff --git a/tests/functional/Checkout/Cart/CartCest.php b/tests/functional/Checkout/Cart/CartCest.php index 16216dfa9..c0eef83cd 100644 --- a/tests/functional/Checkout/Cart/CartCest.php +++ b/tests/functional/Checkout/Cart/CartCest.php @@ -37,11 +37,13 @@ class CartCest ]); $I->amOnPage('/checkout/cart'); - // $I->seeElement('#update_cart_button'); + $I->seeElement('#update_cart_button'); } public function checkCartWithoutQuantityBox(FunctionalTester $I): void { + $I->useDefaultTheme(); + cart()->addProduct($this->productWithoutQuantityBox->id, [ '_token' => session('_token'), 'product_id' => $this->productWithoutQuantityBox->id, @@ -52,5 +54,4 @@ class CartCest $I->amOnPage('/checkout/cart'); $I->dontSeeElement('#update_cart_button'); } - -} \ No newline at end of file +} diff --git a/tests/functional/Checkout/Order/OrderCest.php b/tests/functional/Checkout/Order/OrderCest.php index f2a833b44..3f65ff64a 100644 --- a/tests/functional/Checkout/Order/OrderCest.php +++ b/tests/functional/Checkout/Order/OrderCest.php @@ -4,14 +4,13 @@ namespace Tests\Functional\Checkout\Order; use Faker\Factory; use FunctionalTester; -use Cart; use Webkul\Sales\Models\Order; +use Webkul\Core\Models\Channel; +use Webkul\Customer\Models\Customer; use Webkul\Sales\Models\OrderAddress; use Webkul\Sales\Models\OrderPayment; use Webkul\Checkout\Models\CartAddress; use Webkul\Checkout\Models\CartPayment; -use Webkul\Customer\Models\Customer; -use Webkul\Core\Models\Channel; /** * Class OrderCest @@ -20,7 +19,6 @@ use Webkul\Core\Models\Channel; */ class OrderCest { - /** * @param \FunctionalTester $I */ @@ -46,10 +44,10 @@ class OrderCest 'customer' => $customer, ]); - // assert that checkout can be reached and generate csrf token. + // assert that checkout can be reached and generate csrf token $I->amOnRoute('shop.checkout.onepage.index'); - // simulate the entering of the address(es): + // simulate the entering of the address(es) $I->sendAjaxPostRequest(route('shop.checkout.save-address'), [ '_token' => csrf_token(), 'billing' => array_merge($addressData, [ @@ -100,8 +98,9 @@ class OrderCest 'cart_id' => $mocks['cart']->id, ]); - // simulate click on the 'place order' button at the last step: - $I->sendAjaxPostRequest(route('shop.checkout.save-order'), + // simulate click on the 'place order' button at the last step + $I->sendAjaxPostRequest( + route('shop.checkout.save-order'), ['_token' => csrf_token()] ); @@ -144,4 +143,4 @@ class OrderCest 'order_id' => $order->id, ]); } -} \ No newline at end of file +} diff --git a/tests/functional/Customer/CustomerCest.php b/tests/functional/Customer/CustomerCest.php index bac470277..acb8b93fb 100644 --- a/tests/functional/Customer/CustomerCest.php +++ b/tests/functional/Customer/CustomerCest.php @@ -3,9 +3,8 @@ namespace Tests\Functional\Customer; use Faker\Factory; -use Webkul\Customer\Models\Customer; -use Webkul\Customer\Models\CustomerAddress; use FunctionalTester; +use Webkul\Customer\Models\CustomerAddress; class CustomerCest { @@ -22,23 +21,23 @@ class CustomerCest $I->amOnPage('/'); - // $I->click('Profile'); - // $I->click('Edit'); - // $I->selectOption('gender', 'Other'); - // $I->click('Update Profile'); + $I->click('Profile'); + $I->click('Edit'); + $I->selectOption('gender', 'Other'); + $I->click('Update Profile'); - // $I->dontSeeInSource('The old password does not match.'); - // $I->seeInSource('Profile updated successfully.'); + $I->dontSeeInSource('The old password does not match.'); + $I->seeInSource('Profile updated successfully.'); - // $I->seeRecord(Customer::class, [ - // 'id' => $customer->id, - // 'gender' => 'Other', - // ]); + $I->seeRecord(Customer::class, [ + 'id' => $customer->id, + 'gender' => 'Other', + ]); } public function updateCustomerAddress(FunctionalTester $I): void { - // Instantiate a european faker factory to have the vat provider available + // instantiate a european faker factory to have the vat provider available $faker = Factory::create('at_AT'); $formCssSelector = '#customer-address-form'; @@ -47,9 +46,9 @@ class CustomerCest $I->amOnPage('/'); - // $I->click('Profile'); - // $I->click('Address'); - // $I->click('Add Address'); + $I->click('Profile'); + $I->click('Address'); + $I->click('Add Address'); $this->fields = [ 'company_name' => $faker->company, @@ -65,49 +64,51 @@ class CustomerCest ]; foreach ($this->fields as $key => $value) { - // the following fields are rendered via javascript so we ignore them: - if (! in_array($key, [ + // the following fields are rendered via javascript so we ignore them + if (!in_array($key, [ 'country', 'state', ])) { $selector = 'input[name="' . $key . '"]'; - // $I->fillField($selector, $value); + $I->fillField($selector, $value); } } $I->wantTo('Ensure that the company_name field is being displayed'); - // $I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)'); + $I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)'); - // we need to use this css selector to hit the correct
. There is another one at the - // page header (search) - // $I->submitForm($formCssSelector, $this->fields); - // $I->seeInSource('The given vat id has a wrong format'); + /* + We need to use this css selector to hit the correct . There is another one at the + page header (search). + */ + $I->submitForm($formCssSelector, $this->fields); + $I->seeInSource('The given vat id has a wrong format'); $I->wantTo('enter a valid vat id'); $this->fields['vat_id'] = $faker->vat(false); - // $I->submitForm($formCssSelector, $this->fields); + $I->submitForm($formCssSelector, $this->fields); - // $I->seeInSource('Address have been successfully added.'); + $I->seeInSource('Address have been successfully added.'); $this->assertCustomerAddress($I); $I->wantTo('Update the created customer address again'); - // $I->click('Edit'); + $I->click('Edit'); $oldcompany = $this->fields['company_name']; $this->fields['company_name'] = $faker->company; - // $I->submitForm($formCssSelector, $this->fields); + $I->submitForm($formCssSelector, $this->fields); - // $I->seeInSource('Address updated successfully.'); + $I->seeInSource('Address updated successfully.'); $I->dontSeeRecord(CustomerAddress::class, [ 'company_name' => $oldcompany, ]); - // $this->assertCustomerAddress($I); + $this->assertCustomerAddress($I); } /** @@ -115,17 +116,17 @@ class CustomerCest */ private function assertCustomerAddress(FunctionalTester $I): void { - // $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'], - // ]); + $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'], + ]); } -} \ No newline at end of file +}