NOTE: The testing framework has not yet been backported from V2, so this page does not apply to Zen Cart 1.X.X.
Writing automated tests is important to ensure that the tested features function properly both before and after making future changes to the system.
Preparation / Initial Setup
To prepare to run the Unit Test test suite:
First, install Composer:
- go to
- download and install
- follow the Getting Started instructions.
- go to
vendor/binto your path.
Run all tests, using:
phpunit -c testFramework/unittests/phpunit.xml
Running Individual Tests
While you are debugging a specific test (such as one you’re adding, see below), you may want to just call it in isolation rather than running the entire test suite. The syntax for doing this is:
phpunit --filter <test class name> <path to test class file>
phpunit --filter testPaginationCase testFramework/unittests/testsPaginator/paginatorTest.php
To add a new test, create your test in an appropriate subdir under
Note that if you have defined constants in your file, you may have to use the trick of setting the class global variables as is done in
protected $preserveGlobalState = FALSE; protected $runTestInSeparateProcess = TRUE;
If you want to put your tests in a new folder at the level of
testFramework/unittests, remember to add the new foldername to
Some features can only be properly tested by running them through a browser. We do this using Selenium and Firefox.
Preparation and Setup for Web Tests
- Follow the Prep/Setup above for Unit Testing, as these are dependencies for the Web Tests
- Install a Java JDK if one isn’t already on your computer
- Download Selenium Server Standalone Java Agent. This will give you a
- Install Firefox if not already present.
Be aware that sometimes the “latest” Firefox may not work with Selenium … so occasionally may need to use an older Firefox version, or upgrade Selenium to a newer version.
Preparing custom configurations
WebTests need to run from a local webserver, so you need a MySQL+Apache/Nginx (or equivalent) setup already present on your computer, and need to be able to access it from your installed Firefox browser. The Zen Cart Habitat server is ideal for this.
Since the webtests will run zc_install, be prepared for your database to be wiped out and your configure.php files to be updated.
testFramework/config/ folder there is a
localconfig_EXAMPLE.php file. Make a copy of that file and configure it to suit your local environment:
localconfig_YOURUSERNAME.php… ie: if I login to my PC as
billthen the filename would be:
Inside the file, edit the
definestatements to reflect your local webserver’s domain name, database credentials, etc for your Zen Cart dev site. If you’re running in a Zen Cart Habitat environment, the
WEBTEST_ADMIN_PASSWORD_INSTALLshould be set to
Running Web Tests
a) Start Selenium engine from command line:
java -jar <path_to>/selenium-server-standalone-<version>.jar -trustAllSSLCertificates
b) Start the webtests in another terminal window:
phpunit -c testFramework/webtests/phpunit.xml
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.