Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Do a normal install on the machine you wish to test on. 
  2. Create a phpunit.xml file in your config directory. It should contain the following settings:

    Code Block
    languagexml
    titlephpunit.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>
    


  3. Run the following script from the command line: testing/unittest/cli/init.php

...

  1. 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.

Code Block
php testing/unittest/cli/init.php --clean


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:


keydescriptionexample
tabletable we are selecting from

table' => 'test'

orderbyorder by columns'orderby' => array('c2')
columnscolumns we are interested in'columns' => array('c1','c2')
wherefilter 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
languagephp
titlequery function example
$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.

...

functiondescriptiondirect access in unit test
get_base_adminreturns user data (an array) for the default admin user$this->admin
get_base_studentreturns user data (an array) for the default student user$this->studnet>student
get_base_modulereturns user data (an array) for the default module$this->module
get_base_facultyreturns user data (an array) for the default faculty$this->faculty
get_base_schoolreturns user data (an array) for the default school$this->school

...