Skip to content
This repository

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

..
Octocat-spinner-32 classes
Octocat-spinner-32 data
Octocat-spinner-32 fixtures
Octocat-spinner-32 view
Octocat-spinner-32 README.md
Octocat-spinner-32 TestOfAccountConfigurationController.php
Octocat-spinner-32 TestOfActivateAccountController.php
Octocat-spinner-32 TestOfAppConfigController.php
Octocat-spinner-32 TestOfBackupController.php
Octocat-spinner-32 TestOfBackupMySQLDAO.php
Octocat-spinner-32 TestOfCheckCrawlerController.php
Octocat-spinner-32 TestOfCheckVersionController.php
Octocat-spinner-32 TestOfConfig.php
Octocat-spinner-32 TestOfCrawler.php
Octocat-spinner-32 TestOfCrawlerAuthController.php
Octocat-spinner-32 TestOfDAOFactory.php
Octocat-spinner-32 TestOfDashboardController.php
Octocat-spinner-32 TestOfDataset.php
Octocat-spinner-32 TestOfExportController.php
Octocat-spinner-32 TestOfExportMySQLDAO.php
Octocat-spinner-32 TestOfExportServiceUserDataController.php
Octocat-spinner-32 TestOfFavoritePostMySQLDAO.php
Octocat-spinner-32 TestOfFollowMySQLDAO.php
Octocat-spinner-32 TestOfFollowerCountMySQLDAO.php
Octocat-spinner-32 TestOfForgotPasswordController.php
Octocat-spinner-32 TestOfGridController.php
Octocat-spinner-32 TestOfGridExportController.php
Octocat-spinner-32 TestOfGroupMemberMySQLDAO.php
Octocat-spinner-32 TestOfGroupMembershipCountMySQLDAO.php
Octocat-spinner-32 TestOfGroupMySQLDAO.php
Octocat-spinner-32 TestOfHashtagMySQLDAO.php
Octocat-spinner-32 TestOfInstaller.php
Octocat-spinner-32 TestOfInstallerController.php
Octocat-spinner-32 TestOfInstallerMySQLDAO.php
Octocat-spinner-32 TestOfInstanceMySQLDAO.php
Octocat-spinner-32 TestOfInviteMySQLDAO.php
Octocat-spinner-32 TestOfLinkMySQLDAO.php
Octocat-spinner-32 TestOfLoader.php
Octocat-spinner-32 TestOfLocationMySQLDAO.php
Octocat-spinner-32 TestOfLogger.php
Octocat-spinner-32 TestOfLoginController.php
Octocat-spinner-32 TestOfLogoutController.php
Octocat-spinner-32 TestOfMailer.php
Octocat-spinner-32 TestOfMentionMySQLDAO.php
Octocat-spinner-32 TestOfMenuItem.php
Octocat-spinner-32 TestOfMutexMySQLDAO.php
Octocat-spinner-32 TestOfOptionMySQLDAO.php
Octocat-spinner-32 TestOfOwner.php
Octocat-spinner-32 TestOfOwnerInstanceMySQLDAO.php
Octocat-spinner-32 TestOfOwnerMySQLDAO.php
Octocat-spinner-32 TestOfPDOCorePluginDAO.php
Octocat-spinner-32 TestOfPDODAO.php
Octocat-spinner-32 TestOfPasswordResetController.php
Octocat-spinner-32 TestOfPlaceMySQLDAO.php
Octocat-spinner-32 TestOfPlugin.php
Octocat-spinner-32 TestOfPluginHook.php
Octocat-spinner-32 TestOfPluginMySQLDAO.php
Octocat-spinner-32 TestOfPluginOptionController.php
Octocat-spinner-32 TestOfPluginOptionMySQLDAO.php
Octocat-spinner-32 TestOfPost.php
Octocat-spinner-32 TestOfPostAPIController.php
Octocat-spinner-32 TestOfPostController.php
Octocat-spinner-32 TestOfPostErrorMySQLDAO.php
Octocat-spinner-32 TestOfPostIterator.php
Octocat-spinner-32 TestOfPostMySQLDAO.php
Octocat-spinner-32 TestOfProfiler.php
Octocat-spinner-32 TestOfRSSController.php
Octocat-spinner-32 TestOfRegisterController.php
Octocat-spinner-32 TestOfSession.php
Octocat-spinner-32 TestOfSessionCache.php
Octocat-spinner-32 TestOfSmartyModifierLinkUsernames.php
Octocat-spinner-32 TestOfSmartyThinkUp.php
Octocat-spinner-32 TestOfStreamDataMySQLDAO.php
Octocat-spinner-32 TestOfStreamProcMySQLDAO.php
Octocat-spinner-32 TestOfStreamerAuthController.php
Octocat-spinner-32 TestOfTableStatsMySQLDAO.php
Octocat-spinner-32 TestOfTestAdminController.php
Octocat-spinner-32 TestOfTestAuthAPIController.php
Octocat-spinner-32 TestOfTestAuthController.php
Octocat-spinner-32 TestOfTestController.php
Octocat-spinner-32 TestOfThinkUpEmbedController.php
Octocat-spinner-32 TestOfThreadJSController.php
Octocat-spinner-32 TestOfToggleActiveInstanceController.php
Octocat-spinner-32 TestOfToggleActiveOwnerController.php
Octocat-spinner-32 TestOfToggleActivePluginController.php
Octocat-spinner-32 TestOfToggleOwnerAdminController.php
Octocat-spinner-32 TestOfTogglePublicInstanceController.php
Octocat-spinner-32 TestOfURLProcessor.php
Octocat-spinner-32 TestOfUpdateNowController.php
Octocat-spinner-32 TestOfUpgradeController.php
Octocat-spinner-32 TestOfUserController.php
Octocat-spinner-32 TestOfUserErrorMySQLDAO.php
Octocat-spinner-32 TestOfUserMySQLDAO.php
Octocat-spinner-32 TestOfUtils.php
Octocat-spinner-32 TestOfWebapp.php
Octocat-spinner-32 WebTestOfApplicationSettings.php
Octocat-spinner-32 WebTestOfCSRFToken.php
Octocat-spinner-32 WebTestOfCaptchaImage.php
Octocat-spinner-32 WebTestOfChangePassword.php
Octocat-spinner-32 WebTestOfCrawlerRun.php
Octocat-spinner-32 WebTestOfDashboard.php
Octocat-spinner-32 WebTestOfDeleteInstance.php
Octocat-spinner-32 WebTestOfInstallation.php
Octocat-spinner-32 WebTestOfLogin.php
Octocat-spinner-32 WebTestOfPostDetailPage.php
Octocat-spinner-32 WebTestOfRegistration.php
Octocat-spinner-32 WebTestOfTwitterDashboard.php
Octocat-spinner-32 WebTestOfUpgradeDatabase.php
Octocat-spinner-32 all_controller_tests.php
Octocat-spinner-32 all_install_tests.php
Octocat-spinner-32 all_integration_tests.php
Octocat-spinner-32 all_model_tests.php
Octocat-spinner-32 all_plugin_tests.php
Octocat-spinner-32 all_tests.php
Octocat-spinner-32 config.tests.sample.inc.php
Octocat-spinner-32 init.tests.php
Octocat-spinner-32 migration-assertions.php
README.md

ThinkUp 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 thinkup_tests and set the $TEST_DATABASE config variable to that name. You will also need a local installation of ThinkUp; set the $TEST_SERVER_DOMAIN config variable equal to its URL--for example, http://localhost.

In webapp/config.inc.php, in the DEVELOPER CONFIG section, set the name of your tests database, and the username and password to access it. This database name should match the one you just set in tests/config.tests.inc.php.

Test Assumptions

In order for the tests to pass, you must:

  • Have a tests/config.tests.inc.php file with the correct values set
  • Set the crawler log file in webapp/config.inc.php and make that file writable
  • Set the test database name to an empty tests database which the tests will destroy each run in webapp/config.inc.php
  • Set the test database user to a user with all privileges in the test database and global CREATE, DROP, and FILE privs
  • Set caching to false in webapp/config.inc.php
  • Have a local installation of ThinkUp using your test database
  • Have a working internet connection

To run a particular test suite, like the UserDAO suite, in the ThinkUp source code root folder, use this command:

$ php tests/TestOfUserDAO.php

To run all the test suites, use:

$ php tests/all_tests.php

To run a single test, set the TEST_METHOD environment variable. For example:

$ TEST_METHOD=testIsPluginActive php tests/TestOfPluginMySQLDAO.php

Writing Tests

The test suite assumes there is an empty tests database (like thinkup_tests) which the default ThinkUp database user can access. If your test needs to read and write to the ThinkUp database, extend ThinkUpUnitTestCase and run parent::setUp() in your setUp() method, and parent::tearDown() in your tearDown() method. These methods create an empty copy of the ThinkUp 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 existing tests as examples.

Model Tests (all_model_tests.php)

See TestOfOwnerInstanceMySQLDAO.php as an example of a set of DAO tests. Use the FixtureBuilder class to create test data fixtures to test against.

Controller Tests (all_controller_tests.php)

See TestOfDashboardController.php as an example of a set of controller test cases.

Plugin Tests (all_plugin_tests.php)

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

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 /thinkup/webapp/plugins/twitter/tests/ for examples of Twitter crawler plugin tests.

Integration Tests (all_integration_tests.php)

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

Once your tests pass, add them to the appropriate all_tests.php file to run with the existing suites. For example, new model tests should go in all_model_tests.php, new controller tests should go in all_controller_tests.php, etc.

How to Debug Tests

To print variable values to the terminal while running tests, use the ThinkUpWebTestCase::debug method or ThinkUpBasicTestCase::debug method. For example, you can add a line like this to your test:

$this->debug("This is my debugging statement which will print during my test run.");

To print something other than a string in a debug statement, use the Utils::varDumpToString method, like this:

$this->debug(Utils::varDumpToString($my_nonstring_object));

To see your debug statements, run your test like so:

TEST_DEBUG=1 php tests/yourtest.php

I'm getting lots of test failures. Help!

Possible reasons for getting a high number of test failures include:

  • An incorrect $TEST_SERVER_DOMAIN in tests/config.tests.inc.php. Please make sure that this points to the web root of your ThinkUp installation. Relevant thread
  • An incorrect value for any of the test database values. Please make sure that both config.inc.php and config.tests.inc.php point to an existing, empty database.

If you have double-checked these and everything appears to be intact, send an email to the mailing list or pop into the IRC channel and we'll see what we can do to help you out.

Something went wrong with that request. Please try again.