All code submitted to the repository should have corresponding tests that pass. Here’s how to run and write tests.
First, configure your test environment. Copy
tests/config.tests.inc.php and set the appropriate values. You will need a clean, empty database to run your tests. By default, name it
thinktank_tests and set the
$TEST_DATABASE config variable to that name.
Then, to run a particular test, like the UserDAO test, in the thinktank source code root folder, use this command:
$ php tests/userdao_test.php
To run all the tests, use:
$ php tests/all_tests.php
The webapp tests contained in
tests/frontend_test.php assumes you have a local installation of ThinkTank and that it is using your test database. Make sure you update your
config.inc.php to point to the
thinktank_tests database before running the webapp tests.
The test suite assumes there is an empty tests database (like
thinktank_tests) which the default ThinkTank db user can access. If your test needs to read and write to the ThinkTank database, extend
ThinkTankUnitTestCase and run
parent::setUp() in your
setUp() method, and
parent::tearDown() in your
tearDown() method. These methods create an empty copy of the ThinkTank database structure to execute a test, then drop all the tables in it when the test is complete. After you call the parent setUp() method in your test’s setUp(), insert the data your test requires.
Best practices for writing tests are still getting developed. In the meantime, use some existing tests as examples.
userdao_test.php as an example of a set of DAO tests.
Add tests for particular pages inside the webapp to
To test consumption of data from web services, mock up the appropriate classes and store test data to local files in the format the API would return them in.
For example, the
classes/mock.TwitterOAuth.php class reads Twitter data from the files in the
twittercrawler_test.php as an example of the Twitter crawler test.
Once your tests work, add them to the
all_tests.php file to run along with the existing tests.