public function testGetUserPostsInRange() { $dao = new PostMySQLDAO(); $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:30:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = false); // test date ordering and time range check $date = strtotime($posts[0]->pub_date); foreach ($posts as $post) { $this->assertEqual($post->author_user_id, 18); $this->assertTrue(strtotime($post->pub_date) >= strtotime('2006-01-02 00:00:00')); $this->assertTrue(strtotime($post->pub_date) < strtotime('2006-01-02 00:30:59')); $this->assertTrue(strtotime($post->pub_date) <= $date); $date = strtotime($post->pub_date); } // test ascending order $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:30:59', $order_by = "pub_date", $direction = "ASC", $iterator = false, $is_public = false); $date = strtotime($posts[0]->pub_date); foreach ($posts as $post) { $this->assertTrue(strtotime($post->pub_date) >= $date); $date = strtotime($post->pub_date); } // test filter protected posts $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2006-01-02 00:00:00', $until = '2006-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true); foreach ($posts as $post) { $this->assertEqual($post->is_protected, false); } // test range with no posts $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '1970-01-02 00:00:00', $until = '1971-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true); $this->assertEqual(sizeof($posts), 0); // test from greater than until $posts = $dao->getPostsByUserInRange(18, 'twitter', $from = '2008-01-02 00:00:00', $until = '2006-01-02 00:59:59', $order_by = "pub_date", $direction = "DESC", $iterator = false, $is_public = true); $this->assertEqual(sizeof($posts), 0); }