コード例 #1
0
 public function testDeleteExistingInstanceNoPrivileges()
 {
     //Not admin without access privs (set error messages)
     $builders = array();
     $builders[] = FixtureBuilder::build('instances', array('id' => 2, 'network_user_id' => 12, 'network_username' => 'tuinstance', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 2, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy'));
     $instance_dao = new InstanceMySQLDAO();
     $owner_instance_dao = new OwnerInstanceMySQLDAO();
     //Should delete the owner instance but leave the instance alone
     $this->simulateLogin('*****@*****.**');
     $_POST['action'] = "delete";
     $_POST["instance_id"] = 2;
     $controller = new AccountConfigurationController(true);
     //before
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertNotNull($owner_instances);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 1);
     //process controller
     $controller->go();
     //instance should NOT be deleted
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     //owner instance should NOT be deleted
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 1);
     $v_mgr = $controller->getViewManager();
     $this->assertNull($v_mgr->getTemplateDataItem('successmsg'));
     $this->assertNotNull($v_mgr->getTemplateDataItem('errormsg'));
     $this->assertEqual($v_mgr->getTemplateDataItem('errormsg'), 'Insufficient privileges.');
 }
コード例 #2
0
 public function testGetByInstance()
 {
     $dao = new OwnerInstanceMySQLDAO();
     $builder1 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 50));
     $builder2 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 51));
     $builder3 = FixtureBuilder::build(self::TEST_TABLE_OI, array('instance_id' => 20, 'owner_id' => 52));
     $owner_instances = $dao->getByInstance(20);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 3);
 }
コード例 #3
0
 public function testDeleteExistingInstanceWithTweetSearchWithPrivilegesWithOtherOwners()
 {
     $this->debug(__METHOD__);
     //Not admin with access privs, with other owners (delete owner instance and NOT instance)
     $builders = array();
     $builders[] = FixtureBuilder::build('instances', array('id' => 2, 'network_user_id' => 12, 'network_username' => 'tuinstance', 'network' => 'twitter'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 1, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy'));
     $builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => 2, 'instance_id' => 2, 'oauth_access_token' => 'xxx', 'oauth_access_token_secret' => 'yyy'));
     $instance_dao = new InstanceMySQLDAO();
     $owner_instance_dao = new OwnerInstanceMySQLDAO();
     $instance_hashtag_dao = new InstanceHashtagMySQLDAO();
     //before builder
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     $instances_hashtags = $instance_hashtag_dao->getByInstance($instance->id);
     $this->assertEqual(sizeof($instances_hashtags), 0);
     $builder = $this->buildHashtagData(2);
     //after builder
     $hashtag_dao = new HashtagMySQLDAO();
     $hashtagpost_dao = new HashtagPostMySQLDAO();
     $hashtags = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     $hashtags = $hashtagpost_dao->getHashtagsForPost(2, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     //instances hashtags should be deleted
     $instances_hashtags = $instance_hashtag_dao->getByInstance(2);
     $this->assertEqual(sizeof($instances_hashtags), 2);
     //hashtag should be deleted
     $hashtag = $hashtag_dao->getHashtagByID(1);
     $this->assertEqual(sizeof($hashtag), 1);
     $hashtag = $hashtag_dao->getHashtagByID(2);
     $this->assertEqual(sizeof($hashtag), 1);
     //Should delete the owner instance but leave the instance alone
     $this->simulateLogin('*****@*****.**', false, true);
     $_POST['action'] = "Delete";
     $_POST["instance_id"] = 2;
     $_POST['csrf_token'] = parent::CSRF_TOKEN;
     $controller = new AccountConfigurationController(true);
     //before
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertNotNull($owner_instances);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 2);
     //process controller
     $controller->go();
     //hashtags posts should be deleted
     $hashtags = $hashtagpost_dao->getHashtagsForPost(1, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     $hashtags = $hashtagpost_dao->getHashtagsForPost(2, 'twitter');
     $this->assertEqual(sizeof($hashtags), 1);
     //instances hashtags should NOT be deleted
     $instances_hashtags = $instance_hashtag_dao->getByInstance(2);
     $this->assertEqual(sizeof($instances_hashtags), 2);
     //hashtag should NOT be deleted
     $hashtag = $hashtag_dao->getHashtagByID(1);
     $this->assertEqual(sizeof($hashtag), 1);
     $hashtag = $hashtag_dao->getHashtagByID(2);
     $this->assertEqual(sizeof($hashtag), 1);
     $this->debug('Still running');
     //instance should NOT be deleted
     $instance = $instance_dao->get(2);
     $this->assertNotNull($instance);
     //just one owner_instance should be deleted
     $owner_instances = $owner_instance_dao->getByInstance(2);
     $this->assertIsA($owner_instances, 'Array');
     $this->assertEqual(sizeof($owner_instances), 1);
     $v_mgr = $controller->getViewManager();
     $success_msgs = $v_mgr->getTemplateDataItem('success_msgs');
     $this->assertNotNull($success_msgs);
     $this->assertEqual($success_msgs['account'], 'Account deleted.');
     $this->assertNull($v_mgr->getTemplateDataItem('error_msg'));
 }