...
- Do a normal install on the machine you wish to test on.
Create a
phpunit.xml
file in your config directory. It should contain the following settings:Code Block language xml title phpunit.xml <?xml version="1.0" encoding="UTF-8"?> <rogo> <db_database>phpunit_database_schema_name</db_database> <db_user>username</db_user> <db_password>password</db_password> <data>path_to_user_data_directory</data> <db_engine>The database table type you wish to run Rogo, it will default to the one your main Rogo site is installed on (optional)</db_engine> <db_help_engine>The database table type you wish to run the help system on, it will default to the one your main Rogo site is installed on (optional)</db_help_engine> </rogo>
- Run the following script from the command line: testing/unittest/cli/init.php
...
- Run the following command to run the test suite:
vendor/bin/phpunit -c testing/unittest/config/phpunit.xml
Info | ||
---|---|---|
If you are developing a patch that makes changes to the Rogo database you will need to reinitialise your unit test database with the --clean option to ensure that it is in place.
|
Creating a unit test
All unit tests should be placed in the testing/unittest/tests
directory of rogo.
...
In the test_example_logicalfunction
if you to query the database you simply use the query function:
The function takes an array as a parmater:
key | description | example |
---|---|---|
table | table we are selecting from | table' => 'test' |
orderby | order by columns | 'orderby' => array('c2') |
columns | columns we are interested in | 'columns' => array('c1','c2') |
where | filter to apply - an array (column, value, operator) | 'where' => array(array('column' => 'c2', 'value' => 1, 'operator' => '=') |
The function returns a results array you can use the phpunit assertEquals fucntion to comapre against an expected result set.
Code Block | ||||
---|---|---|---|---|
| ||||
$querytable = $this->query(array('columns' => array('property_id', 'idMod'), 'table' => 'properties_modules'));
// example result set
array(0 =>
array(
'property_id' => 1,
'idMod' => 2
),
array(
'property_id' => 2,
'idMod' => 4
),
) |
If you need to do more and wanted to access the rogo database object all you would have to do is use the $this->db
variable.
...
function | description | direct access in unit test |
---|---|---|
get_base_admin | returns user data (an array) for the default admin user | $this->admin |
get_base_student | returns user data (an array) for the default student user | $this->studnet>student |
get_base_module | returns user data (an array) for the default module | $this->module |
get_base_faculty | returns user data (an array) for the default faculty | $this->faculty |
get_base_school | returns user data (an array) for the default school | $this->school |
...