Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
classes
view
README.md
TestOfChangePassword.php
TestOfConfig.php
TestOfCrawler.php
TestOfDAOFactory.php
TestOfDatabase.php
TestOfFollowMySQLDAO.php
TestOfInstanceMySQLDAO.php
TestOfLinkMySQLDAO.php
TestOfLogger.php
TestOfMySQLDAO.php
TestOfOwnerInstanceDAO.php
TestOfOwnerMySQLDAO.php
TestOfPDODAO.php
TestOfPluginDAO.php
TestOfPluginHook.php
TestOfPostController.php
TestOfPostErrorMySQLDAO.php
TestOfPostMySQLDAO.php
TestOfPrivateDashboard.php
TestOfPrivateDashboardController.php
TestOfPublicTimeline.php
TestOfPublicTimelineController.php
TestOfSignIn.php
TestOfSmartyThinkTank.php
TestOfTestAuthController.php
TestOfTestController.php
TestOfUserMySQLDAO.php
TestOfUtils.php
TestOfWebapp.php
all_controller_tests.php
all_frontend_tests.php
all_model_tests.php
all_plugin_tests.php
all_tests.php
config.tests.sample.inc.php
init.tests.php

README.md

ThinkTank Tests

All code submitted to the repository should have corresponding tests that pass. Here's how to run and write tests.

Running Tests

First, configure your test environment. Copy tests/config.tests.sample.inc.php to 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/TestOfUserDAO.php

To run all the tests, use:

$ php tests/all_tests.php

The webapp tests contained in tests/all_frontend_tests.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.

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

Model Tests (all_model_tests.php)

See TestOfUserDAO.php as an example of a set of DAO tests.

Web Page Tests (all_frontend_tests.php)

Add tests for particular pages inside the webapp to an appropriately-named class. See TestOfChangePassword.php for an example.

Plugin Tests (all_plugin_tests.php)

All plugin-specific tests should live in the thinktank/webapp/plugins/plugin-name/tests/ directory. Write tests for the plugin's model objects and controller methods.

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 testdata directory.

See /thinktank/webapp/plugins/twitter/tests/ for examples of Twitter crawler plugin tests.

Once your tests work, add them to the all_tests.php file to run along with the existing tests.

Something went wrong with that request. Please try again.