Skip to content

Commit

Permalink
Issue #119: Refine plugin architecture
Browse files Browse the repository at this point in the history
* Converted Webapp and Crawler objects to singletons, added tests
* Removed global webapp and crawler instantiation in init.php
* Fixed all plugin tests to work with new singletons
* Fixed all_plugin_tests.php test group
* Cleaned up test file requires, refined ThinkTank-specific Unit Test classes
* Fixed potential fatal errors in plugin hook objects
* Added missing docblocks
  • Loading branch information
ginatrapani committed Jun 15, 2010
1 parent 99e5706 commit 21fa1c5
Show file tree
Hide file tree
Showing 29 changed files with 664 additions and 314 deletions.
20 changes: 12 additions & 8 deletions tests/TestOfConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankBasicUnitTestCase.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Config.php';

/**
* Test of Config object
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfConfig extends ThinkTankBasicUnitTestCase {
function TestOfConfig() {
/**
* Constructor
*/
function __construct() {
$this->UnitTestCase('Config class test');
}

function setUp() {
}
function tearDown() {
}

/**
* Test config singleton instantiation
*/
function testConfigSingleton() {
// this here just to test values, not needed in normal use.
global $THINKTANK_CFG;
Expand All @@ -25,4 +30,3 @@ function testConfigSingleton() {
$this->assertTrue($config->getValue('log_location') == $THINKTANK_CFG['log_location'], 'Log location set');
}
}
?>
79 changes: 79 additions & 0 deletions tests/TestOfCrawler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
require_once dirname(__FILE__).'/config.tests.inc.php';
require_once $SOURCE_ROOT_PATH.'extlib/simpletest/autorun.php';
require_once $SOURCE_ROOT_PATH.'extlib/simpletest/web_tester.php';
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);

require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankBasicUnitTestCase.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.ThinkTankPlugin.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/class.TestFauxHookableApp.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/interface.TestAppPlugin.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/class.TestFauxPlugin.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.ThinkTankPlugin.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.CrawlerPlugin.php';
require_once $SOURCE_ROOT_PATH.'webapp/plugins/hellothinktank/model/class.HelloThinkTankPlugin.php';

/**
* Test Crawler object
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfCrawler extends ThinkTankBasicUnitTestCase {

/**
* Constructor
*/
function __construct() {
$this->UnitTestCase('Crawler class test');
}

/**
* Set up test
*/
function setUp() {
parent::setUp();
}

/**
* Tear down test
*/
function tearDown() {
parent::tearDown();
}

/**
* Test Crawler singleton instantiation
*/
public function testCrawlerSingleton() {
$crawler = Crawler::getInstance();
$this->assertTrue(isset($crawler));
//clean copy of crawler, no registered plugins, will throw exception
$this->expectException( new Exception("No plugin object defined for: hellothinktank") );
$this->assertEqual($crawler->getPluginObject("hellothinktank"), "HelloThinkTankPlugin");
//register a plugin
$crawler->registerPlugin('hellothinktank', 'HelloThinkTankPlugin');
$this->assertEqual($crawler->getPluginObject("hellothinktank"), "HelloThinkTankPlugin");

//make sure singleton still has those values
$crawler_two = Crawler::getInstance();
$this->assertEqual($crawler->getPluginObject("hellothinktank"), "HelloThinkTankPlugin");
}

/**
* Test Crawler->crawl
*/
public function testCrawl() {
$crawler = Crawler::getInstance();

$crawler->registerPlugin('nonexistent', 'TestFauxPluginOne');
$crawler->registerCrawlerPlugin('TestFauxPluginOne');
$this->expectException( new Exception("The TestFauxPluginOne object does not have a crawl method.") );
$crawler->crawl();

$crawler->registerPlugin('hellothinktank', 'HelloThinkTankPlugin');
$crawler->registerCrawlerPlugin('HelloThinkTankPlugin');
$this->assertEqual($crawler->getPluginObject("hellothinktank"), "HelloThinkTankPlugin");
$crawler->crawl();

}
}
8 changes: 3 additions & 5 deletions tests/TestOfLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankBasicUnitTestCase.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Logger.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.Config.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.LoggerSlowSQL.php';
require_once $SOURCE_ROOT_PATH.'webapp/config.inc.php';


class TestOfLogging extends ThinkTankBasicUnitTestCase {
class TestOfLogger extends ThinkTankBasicUnitTestCase {
function __construct() {
$this->UnitTestCase('Log class test');
$this->UnitTestCase('Logger class test');
}

function setUp() {
Expand All @@ -34,8 +33,7 @@ function testNewLoggerSingleton() {
$this->assertWantedPattern('/Singleton logger should write this to the log/', $messages[sizeof($messages) - 1]);
$logger->setUsername('single-ton');
$logger->logStatus('Should write this to the log with a username', get_class($this));
$this->assertWantedPattern('/single-ton | TestOfLogging:Singleton logger should write this to the log/', $messages[sizeof($messages) - 1]);
$this->assertWantedPattern('/single-ton | TestOfLogger:Singleton logger should write this to the log/', $messages[sizeof($messages) - 1]);
$logger->close();
}
}
?>
57 changes: 45 additions & 12 deletions tests/TestOfPluginHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,60 @@
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);

require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankBasicUnitTestCase.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.PluginHook.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.ThinkTankPlugin.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/class.TestFauxHookableApp.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/interface.TestAppPlugin.php';
require_once $SOURCE_ROOT_PATH.'tests/classes/class.TestFauxPlugin.php';

/**
* Test of PluginHook class
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfPluginHook extends ThinkTankBasicUnitTestCase {

function TestOfPluginHook() {
/**
* Constructor
*/
function __construct() {
$this->UnitTestCase('PluginHook class test');
}

function setUp() {
}
/**
* Test registerPlugin
*/
function testRegisterAndGetPlugin() {
$test_ph = new TestFauxHookableApp();
$test_ph->registerPlugin('facebook', "FacebookPlugin");
$test_ph->registerPlugin('twitter', "TwitterPlugin");
$test_ph->registerPlugin('flickr', "FlickrPlugin");

function tearDown() {
$this->assertEqual($test_ph->getPluginObject("facebook"), "FacebookPlugin");
$this->assertEqual($test_ph->getPluginObject("twitter"), "TwitterPlugin");
$this->assertEqual($test_ph->getPluginObject("flickr"), "FlickrPlugin");
}
/**
* Test getPluginObject
*/
function testGetPluginObjectDoesntExist() {
$test_ph = new TestFauxHookableApp();
$this->expectException( new Exception("No plugin object defined for: notregistered") );
$plugin_obj = $test_ph->getPluginObject("notregistered");
}

function testRegisterPlugin() {
$ph = new PluginHook();
$ph->registerPlugin('facebook', "FacebookPlugin");
$plugin_obj = $ph->getPluginObject("facebook");
$this->assertEqual($plugin_obj, "FacebookPlugin");
/**
* Test registerPerformAppFunction and emit
* @TODO Test for registering an object which does not exist; currently this causes a PHP fatal error
*/
function testRegisterPerformAppFunction() {
//register first, should work
$test_ph = new TestFauxHookableApp();
$test_ph->registerPerformAppFunction('TestFauxPlugin');
$test_ph->performAppFunction();

$this->expectException( new Exception("No plugin object defined for: notregistered") );
$plugin_obj = $ph->getPluginObject("notregistered");
//register an object without the right method
$test_ph->registerPerformAppFunction('TestFauxPluginOne');
$this->expectException( new Exception("The TestFauxPluginOne object does not have a performAppFunction method.") );
$test_ph->performAppFunction();
}
}
74 changes: 74 additions & 0 deletions tests/TestOfWebapp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
require_once dirname(__FILE__).'/config.tests.inc.php';
require_once $SOURCE_ROOT_PATH.'extlib/simpletest/autorun.php';
require_once $SOURCE_ROOT_PATH.'extlib/simpletest/web_tester.php';
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);

require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankBasicUnitTestCase.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.ThinkTankPlugin.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/interface.CrawlerPlugin.php';
require_once $SOURCE_ROOT_PATH.'webapp/plugins/hellothinktank/model/class.HelloThinkTankPlugin.php';

/**
* Test Webapp object
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfWebapp extends ThinkTankBasicUnitTestCase {

/**
* Constructor
*/
function __construct() {
$this->UnitTestCase('Webapp class test');
}

/**
* Set up test
*/
function setUp() {
parent::setUp();
}

/**
* Tear down test
*/
function tearDown() {
parent::tearDown();
}

/**
* Test Webapp singleton instantiation
*/
public function testWebappSingleton() {
$webapp = Webapp::getInstance();
//test default active plugin
$this->assertEqual($webapp->getActivePlugin(), "twitter");
}

/**
* Test activePlugin getter/setter
*/
public function testWebappGetSetActivePlugin() {
$webapp = Webapp::getInstance();
$this->assertEqual($webapp->getActivePlugin(), "twitter");
$webapp->setActivePlugin('facebook');
$this->assertEqual($webapp->getActivePlugin(), "facebook");

//make sure another instance reports back the same values
$webapp_two = Webapp::getInstance();
$this->assertEqual($webapp_two->getActivePlugin(), "facebook");
}

/**
* Test registerPlugin when plugin object does not have the right methods available
*/
public function testWebappRegisterPluginWithoutWebappInterfaceImplemented() {
$webapp = Webapp::getInstance();
$webapp->registerPlugin('hellothinktank', "HelloThinkTankPlugin");
$webapp->setActivePlugin('hellothinktank');

$this->expectException( new Exception("The HelloThinkTankPlugin object does not have a getChildTabsUnderPosts method.") );
$webapp->getChildTabsUnderPosts(null);
}
}
14 changes: 7 additions & 7 deletions tests/all_controller_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
require_once $SOURCE_ROOT_PATH.'tests/TestOfTestController.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfTestAuthController.php';

$controllertest = & new GroupTest('Controller tests');
$controllertest->addTestCase(new TestOfPublicTimelineController());
$controllertest->addTestCase(new TestOfPrivateDashboardController());
$controllertest->addTestCase(new TestOfPostController());
$controllertest->addTestCase(new TestOfTestController());
$controllertest->addTestCase(new TestOfTestAuthController());
$controllertest->run( new TextReporter());
$controller_test = & new GroupTest('Controller tests');
$controller_test->addTestCase(new TestOfPublicTimelineController());
$controller_test->addTestCase(new TestOfPrivateDashboardController());
$controller_test->addTestCase(new TestOfPostController());
$controller_test->addTestCase(new TestOfTestController());
$controller_test->addTestCase(new TestOfTestAuthController());
$controller_test->run( new TextReporter());
13 changes: 6 additions & 7 deletions tests/all_frontend_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
require_once $SOURCE_ROOT_PATH.'tests/TestOfPublicTimeline.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfSignIn.php';

$webtest = & new GroupTest('Frontend tests');
$web_tests = & new GroupTest('Frontend tests');

$webtest->addTestCase(new TestOfChangePassword());
$webtest->addTestCase(new TestOfPrivateDashboard());
$webtest->addTestCase(new TestOfPublicTimeline());
$webtest->addTestCase(new TestOfSignIn());
$webtest->run( new TextReporter());
?>
$web_tests->addTestCase(new TestOfChangePassword());
$web_tests->addTestCase(new TestOfPrivateDashboard());
$web_tests->addTestCase(new TestOfPublicTimeline());
$web_tests->addTestCase(new TestOfSignIn());
$web_tests->run( new TextReporter());
45 changes: 24 additions & 21 deletions tests/all_model_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* MODEL TESTS */
require_once $SOURCE_ROOT_PATH.'tests/TestOfConfig.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfCrawler.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfDatabase.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfFollowMySQLDAO.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfInstanceMySQLDAO.php';
Expand All @@ -23,25 +24,27 @@
require_once $SOURCE_ROOT_PATH.'tests/TestOfUtils.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfPDODAO.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfDAOFactory.php';
require_once $SOURCE_ROOT_PATH.'tests/TestOfWebapp.php';

$modeltest = & new GroupTest('Model tests');
$modeltest->addTestCase(new TestOfLogging());
$modeltest->addTestCase(new TestOfPDODAO());
$modeltest->addTestCase(new TestOfDAOFactory());
$modeltest->addTestCase(new TestOfConfig());
$modeltest->addTestCase(new TestOfDatabase());
$modeltest->addTestCase(new TestOfFollowMySQLDAO());
$modeltest->addTestCase(new TestOfInstanceMySQLDAO());
$modeltest->addTestCase(new TestOfLinkMySQLDAO());
$modeltest->addTestCase(new TestOfMySQLDAO());
$modeltest->addTestCase(new TestOfOwnerMySQLDAO());
$modeltest->addTestCase(new TestOfOwnerInstanceDAO());
$modeltest->addTestCase(new TestOfPluginDAO());
$modeltest->addTestCase(new TestOfPluginHook());
$modeltest->addTestCase(new TestOfPostMySQLDAO());
$modeltest->addTestCase(new TestOfPostErrorMySQLDAO());
$modeltest->addTestCase(new TestOfSmartyThinkTank());
$modeltest->addTestCase(new TestOfUserMySQLDAO());
$modeltest->addTestCase(new TestOfUtils());
$modeltest->run( new TextReporter());
?>
$model_tests = & new GroupTest('Model tests');
$model_tests->addTestCase(new TestOfLogger());
$model_tests->addTestCase(new TestOfPDODAO());
$model_tests->addTestCase(new TestOfDAOFactory());
$model_tests->addTestCase(new TestOfConfig());
$model_tests->addTestCase(new TestOfCrawler());
$model_tests->addTestCase(new TestOfDatabase());
$model_tests->addTestCase(new TestOfFollowMySQLDAO());
$model_tests->addTestCase(new TestOfInstanceMySQLDAO());
$model_tests->addTestCase(new TestOfLinkMySQLDAO());
$model_tests->addTestCase(new TestOfMySQLDAO());
$model_tests->addTestCase(new TestOfOwnerMySQLDAO());
$model_tests->addTestCase(new TestOfOwnerInstanceDAO());
$model_tests->addTestCase(new TestOfPluginDAO());
$model_tests->addTestCase(new TestOfPluginHook());
$model_tests->addTestCase(new TestOfPostMySQLDAO());
$model_tests->addTestCase(new TestOfPostErrorMySQLDAO());
$model_tests->addTestCase(new TestOfSmartyThinkTank());
$model_tests->addTestCase(new TestOfUserMySQLDAO());
$model_tests->addTestCase(new TestOfUtils());
$model_tests->addTestCase(new TestOfWebapp());
$model_tests->run( new TextReporter());
Loading

0 comments on commit 21fa1c5

Please sign in to comment.