Testing in Humhub/Yii extends the paradigm of unit testing by functional and acceptance tests.
Functional tests are similar to acceptance tests, with the difference that functional tests do not run on an actual browser
application logic as database or the
Yii application context. This can be handy if you require a specific application state
as specific settings for a test. Write functional tests in order to test your controllers, forms and controller access for different configurations settings.
Unit tests are ideal for white box testing and is the fastest way of writing low level tests for specific classes or components. Implement unit tests for testing single components and classes.
HumHub uses Codeception as testing framework.
ATTENTION: Some of the test libraries are developed for use with PHP 7 only
Information about how to write tests with codeception are available here:
- Install codeception (http://codeception.com/install)
- Composer codeception:
Note: Instead of a global codeception installation you can also use the version fetched by composer
protected/vendor/codeception/codeception. The composer version is used when running the tests with grunt.
- Create a test database:
- Configure database access:
Configure the database connection for your test environment in
- Run Database Migrations:
Note: You'll have to run the migrations for your test environment manually in order to keep your test environment up to date.
- Install test environment:
HUMHUB_PATH is used by your test environment in non core module tests to determine the HumHub root.
This is only required for non core module tests and can also be set in your modules test configuration
The settings of your default configuration files in the
$HUMHUB_PATH/protected/humhub/tests/config directory can be overwritten for each module
within the corresponding
The following configuration files can be used to overwrite the test configuration:
- The initial test configuration
test.phpis used to set general test settings as the path to your
humhub_rootor used fixtures.
- The configuration of
common.phpis used for all suites and can be overwritten by settings in a suite configuration.
- Suite specific test configurations (e.g. functional.php) are used to configure HumHub for a specific test suite.
The configurations for a suite will be merged in the following order:
@myModule/tests/config/env/myenv/common.php (if exists)
@myModule/tests/config/env/myenv/functional.php (if exists)
For running a test for a specific environment you'll have to set te
--env argument for your test-run.
Example for running all functional tests of a tasks module in a master environment:
- Create a file
@mymodule/tests/config/env/master/test.phpwith the following content: return [ 'humhub_root' => '/pathToMasterBranch' ];
- If needed set further HumHub settings in
codecept run functional --env master
Note: Your modules test.php configuration file should always set an 'modules' array with all non core modules needed for test execution.
Note: You can specify multiple --env arguments in codeception, for module tests the first --env argument must contain the environment of your
humhub_rootsettings you want to use for this test run.
In order to run a test you can either use the conventional
codecept command which requires a global installation,
grunt test command. The
grunt test command currently only works for core module tests.
The first time you run a test, the test files need to be build, this can be achieved by adding the
-build parameter to the test run command:
Only build test files without test run:
To run non core module tests you have to edit at least the test config file under
If your modules reside outside of the /protected/humhub/modules directory you'll have to set the following configurations:
You may also want to extend the
moduleAutoloadPath in your
Selenium are required to run acceptance tests on your system.
Note: If you are already running a webserver on port 8080, you do not need to start the test server described blow, because Humhub tests are run on port 8080. However if your
DocumentRootdirectory is not configured to directly open HumHub via
localhostyou have to do some adjustments in the
codeception.ymlfile of our
test-entry-url) and the
acceptance.suite.ymlfile. Alternatively start the test server as described below (in humhub root directory).
- Start a Phantom.js server:
and copy them in the same directory.
Start test server:
Run your acceptance test:
grunt testcommand only works for core tests.