Skip to content

Commit

Permalink
Activate Foursquare plugin on installation by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani authored and danipena committed Sep 20, 2012
1 parent 1b46f86 commit 330e140
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 45 deletions.
3 changes: 3 additions & 0 deletions extras/scripts/migratedb
Expand Up @@ -51,6 +51,9 @@ VALUES ('Twitter', 'twitter', 'Twitter support', 'Gina Trapani', 'http://thinkup
INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Facebook', 'facebook', 'Facebook support', 'Gina Trapani', 'http://thinkupapp.com', '0.01', '1');
INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Foursquare', 'foursquare', 'Foursquare support', 'Aaron Kalair', 'http://thinkupapp.com', '0.01', '1');
INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Google+', 'googleplus', 'Google+ support', 'Gina Trapani', 'http://thinkupapp.com', '0.01', '1');
Expand Down
20 changes: 10 additions & 10 deletions tests/TestOfPluginMySQLDAO.php
Expand Up @@ -89,7 +89,7 @@ public function testGetInstalledPlugins() {
$this->assertEqual($plugins[7]->folder_name,"twitterrealtime");
}

public function testInsertPugin() {
public function testInsertPlugin() {
// build our data
$builders_array = $this->buildData();
// init our dao
Expand Down Expand Up @@ -147,7 +147,7 @@ public function testInsertPugin() {
$plugin = $this->createPlugin();
$plugin->name = 'has no home page';
$plugin->homepage = null;
$this->assertEqual($dao->insertPlugin($plugin), 8);
$this->assertEqual($dao->insertPlugin($plugin), 9);
$sql = "select * from " . $this->table_prefix . 'plugins where name = "' . $plugin->name . '"';
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch();
Expand All @@ -157,7 +157,7 @@ public function testInsertPugin() {
$plugin = $this->createPlugin(array('is_active' => false));
$plugin->name = 'not active';
$plugin->homepage = null;
$this->assertEqual($dao->insertPlugin($plugin), 9);
$this->assertEqual($dao->insertPlugin($plugin), 10);
$sql = "select * from " . $this->table_prefix . 'plugins where name = "' . $plugin->name . '"';
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch();
Expand Down Expand Up @@ -303,15 +303,15 @@ public function testIsPluginActive() {
$this->assertFalse($dao->isPluginActive(15));
}

public function testGetPluginId() {
public function testGetPluginID() {
// build our data
$builders_array = $this->buildData();
// init our dao
$dao = new PluginMySQLDAO();

$this->assertEqual($dao->getPluginId('twitter'), 1);
$this->assertEqual($dao->getPluginId('idontexist'), null);
$this->assertEqual($dao->getPluginId('testpluginact'), 6);
$this->assertEqual($dao->getPluginId('testpluginact'), 7);
}

public function testGetPluginFolder() {
Expand All @@ -322,7 +322,7 @@ public function testGetPluginFolder() {

$this->assertEqual($dao->getPluginFolder(1), 'twitter');
$this->assertEqual($dao->getPluginFolder(99), null);
$this->assertEqual($dao->getPluginFolder(6), 'testpluginact');
$this->assertEqual($dao->getPluginFolder(7), 'testpluginact');
}

public function testGetAllPlugins() {
Expand All @@ -332,9 +332,9 @@ public function testGetAllPlugins() {
$dao = new PluginMySQLDAO();

$plugins = $dao->getAllPlugins();
$this->assertEqual(count($plugins), 6);
$this->assertEqual($plugins[4]->name, "My Test Plugin");
$this->assertEqual($plugins[4]->folder_name, "testplugin");
$this->assertEqual(count($plugins), 7);
$this->assertEqual($plugins[5]->name, "My Test Plugin");
$this->assertEqual($plugins[5]->folder_name, "testplugin");

// no plugins?
$builders_array = null;
Expand All @@ -348,7 +348,7 @@ public function testGetActivePlugins() {
$dao = new PluginMySQLDAO();
$plugins = $dao->getActivePlugins();

$this->assertEqual(count($plugins), 5);
$this->assertEqual(count($plugins), 6);
$this->assertEqual($plugins[0]->name,"Twitter");
$this->assertEqual($plugins[0]->folder_name,"twitter");

Expand Down
8 changes: 4 additions & 4 deletions tests/TestOfPluginOptionController.php
Expand Up @@ -188,7 +188,7 @@ public function testSavePluginOption() {
$this->assertEqual($json_response->results->inserted->test1, 3);
$this->assertEqual($json_response->results->inserted->test2, 4);

$sql = "select * from " . $this->table_prefix . 'options where namespace = \'plugin_options-5\'';
$sql = "select * from " . $this->table_prefix . 'options where namespace = \'plugin_options-6\'';
$stmt = $this->pdo->query($sql);
$this->assertEqual($stmt->rowCount(), 3);
for($i = 0; $i < 3; $i++) {
Expand Down Expand Up @@ -228,7 +228,7 @@ public function testSavePluginOptionWithWhitespace() {
$this->assertEqual($json_response->results->inserted->test1, 3);
$this->assertEqual($json_response->results->inserted->test2, 4);

$sql = "select * from " . $this->table_prefix . 'options where namespace = \'plugin_options-5\'';
$sql = "select * from " . $this->table_prefix . 'options where namespace = \'plugin_options-6\'';
$stmt = $this->pdo->query($sql);
$this->assertEqual($stmt->rowCount(), 3);
for($i = 0; $i < 3; $i++) {
Expand Down Expand Up @@ -287,7 +287,7 @@ public function testUpdatePluginOption() {
$this->assertEqual($json_response->status, 'success');
$this->assertEqual($json_response->results->updated, 2);

$sql = "select * from " . $this->table_prefix . "options where namespace = 'plugin_options-5'";
$sql = "select * from " . $this->table_prefix . "options where namespace = 'plugin_options-6'";
$stmt = $this->pdo->query($sql);
$this->assertEqual($stmt->rowCount(), 3);
for($i = 0; $i < 3; $i++) {
Expand Down Expand Up @@ -353,7 +353,7 @@ public function testUpdateDeletePluginOption() {
$this->assertEqual($json_response->results->updated, 1);
$this->assertEqual($json_response->results->deleted, 1);

$sql = "select * from " . $this->table_prefix . "options where namespace = 'plugin_options-5'";
$sql = "select * from " . $this->table_prefix . "options where namespace = 'plugin_options-6'";
$stmt = $this->pdo->query($sql);
$this->assertEqual($stmt->rowCount(), 2);
for($i = 1; $i < 3; $i++) {
Expand Down
12 changes: 6 additions & 6 deletions tests/TestOfPluginOptionMySQLDAO.php
Expand Up @@ -131,18 +131,18 @@ public function testOfUpdateOption() {
}

public function testOfGetOptions() {
$plugin_builder1 = FixtureBuilder::build('plugins', array('id'=>'5', 'folder_name'=>'test_plugin',
$plugin_builder1 = FixtureBuilder::build('plugins', array('id'=>'6', 'folder_name'=>'test_plugin',
'is_active'=>1));
$plugin_builder2 = FixtureBuilder::build('plugins', array('id'=>'6', 'folder_name'=>'test_plugin1',
$plugin_builder2 = FixtureBuilder::build('plugins', array('id'=>'7', 'folder_name'=>'test_plugin1',
'is_active'=>1));

# init our dao
$dao = new PluginOptionMySQLDAO();
$builder1 = $this->buildOptions(1, 'test name', 'test option');
$insert_id1 = $builder1->columns[ 'last_insert_id' ];
$builder2 = $this->buildOptions(5, 'test name2', 'test option2');
$builder2 = $this->buildOptions(6, 'test name2', 'test option2');
$insert_id2 = $builder2->columns[ 'last_insert_id' ];
$builder3 = $this->buildOptions(5, 'test name3', 'test option3');
$builder3 = $this->buildOptions(6, 'test name3', 'test option3');
$insert_id3 = $builder3->columns[ 'last_insert_id' ];

// bad plugin id
Expand All @@ -161,10 +161,10 @@ public function testOfGetOptions() {
$this->assertNotNull( $options );
$this->assertEqual(count($options), 2);
$this->assertIsA($options[0], 'PluginOption');
$this->assertEqual($options[0]->plugin_id, 5);
$this->assertEqual($options[0]->plugin_id, 6);
$this->assertEqual($options[0]->id, 3);
$this->assertIsA($options[1], 'PluginOption');
$this->assertEqual($options[1]->plugin_id, 5);
$this->assertEqual($options[1]->plugin_id, 6);
$this->assertEqual($options[1]->id, 4);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfTableStatsMySQLDAO.php
Expand Up @@ -56,14 +56,14 @@ public function testGetCounts() {
if ($table['table'] == $this->table_prefix . 'options') {
$this->assertEqual($table['count'], 1);
} else if ($table['table'] == $this->table_prefix . 'plugins') {
$this->assertEqual($table['count'], 4);
$this->assertEqual($table['count'], 5);
} else {
$this->assertEqual($table['count'], 0);
}
}

// are we sorted by count desc?
$this->assertEqual(4,$counts[0]['count']);
$this->assertEqual(5,$counts[0]['count']);
$this->assertEqual(1,$counts[1]['count']);
$this->assertEqual(0,$counts[2]['count']);
}
Expand Down
7 changes: 5 additions & 2 deletions webapp/install/sql/build-db_mysql.sql
@@ -1,6 +1,6 @@
--
-- ThinkUp Database Creation Script
-- Auto-generated by thinkup/extras/scripts/migratedb script on 2012-09-06
-- Auto-generated by thinkup/extras/scripts/migratedb script on 2012-09-11
--

ALTER DATABASE DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Expand Down Expand Up @@ -517,7 +517,7 @@ CREATE TABLE tu_users (
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Service user details.';


-- Dump completed on 2012-09-06 23:52:08
-- Dump completed on 2012-09-11 17:33:14

--
-- Insert DB Version
Expand All @@ -535,6 +535,9 @@ VALUES ('Twitter', 'twitter', 'Twitter support', 'Gina Trapani', 'http://thinkup
INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Facebook', 'facebook', 'Facebook support', 'Gina Trapani', 'http://thinkupapp.com', '0.01', '1');

INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Foursquare', 'foursquare', 'Foursquare support', 'Aaron Kalair', 'http://thinkupapp.com', '0.01', '1');

INSERT INTO tu_plugins (name , folder_name, description, author, homepage, version, is_active )
VALUES ('Google+', 'googleplus', 'Google+ support', 'Gina Trapani', 'http://thinkupapp.com', '0.01', '1');

Expand Down
20 changes: 14 additions & 6 deletions webapp/plugins/expandurls/tests/TestOfExpandURLsPlugin.php
Expand Up @@ -39,8 +39,16 @@

class TestOfExpandURLsPlugin extends ThinkUpUnitTestCase {

var $plugin_id;

public function setUp() {
parent::setUp();

$sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'expandurls'";
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$this->plugin_id = $data['id'];

$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$crawler_plugin_registrar->registerCrawlerPlugin('ExpandURLsPlugin');
}
Expand Down Expand Up @@ -318,8 +326,8 @@ public function testFlickrCrawl() {
$config = Config::getInstance();

//use fake Flickr API key
$option_builder = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-4',
'option_name' => 'flickr_api_key', 'option_value' => 'dummykey') );
$option_builder = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-'.
$this->plugin_id, 'option_name' => 'flickr_api_key', 'option_value' => 'dummykey') );

$this->simulateLogin('admin@example.com', true);
$crawler_plugin_registrar->runRegisteredPluginsCrawl();
Expand Down Expand Up @@ -535,12 +543,12 @@ public function testBitlyCrawl() {
$config = Config::getInstance();

//use fake Bitly API key
$builders[] = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-4',
'option_name' => 'bitly_api_key', 'option_value' => 'dummykey'));
$builders[] = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-'.
$this->plugin_id, 'option_name' => 'bitly_api_key', 'option_value' => 'dummykey'));

//use fake Bitly login name
$builder[] = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-4',
'option_name' => 'bitly_login', 'option_value' => 'bitly123'));
$builder[] = FixtureBuilder::build('options', array('namespace' => OptionDAO::PLUGIN_OPTIONS . '-'.
$this->plugin_id, 'option_name' => 'bitly_login', 'option_value' => 'bitly123'));

$this->simulateLogin('admin@example.com', true);
$crawler_plugin_registrar->runRegisteredPluginsCrawl();
Expand Down
Expand Up @@ -58,13 +58,11 @@ public function tearDown() {
private function buildController() {
// Create an owner
$builder_owner = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
// Create a plugin (required as foursquare isn't a default plugin)
$builder_plugin = FixtureBuilder::build('plugins', array('name' => 'foursquare',
'folder_name' => 'foursquare', 'is_active' => 1) );
// Set the plugin ID (the id of the last insert to the database (the call above)
$plugin_id = $builder_plugin->columns['last_insert_id'];
// Set the name space to plugin_options-pluginid
$namespace = OptionDAO::PLUGIN_OPTIONS . '-' .$plugin_id;
$sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
// Create the client id option
$builder_plugin_options[] =
FixtureBuilder::build('options',
Expand Down Expand Up @@ -95,11 +93,11 @@ public function getElementById($doc, $id) {
// Insert the plugin options in the database
private function buildPluginOptions() {
$builders = array();
// Create a plugin
$builders[] = FixtureBuilder::build('plugins', array('name' => 'Foursquare', 'folder_name' => 'foursquare',
'is_active' => 1) );
// Set the plugin ID
$namespace = OptionDAO::PLUGIN_OPTIONS . '-' .'5';
$sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'foursquare'";
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
// Create the client id option
$builders[] = FixtureBuilder::build('options', array('namespace' => $namespace,
'option_name' => 'foursquare_client_id', 'option_value' => "test_client_id") );
Expand Down
Expand Up @@ -185,8 +185,11 @@ public function testGetPluginOptions() {

private function buildController() {
$builder_owner = FixtureBuilder::build('owners', array('email' => 'me@example.com', 'user_activated' => 1) );
$plugin_id = 3;
$namespace = OptionDAO::PLUGIN_OPTIONS . '-' .$plugin_id;
// Get plugin ID
$sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'googleplus'";
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
$builder_plugin_options[] =
FixtureBuilder::build('options',
array('namespace' => $namespace, 'option_name' => 'google_plus_client_id',
Expand Down Expand Up @@ -249,10 +252,12 @@ public function testConfigSet() {
}

private function buildPluginOptions() {
$namespace = OptionDAO::PLUGIN_OPTIONS . '-3';
// Get plugin ID
$sql = "select id from " . $this->table_prefix . "plugins where folder_name = 'googleplus'";
$stmt = PluginMySQLDAO::$PDO->query($sql);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$namespace = OptionDAO::PLUGIN_OPTIONS . '-'.$data['id'];
$builders = array();
$builders[] = FixtureBuilder::build('plugins',
array('name' => 'Google+', 'folder_name' => 'googleplus', 'description' => "Google+ plugin") );
$builders[] = FixtureBuilder::build('options',
array('namespace' => $namespace, 'option_name' => 'google_plus_client_id', 'option_value' => "id") );
$builders[] = FixtureBuilder::build('options',
Expand Down

0 comments on commit 330e140

Please sign in to comment.