Skip to content

Commit

Permalink
Reorganize file structure and clarify naming
Browse files Browse the repository at this point in the history
* Move non-model objects outside of model folder
* Move exceptions folder up one level to reduce complexity
* Rename PluginHook and its extending classes to PluginRegistrar for clarity
* Remove ThinkUp from class names: mv ThinkUpPlugin to GenericPlugin and SmartyThinkUp to ViewManager
* Clarify crawler registrar crawl function name, renamed to runRegisteredPluginsCrawl to differentiate from plugins' crawl function
* Rename InsightsGenerator to DashboardModuleCacher to differentiate from Insights plugin
* Modify makeplugin dev script to reflect changes

This refactor is in preparatory groundwork for making insights pluggable
  • Loading branch information
ginatrapani committed Aug 14, 2012
1 parent d3328a4 commit 6225836
Show file tree
Hide file tree
Showing 115 changed files with 427 additions and 438 deletions.
2 changes: 1 addition & 1 deletion extras/dev/makemodel/classes/class.ModelMaker.php
Expand Up @@ -87,7 +87,7 @@ public function makeModel() {
}

//instantiate Smarty, assign results to view
$view_mgr = new SmartyThinkUp();
$view_mgr = new ViewManager();
$view_mgr->assign('fields', $columns);
$view_mgr->assign('object_name', $this->object_name);
$view_mgr->assign('parent_name', $this->parent_name);
Expand Down
18 changes: 9 additions & 9 deletions extras/dev/makeplugin/makeplugin
Expand Up @@ -218,11 +218,11 @@ cat<< END >>'webapp/plugins/'$plugin_name_lcase'/controller/'$plugin_name_lcase'
* @copyright 2012 (Your Name)
*/
\$webapp = Webapp::getInstance();
\$webapp->registerPlugin('$plugin_name_lcase', '$1Plugin');
\$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
\$webapp_plugin_registrar->registerPlugin('$plugin_name_lcase', '$1Plugin');
\$crawler = Crawler::getInstance();
\$crawler->registerCrawlerPlugin('$1Plugin');
\$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
\$crawler_plugin_registrar->registerCrawlerPlugin('$1Plugin');
END

Expand Down Expand Up @@ -328,9 +328,9 @@ class TestOf$1Plugin extends ThinkUpUnitTestCase {
public function setUp(){
parent::setUp();
\$webapp = Webapp::getInstance();
\$webapp->registerPlugin('$1', '$1Plugin');
\$webapp->setActivePlugin('$1');
\$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
\$webapp_plugin_registrar->registerPlugin('$1', '$1Plugin');
\$webapp_plugin_registrar->setActivePlugin('$1');
}
public function tearDown() {
Expand Down Expand Up @@ -360,8 +360,8 @@ class TestOf$1PluginConfigurationController extends ThinkUpUnitTestCase {
public function setUp(){
parent::setUp();
\$webapp = Webapp::getInstance();
\$webapp->registerPlugin('$1', '$1Plugin');
\$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
\$webapp_plugin_registrar->registerPlugin('$1', '$1Plugin');
\$_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfAccountConfigurationController.php
Expand Up @@ -44,8 +44,8 @@ class TestOfAccountConfigurationController extends ThinkUpUnitTestCase {

public function setUp(){
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
$this->builders = self::buildData();
$_SERVER['HTTP_HOST'] = "mytesthost";
$_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
Expand Down
2 changes: 0 additions & 2 deletions tests/TestOfBackupController.php
Expand Up @@ -33,7 +33,6 @@
}

class TestOfBackupController extends ThinkUpUnitTestCase {

public function setUp() {
parent::setUp();
new BackupMySQLDAO();
Expand Down Expand Up @@ -139,7 +138,6 @@ public function testBackup() {
$controller->go();
$results = ob_get_contents();
ob_end_clean();

// write downloaded zip file to disk...
$fh = fopen($this->backup_test, 'wb');
fwrite($fh, $results);
Expand Down
50 changes: 25 additions & 25 deletions tests/TestOfCrawler.php
Expand Up @@ -45,54 +45,54 @@ public function tearDown() {
* Test Crawler singleton instantiation
*/
public function testCrawlerSingleton() {
$crawler = Crawler::getInstance();
$this->assertTrue(isset($crawler));
$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$this->assertTrue(isset($crawler_plugin_registrar));
//clean copy of crawler, no registered plugins, will throw exception
$this->expectException( new PluginNotFoundException("hellothinkup") );
$this->assertEqual($crawler->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
$this->assertEqual($crawler_plugin_registrar->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
//register a plugin
$crawler->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$this->assertEqual($crawler->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
$crawler_plugin_registrar->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$this->assertEqual($crawler_plugin_registrar->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");

//make sure singleton still has those values
$crawler_two = Crawler::getInstance();
$this->assertEqual($crawler->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
$crawler_plugin_registrar_two = PluginRegistrarCrawler::getInstance();
$this->assertEqual($crawler_plugin_registrar->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
}

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

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

$crawler->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler->registerCrawlerPlugin('HelloThinkUpPlugin');
$this->assertEqual($crawler->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");
$crawler_plugin_registrar->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler_plugin_registrar->registerCrawlerPlugin('HelloThinkUpPlugin');
$this->assertEqual($crawler_plugin_registrar->getPluginObject("hellothinkup"), "HelloThinkUpPlugin");

$builders = $this->buildData();
$this->simulateLogin('admin@example.com', true);
$crawler->crawl();
$crawler_plugin_registrar->runRegisteredPluginsCrawl();

$this->simulateLogin('me@example.com');
$crawler->crawl();
$crawler_plugin_registrar->runRegisteredPluginsCrawl();

Session::logout();
$this->expectException(new UnauthorizedUserException('You need a valid session to launch the crawler.'));
$crawler->crawl();
$crawler_plugin_registrar->runRegisteredPluginsCrawl();
}

public function testCrawlUnauthorized() {
$builders = $this->buildData();
$crawler = Crawler::getInstance();
$crawler->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler->registerCrawlerPlugin('HelloThinkUpPlugin');
$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$crawler_plugin_registrar->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler_plugin_registrar->registerCrawlerPlugin('HelloThinkUpPlugin');
$this->expectException(new UnauthorizedUserException('You need a valid session to launch the crawler.'));
$crawler->crawl();
$crawler_plugin_registrar->runRegisteredPluginsCrawl();
}

public function testCrawlUpgrading() {
Expand All @@ -102,13 +102,13 @@ public function testCrawlUpgrading() {
$config->setValue('THINKUP_VERSION', $config->getValue('THINKUP_VERSION') + 10); //set a high version num

$builders = $this->buildData();
$crawler = Crawler::getInstance();
$crawler->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler->registerCrawlerPlugin('HelloThinkUpPlugin');
$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$crawler_plugin_registrar->registerPlugin('hellothinkup', 'HelloThinkUpPlugin');
$crawler_plugin_registrar->registerCrawlerPlugin('HelloThinkUpPlugin');
$this->simulateLogin('admin@example.com', true);
$this->expectException(
new InstallerException('ThinkUp needs a database migration, so we are unable to run the crawler.'));
$crawler->crawl();
$crawler_plugin_registrar->runRegisteredPluginsCrawl();
// reset version
$config->setValue('THINKUP_VERSION', $init_db_version);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TestOfDashboardController.php
Expand Up @@ -37,10 +37,10 @@ class TestOfDashboardController extends ThinkUpUnitTestCase {

public function setUp(){
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp->registerPlugin('facebook', 'FacebookPlugin');
$webapp->registerPlugin('google+', 'GooglePlusPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
$webapp_plugin_registrar->registerPlugin('facebook', 'FacebookPlugin');
$webapp_plugin_registrar->registerPlugin('google+', 'GooglePlusPlugin');
}

public function testConstructor() {
Expand Down
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/tests/TestOfInsightsGenerator.php
* ThinkUp/tests/TestOfDashboardModuleCacher.php
*
* Copyright (c) 2012 Gina Trapani
*
Expand Down Expand Up @@ -30,7 +30,7 @@
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';

class TestOfInsightsGenerator extends ThinkUpUnitTestCase {
class TestOfDashboardModuleCacher extends ThinkUpUnitTestCase {
public function setUp() {
parent::setUp();
}
Expand All @@ -54,7 +54,7 @@ public function testGetHotPostVisualizationData() {
)
);

$result = InsightsGenerator::getHotPostVisualizationData($hot_posts, 'twitter');
$result = DashboardModuleCacher::getHotPostVisualizationData($hot_posts, 'twitter');
$this->assertEqual(gettype($result), 'string');

$visualization_object = json_decode($result);
Expand All @@ -71,7 +71,7 @@ public function testGetHotPostVisualizationData() {
$this->assertEqual($visualization_object->rows[0]->c[2]->v, 2);
$this->assertEqual($visualization_object->rows[0]->c[3]->v, 1);

$result = InsightsGenerator::getHotPostVisualizationData($hot_posts, 'facebook');
$result = DashboardModuleCacher::getHotPostVisualizationData($hot_posts, 'facebook');
$this->assertEqual(gettype($result), 'string');

$visualization_object = json_decode($result);
Expand All @@ -95,7 +95,7 @@ public function testGetClientVisualizationData() {
'Client 2' => 10,
);

$result = InsightsGenerator::getClientUsageVisualizationData($client_data);
$result = DashboardModuleCacher::getClientUsageVisualizationData($client_data);
$this->assertEqual(gettype($result), 'string');

$visualization_object = json_decode($result);
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testGetClickStatsVisualizationData() {
'click_count' => 23),
);

$result = InsightsGenerator::getClickStatsVisualizationData($click_stats);
$result = DashboardModuleCacher::getClickStatsVisualizationData($click_stats);
$this->assertEqual(gettype($result), 'string');

$visualization_object = json_decode($result);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfGridController.php
Expand Up @@ -35,8 +35,8 @@ class TestOfGridController extends ThinkUpUnitTestCase {

public function setUp(){
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
}

public function tearDown() {
Expand Down
17 changes: 11 additions & 6 deletions tests/TestOfLoader.php
Expand Up @@ -48,9 +48,10 @@ public function testLoaderRegisterDefault() {

// check default lookup path without additionalPath
$this->assertEqual( Loader::getLookupPath(), array(
THINKUP_WEBAPP_PATH . '_lib/',
THINKUP_WEBAPP_PATH . '_lib/model/',
THINKUP_WEBAPP_PATH . '_lib/controller/',
THINKUP_WEBAPP_PATH . '_lib/model/exceptions/'
THINKUP_WEBAPP_PATH . '_lib/exceptions/'
));

// check special classes
Expand All @@ -67,9 +68,10 @@ public function testLoaderRegisterWithStringAdditionalPath() {

// check lookup path with single additionalPath
$this->assertEqual( Loader::getLookupPath(), array(
THINKUP_WEBAPP_PATH . '_lib/',
THINKUP_WEBAPP_PATH . '_lib/model/',
THINKUP_WEBAPP_PATH . '_lib/controller/',
THINKUP_WEBAPP_PATH . '_lib/model/exceptions/',
THINKUP_WEBAPP_PATH . '_lib/exceptions/',
THINKUP_ROOT_PATH . 'tests/classes'
));
}
Expand All @@ -86,9 +88,10 @@ public function testLoaderRegisterWithArrayAdditionalPaths() {

// check lookup path with array additionalPath
$this->assertEqual( Loader::getLookupPath(), array(
THINKUP_WEBAPP_PATH . '_lib/',
THINKUP_WEBAPP_PATH . '_lib/model/',
THINKUP_WEBAPP_PATH . '_lib/controller/',
THINKUP_WEBAPP_PATH . '_lib/model/exceptions/',
THINKUP_WEBAPP_PATH . '_lib/exceptions/',
THINKUP_ROOT_PATH . 'tests',
THINKUP_ROOT_PATH . 'tests/classes'
));
Expand All @@ -112,7 +115,7 @@ public function testLoaderInstantiateClasses() {
$this->assertClassInstantiates('Instance');
$this->assertClassInstantiates('User');

$this->assertIsA(new Crawler, 'Crawler');
$this->assertIsA(new PluginRegistrarCrawler, 'PluginRegistrarCrawler');
$this->assertIsA(new DAOFactory, 'DAOFactory');

$this->assertIsA(Config::getInstance(), 'Config');
Expand All @@ -122,16 +125,18 @@ public function testLoaderInstantiateClasses() {
public function testAdditionalPathAfterInitialRegister() {
Loader::register();
$this->assertEqual( Loader::getLookupPath(), array(
THINKUP_WEBAPP_PATH . '_lib/',
THINKUP_WEBAPP_PATH . '_lib/model/',
THINKUP_WEBAPP_PATH . '_lib/controller/',
THINKUP_WEBAPP_PATH . '_lib/model/exceptions/',
THINKUP_WEBAPP_PATH . '_lib/exceptions/',
));

Loader::addPath(THINKUP_ROOT_PATH . 'tests/classes');
$this->assertEqual( Loader::getLookupPath(), array(
THINKUP_WEBAPP_PATH . '_lib/',
THINKUP_WEBAPP_PATH . '_lib/model/',
THINKUP_WEBAPP_PATH . '_lib/controller/',
THINKUP_WEBAPP_PATH . '_lib/model/exceptions/',
THINKUP_WEBAPP_PATH . '_lib/exceptions/',
THINKUP_ROOT_PATH . 'tests/classes'
));
}
Expand Down
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/tests/TestOfPluginHook.php
* ThinkUp/tests/TestOfPluginRegistrar.php
*
* Copyright (c) 2009-2012 Gina Trapani
*
Expand All @@ -20,7 +20,7 @@
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
* Test of PluginHook class
* Test of PluginRegistrar class
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2012 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
Expand All @@ -29,7 +29,7 @@
require_once THINKUP_WEBAPP_PATH.'_lib/extlib/simpletest/autorun.php';
require_once THINKUP_WEBAPP_PATH.'config.inc.php';

class TestOfPluginHook extends ThinkUpBasicUnitTestCase {
class TestOfPluginRegistrar extends ThinkUpBasicUnitTestCase {

/**
* Test registerPlugin
Expand Down Expand Up @@ -66,7 +66,7 @@ public function testRegisterPerformAppFunction() {
//register an object without the right method
$test_ph->registerPerformAppFunction('TestFauxPluginOne');
$this->expectException(new
Exception("The TestFauxPluginOne object does not have a performAppFunction method."));
Exception("The TestFauxPluginOne object does not have a performAppFunction function."));
$test_ph->performAppFunction();
}
}
4 changes: 2 additions & 2 deletions tests/TestOfPostController.php
Expand Up @@ -41,8 +41,8 @@
class TestOfPostController extends ThinkUpUnitTestCase {
public function setUp(){
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
$this->config = Config::getInstance();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfRegisterController.php
Expand Up @@ -39,8 +39,8 @@ class TestOfRegisterController extends ThinkUpUnitTestCase {

public function setUp() {
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
}

public function tearDown() {
Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfThreadJSController.php
Expand Up @@ -32,8 +32,8 @@ class TestOfThreadJSController extends ThinkUpUnitTestCase {

public function setUp() {
parent::setUp();
$webapp = Webapp::getInstance();
$webapp->registerPlugin('embedthread', 'EmbedThreadPlugin');
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('embedthread', 'EmbedThreadPlugin');
}

//test plugin not enabled
Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfToggleActivePluginController.php
Expand Up @@ -115,8 +115,8 @@ public function testBothParamsExistentInstanceNoCSRFToken() {
}

public function testBothParamsExistentInstanceDeactivateCallback() {
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', "TwitterPlugin");
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('twitter', "TwitterPlugin");

//set up 2 active Twitter instances
$instance_builder_1 = FixtureBuilder::build('instances', array('network_username'=>'julie',
Expand Down

0 comments on commit 6225836

Please sign in to comment.