Skip to content

Merchant oriented scripts for OpenCart based on PHPUnit.

License

Notifications You must be signed in to change notification settings

anytizer/ocunit

Repository files navigation

OCUnit

Merchant oriented scripts for OpenCart based on PHPUnit.

It partially overrides the default OpenCart installation, i.e. install/opencart.sql and re-builds with your own memo.


WARNING

Never execute these scripts against your live database or in production server environment.

THIS IS AN EXPERIMENTAL SOFTWARE.

It will overwrite the product information, pricing, images, currencies, customers, users, session, emails, passwords, .htaccess and more. Almost any information will be destroyed, and recreated. It even truncates a lot of oc_* tables!

The database will NEVER return to its original state. So, OCUnit is for you only if you are setting up your store for the first time.

Run OCUnit at your own risk. The developers of OCUnit cannot be responsible for your accidental damage to the database on your store.


OCUnit is better when you are about to set up a new store. If you have already set up a store that is live, and you do not have a local copy of your catalog memo, do not run these tests.

Disclaimer Story

This project is NOT about developing the core OpenCart, but the implementation of that software to run a store. Please do not expect a code coverage test for OpenCart.

End user of OCUnit is a semi techincal store owner or a development team dedicated to support the store onwer establish digital a store.

OCUnit reads the ACTUAL database configuration values and URLs from within your OpenCart's config.php files to run tests. There are few business rules and configurations you should edit, to prepare your use. Rules may differ as per businesses. So, most of the tests are empty. But they should self-guide you technically on how to write the tests.

Some information in this document are drafts only (documented before coding).

Test Examples

Do test like (merchant's perspectives - yes)

  • A corresponding image should exist for product or category.
    • Product Image: 800 px x 400 px
    • Category Image: 200 px x 200 px
    • Images should be in .png format only
  • A "downloadable" file has to be in a .zip format only.
  • Directory listing should be disabled throughout the website - admin or store.
  • Store price cannot be less than the manufacturer price even after discounts.
  • Updating price makes a history of price change.
    • Keep a log of when prices were changed.
    • Maintain a price change history.
    • Create a price log table.
  • Products must have video links associated with them in their description.
  • Products must have multiple images.
  • Concisely generate inventory statistics - here.
  • Re-create the database information from your merchant memos.
    • Stores and URLs
    • Categories and Products
    • Images
    • Languages - be always default: "1" for en-gb.
    • Information Pages

And it DOES NOT test like (code coverage - no)

  • Add product feature should accept an image upload.
  • The system should allow to upload a downloadable file.
  • Price edit should be working fine.

More accurate progress report on individual testdox: admin, catalog, business (logs produced).

These are just some samples to illustrate how business rules are created.

Tests have been now separated to admin, catalog and business to match the nature of OpenCart.

Requirements

Dependency Version Description
PHP 8.1.1+ -
PHPUnit 9.5.20+ -
OpenCart 4.0.0+ master branch
relay.php - composer package of a minimal HTTP client
guid.php - UUID generator
parsedown - .md to .html
phpmailer or alike - to generate emails (compare with in-built smtp client)

Sample Test Output

Sample Output

Test Cases

Folder Case Description
admin admin various tests in admin features
catalog api API tests as on documentation
business business logic tests
catalog frontend general tests
core opencart core tests
database tests with direct database hits
general other uncategorized tests appear here
issues For issues imported from GitHub and CVE Database
mail test email sending features
report inventory and database statistics from merchant's perspectives
business cases Customized business rules

Three steps of Operation

Install OCUnit, Configure it, Execute it, Check your store. And finally, delete it ;-)

Since OCUnit rebuilds the OpenCart database, it is always riskier to run second time, particularly when you created your live copy of OpenCart store data.

wireframe

Picture made with Balsamiq

Step 1: Installation

Clone OpenCart and OCUnit projects "locally". Then install and configure them independently in "/oc/opencart" and "/oc/ocunit". Also, download the phpunit phar file in the ocunit directory and, update the composer dependencies.

Again, do not install OCUnit to connect to the live database!

  • Installation: download phpunit-11.3.1.phar and put it in here.
  • Rename it to phpunit.phar and run like below.

Sample scripts:

cd /HOME/USER/htdocs|public_html|www|web
mkdir oc
cd oc

git clone https://github.com/opencart/opencart.git opencart
git clone https://github.com/anytizer/ocunit.git ocunit

cd ocunit

# Download PHPUnit
wget -oq https://phar.phpunit.de/phpunit.phar
mv phpunit-11.3.1.phar phpunit.phar

# Update Composer based packages
# wget -oq https://getcomposer.org/download/latest-stable/composer.phar
# php composer.phar update

Step 2: Configurations

Important - right after installation, you should consider editing:

to tell something about your store information. Merchants may depend on these/(their own) files to change the behaviour of OpenCart. Though not fully promised, OCUnit will re-build the OpenCart database based on these configurations.

Step 3: Test Execution

You have to scope your tests for admin, catalog or business purpose. So, run them individually.

cd admin
php ../phpunit.phar cases/admin/

Or,

cd catalog
php ../phpunit.phar cases/catalog/

Or,

cd business
php ../phpunit.phar cases/

Log Files Produced

Inspirations

Contribution

If you have a specific idea on how OCUnit (Merchant's view of test scripts for OpenCart based on PHPUnit) should function, fork the project and open pull request for your new test cases. Or, create a new issue in @anytizer/ocunit project.

Made with IDEs and Tools

About

Merchant oriented scripts for OpenCart based on PHPUnit.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages