Skip to content

Commit

Permalink
Issue #412: Consolidated menu call with custom headers; changed Twitt…
Browse files Browse the repository at this point in the history
…er's 'Posts' to 'Tweets', etc
  • Loading branch information
ginatrapani committed Nov 1, 2010
1 parent 72879a6 commit f2b0dff
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 401 deletions.
28 changes: 14 additions & 14 deletions tests/TestOfWebappTabDataset.php → tests/TestOfDataset.php
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/tests/TestOfWebappTabDataset.php
* ThinkUp/tests/TestOfDataset.php
*
* Copyright (c) 2009-2010 Gina Trapani, Mark Wilkie
*
Expand All @@ -25,19 +25,19 @@
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
* Test of WebappTabDataset
* Test of Dataset
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani, Mark Wilkie
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfWebappTabDataset extends ThinkUpUnitTestCase {
class TestOfDataset extends ThinkUpUnitTestCase {

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

/**
Expand All @@ -58,7 +58,7 @@ public function tearDown() {
* Test constructor with allowed DAO name
*/
public function testConstructorAllowedDAO() {
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts');
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts');
$this->assertTrue(isset($dataset));
$this->assertEqual($dataset->dao_name, 'PostDAO');
$this->assertEqual($dataset->dao_method_name, 'getAllPosts');
Expand All @@ -70,7 +70,7 @@ public function testConstructorAllowedDAO() {
* Test constructor with optiona iterator names
*/
public function testConstructorAllowedDAOSearchIterators() {
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(), 'getAllPostsByUsernameIterator');
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(), 'getAllPostsByUsernameIterator');
$this->assertTrue(isset($dataset));
$this->assertEqual($dataset->dao_name, 'PostDAO');
$this->assertEqual($dataset->dao_method_name, 'getAllPosts');
Expand All @@ -86,14 +86,14 @@ public function testConstructorAllowedDAOSearchIterators() {
*/
public function testConstructorDisallowedDAO() {
$this->expectException(new Exception('BadDAO is not one of the allowed DAOs'));
$dataset = new WebappTabDataset('all-posts', 'BadDAO', 'getAllPosts');
$dataset = new Dataset('all-posts', 'BadDAO', 'getAllPosts');
}

/**
* Test retrieveData with an existing method
*/
public function testRetrieveDataMethodExists() {
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15));
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15));
$data = $dataset->retrieveDataset();
$this->assertTrue(isset($data));
$this->assertIsA($data, 'array');
Expand All @@ -106,7 +106,7 @@ public function testRetrieveIteratorMethodExists() {
$build_data = $this->buildData();

// getAllPostsByUsernameIterator
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
'getAllPostsByUsernameIterator', array('someuser2', 'twitter', 10) );
$iterator = $dataset->retrieveIterator();
$this->assertTrue(isset($iterator));
Expand All @@ -118,7 +118,7 @@ public function testRetrieveIteratorMethodExists() {
$this->assertEqual(2, $cnt, 'count should be 2');

// getAllPostsByUsernameIterator with a limit of 1
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
'getAllPostsByUsernameIterator', array('someuser2', 'twitter', 1) );
$iterator = $dataset->retrieveIterator();
$this->assertTrue(isset($iterator));
Expand All @@ -130,7 +130,7 @@ public function testRetrieveIteratorMethodExists() {
$this->assertEqual(1, $cnt, 'count should be 1');

// getAllMentionsIterator
$dataset = new WebappTabDataset('tweets-mostreplies', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
$dataset = new Dataset('tweets-mostreplies', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15),
'getAllMentionsIterator', array('someuser1', 10, 'twitter') );
$iterator = $dataset->retrieveIterator();
$this->assertTrue(isset($iterator));
Expand All @@ -146,9 +146,9 @@ public function testRetrieveIteratorMethodExists() {
* Test retrieveData with an existing method AND page number
*/
public function testRetrieveDataMethodExistsWithPage() {
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15,
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15,
'#page_number#'));
// $dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15));
// $dataset = new Dataset('all-posts', 'PostDAO', 'getAllPosts', array(930061, 'twitter', 15));
$data = $dataset->retrieveDataset();
$this->assertTrue(isset($data));
$this->assertIsA($data, 'array');
Expand All @@ -158,7 +158,7 @@ public function testRetrieveDataMethodExistsWithPage() {
* Test retrieveData with a non-existing method
*/
public function testRetrieveDataMethodDoesNotExist() {
$dataset = new WebappTabDataset('all-posts', 'PostDAO', 'getAllPostsIDontExist', array(930061, 'twitter', 15));
$dataset = new Dataset('all-posts', 'PostDAO', 'getAllPostsIDontExist', array(930061, 'twitter', 15));
$this->expectException(new Exception('PostDAO does not have a getAllPostsIDontExist method.'));
$data = $dataset->retrieveDataset();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/TestOfWebappTab.php → tests/TestOfMenuItem.php
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/tests/TestOfWebappTab.php
* ThinkUp/tests/TestOfMenuItem.php
*
* Copyright (c) 2009-2010 Gina Trapani
*
Expand All @@ -25,19 +25,19 @@
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
* Test of WebappTab
* Test of MenuItem
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class TestOfWebappTab extends ThinkUpBasicUnitTestCase {
class TestOfMenuItem extends ThinkUpBasicUnitTestCase {

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

/**
Expand All @@ -58,7 +58,7 @@ public function tearDown() {
* Test constructor
*/
public function testConstructor() {
$tab = new WebappTab('my_short_name', "Name of My Tab");
$tab = new MenuItem('my_short_name', "Name of My Tab");
$this->assertEqual($tab->short_name, 'my_short_name');
$this->assertEqual($tab->name, 'Name of My Tab');
$this->assertEqual($tab->description, '');
Expand Down
38 changes: 20 additions & 18 deletions tests/TestOfWebapp.php
Expand Up @@ -19,6 +19,13 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* Test Webapp object
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
Expand All @@ -27,33 +34,27 @@
require_once THINKUP_ROOT_PATH.'webapp/plugins/hellothinkup/model/class.HelloThinkUpPlugin.php';
require_once THINKUP_ROOT_PATH.'webapp/plugins/twitter/model/class.TwitterPlugin.php';

/**
* Test Webapp object
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/

class TestOfWebapp extends ThinkUpBasicUnitTestCase {

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

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

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

Expand Down Expand Up @@ -89,14 +90,14 @@ public function testWebappRegisterPluginWithoutWebappInterfaceImplemented() {
$webapp->setActivePlugin('hellothinkup');

$this->expectException( new Exception(
"The HelloThinkUpPlugin object does not have a getChildTabsUnderPosts method.") );
$webapp->getChildTabsUnderPosts(null);
"The HelloThinkUpPlugin object does not have a getDashboardMenu method.") );
$webapp->getDashboardMenu(null);
}

/**
* Test getTab
* Test getMenuItem
*/
public function testGetTab() {
public function testGetMenuItem() {
$webapp = Webapp::getInstance();
$config = Config::getInstance();
$webapp->registerPlugin('twitter', "TwitterPlugin");
Expand All @@ -105,16 +106,17 @@ public function testGetTab() {
$instance = new Instance();
$instance->network_user_id = 930061;

$tab = $webapp->getTab('tweets-all', $instance);
$this->assertIsA($tab, 'WebappTab');
$this->assertEqual($tab->view_template, Utils::getPluginViewDirectory('twitter').'twitter.inline.view.tpl', "Template ");
$tab = $webapp->getMenuItem('tweets-all', $instance);
$this->assertIsA($tab, 'MenuItem');
$this->assertEqual($tab->view_template, Utils::getPluginViewDirectory('twitter').'twitter.inline.view.tpl',
"Template ");
$this->assertEqual($tab->short_name, 'tweets-all', "Short name");
$this->assertEqual($tab->name, 'All Tweets', "Name");
$this->assertEqual($tab->description, 'All tweets', "Description");
$this->assertIsA($tab->datasets, 'array');
$this->assertEqual(sizeOf($tab->datasets), 1);

$tab = $webapp->getTab('nonexistent', $instance);
$tab = $webapp->getMenuItem('nonexistent', $instance);
$this->assertEqual($tab, null);
}
}
4 changes: 2 additions & 2 deletions tests/all_model_tests.php
Expand Up @@ -60,8 +60,8 @@
$model_tests->addTestCase(new TestOfUserErrorMySQLDAO());
$model_tests->addTestCase(new TestOfUtils());
$model_tests->addTestCase(new TestOfWebapp());
$model_tests->addTestCase(new TestOfWebappTab());
$model_tests->addTestCase(new TestOfWebappTabDataset());
$model_tests->addTestCase(new TestOfMenuItem());
$model_tests->addTestCase(new TestOfDataset());
$model_tests->addTestCase(new TestOfPostIterator());
$model_tests->addTestCase(new TestOfMutexMySQLDAO());
$model_tests->run( new TextReporter());
43 changes: 3 additions & 40 deletions webapp/_lib/controller/class.DashboardController.php
Expand Up @@ -51,7 +51,8 @@ public function control() {
$webapp = Webapp::getInstance();
if (isset($this->instance)) {
$webapp->setActivePlugin($this->instance->network);
$this->loadSidebarMenu();
$sidebar_menu = $webapp->getDashboardMenu($this->instance);
$this->addToView('sidebar_menu', $sidebar_menu);
$this->loadView();
} else {
if (!Session::isLoggedIn()) {
Expand All @@ -68,44 +69,6 @@ public function control() {
return $this->generateView();
}


private function loadSidebarMenu() {
$webapp = Webapp::getInstance();
$tabs = $webapp->getChildTabsUnderPosts($this->instance);
$tabs_array = array();
foreach ($tabs as $tab) {
$tabs_array[$tab->short_name] = $tab->name;
}
$this->addToView("sidebar_menu_posts", $tabs_array);

$tabs = $webapp->getChildTabsUnderReplies($this->instance);
$tabs_array = array();
foreach ($tabs as $tab) {
$tabs_array[$tab->short_name] = $tab->name;
}
$this->addToView("sidebar_menu_replies", $tabs_array);

$tabs = $webapp->getChildTabsUnderFriends($this->instance);
$tabs_array = array();
foreach ($tabs as $tab) {
$tabs_array[$tab->short_name] = $tab->name;
}
$this->addToView("sidebar_menu_friends", $tabs_array);

$tabs = $webapp->getChildTabsUnderFollowers($this->instance);
$tabs_array = array();
foreach ($tabs as $tab) {
$tabs_array[$tab->short_name] = $tab->name;
}
$this->addToView("sidebar_menu_followers", $tabs_array);

$tabs = $webapp->getChildTabsUnderLinks($this->instance);
$tabs_array = array();
foreach ($tabs as $tab) {
$tabs_array[$tab->short_name] = $tab->name;
}
$this->addToView("sidebar_menu_links", $tabs_array);
}
/**
* Load the view with required variables
*/
Expand All @@ -114,7 +77,7 @@ private function loadView() {
if ($this->view_name == 'default') {
$this->loadDefaultDashboard();
} else {
$tab = $webapp->getTab($this->view_name, $this->instance);
$tab = $webapp->getMenuItem($this->view_name, $this->instance);
$this->addToView('data_template', $tab->view_template);
$this->addToView('display', $tab->short_name);
$this->addToView('header', $tab->name);
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.GridController.php
Expand Up @@ -104,7 +104,7 @@ public function authControl() {
} else {
$webapp = Webapp::getInstance();
$webapp->setActivePlugin($instance->network);
$tab = $webapp->getTab($_GET['d'], $instance);
$tab = $webapp->getMenuItem($_GET['d'], $instance);
$posts_it = $tab->datasets[0]->retrieveIterator();
}
echo '{"status":"success","posts": [' . "\n";
Expand Down
3 changes: 2 additions & 1 deletion webapp/_lib/model/class.Crawler.php
Expand Up @@ -105,7 +105,8 @@ public function crawl() {

/**
* Register crawler plugin.
* @param str $object_name Name of Crawler plugin object which instantiates the Crawler interface, like "TwitterPlugin"
* @param str $object_name Name of Crawler plugin object which instantiates the Crawler interface, like
* "TwitterPlugin"
*/
public function registerCrawlerPlugin($object_name) {
$this->registerObjectMethod('crawl', $object_name, 'crawl');
Expand Down
@@ -1,7 +1,7 @@
<?php
/**
*
* ThinkUp/webapp/_lib/model/class.WebappTabDataset.php
* ThinkUp/webapp/_lib/model/class.Dataset.php
*
* Copyright (c) 2009-2010 Gina Trapani
*
Expand All @@ -21,13 +21,14 @@
* <http://www.gnu.org/licenses/>.
*
*
* Webapp Tab Dataset
* Dataset
* Parameters needed to retrieve a set of data to display in ThinkUp.
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2010 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
class WebappTabDataset {
class Dataset {
/**
* @var str
*/
Expand Down Expand Up @@ -68,7 +69,7 @@ class WebappTabDataset {
* @param str $dao_name
* @param str $dao_method_name
* @param array $method_params
* @return WebappTabDataset
* @return Dataset
*/
public function __construct($name, $dao_name, $dao_method_name, $method_params=array(),
$iterator_method_name = null, $iterator_method_params = array()) {
Expand Down

0 comments on commit f2b0dff

Please sign in to comment.