-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #119: Refine plugin architecture
* 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
1 parent
99e5706
commit 21fa1c5
Showing
29 changed files
with
664 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.