Esempio n. 1
0
 public function tearDown()
 {
     parent::tearDown();
     //clear doesOwnerHaveAccessToPost query cache
     OwnerInstanceMySQLDAO::$post_access_query_cache = array();
 }
 public function testDoesOwnerHaveAccessToPost()
 {
     $oi_data = array('owner_id' => 2, 'instance_id' => 20);
     $oinstances_builder = FixtureBuilder::build(self::TEST_TABLE_OI, $oi_data);
     $i_data = array('id' => 20, 'network_username' => 'mojojojo', 'network_user_id' => '10', 'network' => 'twitter');
     $instances_builder = FixtureBuilder::build(self::TEST_TABLE_I, $i_data);
     $dao = new OwnerInstanceMySQLDAO();
     $post = new Post(array('id' => 1, 'author_user_id' => '20', 'author_username' => 'no one', 'author_fullname' => "No One", 'author_avatar' => 'yo.jpg', 'source' => 'TweetDeck', 'pub_date' => '', 'adj_pub_date' => '', 'in_reply_to_user_id' => '', 'in_reply_to_post_id' => '', 'reply_count_cache' => '', 'in_retweet_of_post_id' => '', 'retweet_count_cache' => '', 'retweet_count_api' => '', 'old_retweet_count_cache' => '', 'in_rt_of_user_id' => '', 'post_id' => '9021481076', 'is_protected' => 1, 'place_id' => 'ece7b97d252718cc', 'favlike_count_cache' => 0, 'post_text' => 'I like cookies', 'network' => 'twitter', 'geo' => '', 'place' => '', 'location' => '', 'is_geo_encoded' => 0, 'is_reply_by_friend' => 0, 'is_retweet_by_friend' => 0, 'reply_retweet_distance' => 0));
     // no owner id
     try {
         $dao->doesOwnerHaveAccessToPost(new Owner(), $post);
         $this->fail("should throw BadArgumentException");
     } catch (BadArgumentException $e) {
         $this->assertPattern('/requires an/', $e->getMessage());
     }
     // no match
     $owner = new Owner();
     $owner->id = 1;
     //public post and owner not admin
     $post->is_protected = false;
     $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post));
     //protected post and owner not admin
     $post->is_protected = true;
     $this->assertFalse($dao->doesOwnerHaveAccessToPost($owner, $post));
     // should have empty cache arrays
     $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['1-twitter-network_id_cache']), 0);
     $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache']), 0);
     //protected post but owner is admin
     $owner->is_admin = true;
     $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post));
     //protected post, owner is not admin, and owner doesn't have an authed instance which follows author
     $owner->is_admin = false;
     $this->assertFalse($dao->doesOwnerHaveAccessToPost($owner, $post));
     //protected post, owner is not admin, and owner DOES have an authed instance which follows author
     OwnerInstanceMySQLDAO::$post_access_query_cache = array();
     // clear cache
     $owner->id = 2;
     $follows_builder = FixtureBuilder::build('follows', array('user_id' => '20', 'follower_id' => '10', 'network' => 'twitter'));
     $this->assertTrue($dao->doesOwnerHaveAccessToPost($owner, $post));
     // should have populated cache arrays
     $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['2-twitter-network_id_cache']), 1);
     $this->assertEqual(count(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache']), 1);
     $this->assertEqual(OwnerInstanceMySQLDAO::$post_access_query_cache['2-twitter-network_id_cache'][0]['network_user_id'], 10);
     $this->assertEqual(OwnerInstanceMySQLDAO::$post_access_query_cache['20-twitter-follower_id_cache'][0]['follower_id'], 10);
 }