Permalink
Browse files

Issue #48: Converted PostDAO and PostErrorDAO to PDO

* 163 test passes total for TestOfPostMySQLDAO (model passes up from 547 to 675)
  • Loading branch information...
1 parent b190f0d commit 28e5a78ee9e65a727b3704085adab40706f0495d @ginatrapani ginatrapani committed Jun 5, 2010
Showing with 1,939 additions and 1,148 deletions.
  1. +31 −2 tests/TestOfDAOFactory.php
  2. +0 −278 tests/TestOfPostDAO.php
  3. +54 −0 tests/TestOfPostErrorMySQLDAO.php
  4. +745 −0 tests/TestOfPostMySQLDAO.php
  5. +4 −2 tests/all_model_tests.php
  6. +1 −1 webapp/controller/class.PostController.php
  7. +1 −1 webapp/controller/class.PrivateDashboardController.php
  8. +1 −2 webapp/controller/class.PublicTimelineController.php
  9. +1 −1 webapp/inline.view.php
  10. +22 −9 webapp/model/class.DAOFactory.php
  11. +1 −814 webapp/model/class.Post.php
  12. +23 −0 webapp/model/class.PostErrorMySQLDAO.php
  13. +714 −0 webapp/model/class.PostMySQLDAO.php
  14. +272 −0 webapp/model/interface.PostDAO.php
  15. +23 −0 webapp/model/interface.PostErrorDAO.php
  16. +1 −1 webapp/plugins/facebook/model/class.FacebookCrawler.php
  17. +2 −2 webapp/plugins/facebook/model/class.FacebookPlugin.php
  18. +3 −3 webapp/plugins/facebook/tests/TestOfFacebookCrawler.php
  19. +1 −1 webapp/plugins/facebook/tests/TestOfFacebookPlugin.php
  20. +8 −8 webapp/plugins/twitter/model/class.TwitterCrawler.php
  21. +1 −1 webapp/plugins/twitter/model/class.TwitterPlugin.php
  22. +7 −1 webapp/plugins/twitter/tests/TestOfRetweetDetector.php
  23. +13 −8 webapp/plugins/twitter/tests/TestOfTwitterCrawler.php
  24. +1 −1 webapp/plugins/twitter/tests/TestOfTwitterPlugin.php
  25. +1 −1 webapp/post/export.php
  26. +1 −1 webapp/post/mark-parent.php
  27. +1 −1 webapp/user/index.php
  28. +3 −4 webapp/view/plugins/modifier.link_usernames_to_twitter.php
  29. +3 −5 webapp/view/plugins/modifier.tweet_from_id.php
View
@@ -8,9 +8,17 @@
require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankUnitTestCase.php';
// require_once $SOURCE_ROOT_PATH.'tests/classes/class.TestDAO.php';
require_once $SOURCE_ROOT_PATH.'webapp/model/class.DAOFactory.php';
+
+/**
+ * Test of DAOFactory
+ *
+ * @author Mark Wilkie
+ * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
+ *
+ */
class TestOfDAOFactory extends ThinkTankUnitTestCase {
- function TestOfDAOFactory() {
+ function __construct() {
$this->UnitTestCase('DAOFactory test');
}
@@ -91,5 +99,26 @@ function testGetTestDAO() {
$this->assertEqual($data_obj->test_id, 2001);
}
+ /**
+ * Test get InstanceDAO
+ */
+ function getInstanceDAO(){
+ $dao = DAOFactory::getDAO('InstanceDAO');
+ $this->assertTrue(isset($dao));
+ }
-}
+ /**
+ * Test get PostErrorDAO
+ */
+ function getPostErrorDAO(){
+ $dao = DAOFactory::getDAO('PostErrorDAO');
+ $this->assertTrue(isset($dao));
+ }
+ /**
+ * Test get PostDAO
+ */
+ function getPostDAO(){
+ $dao = DAOFactory::getDAO('PostDAO');
+ $this->assertTrue(isset($dao));
+ }
+ }
View
@@ -1,278 +0,0 @@
-<?php
-require_once dirname(__FILE__).'/config.tests.inc.php';
-require_once $SOURCE_ROOT_PATH.'extlib/simpletest/autorun.php';
-require_once $SOURCE_ROOT_PATH.'extlib/simpletest/web_tester.php';
-ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);
-
-require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankUnitTestCase.php';
-require_once $SOURCE_ROOT_PATH.'webapp/model/class.Post.php';
-require_once $SOURCE_ROOT_PATH.'webapp/model/class.Link.php';
-
-class TestOfPostDAO extends ThinkTankUnitTestCase {
- var $logger;
-
- function TestOfPostDAO() {
- $this->UnitTestCase('PostDAO class test');
- }
-
- function setUp() {
- parent::setUp();
- $this->logger = Logger::getInstance();
-
- //TODO: Insert test data into post table
- //$this->db->exec($q);
- //Add instance_owner
- $q = "INSERT INTO tt_owner_instances (owner_id, instance_id) VALUES (1, 1)";
- $this->db->exec($q);
-
- //Insert test data into test table
- $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, last_updated) VALUES (13, 'ev', 'Ev Williams', 'avatar.jpg', '1/1/2005');";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (18, 'shutterbug', 'Shutter Bug', 'avatar.jpg', 0, 10);";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_users (user_id, user_name, full_name, avatar, is_protected, follower_count) VALUES (19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 0, 10);";
- $this->db->exec($q);
-
- //Make public
- $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (13, 'ev', 1);";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (18, 'shutterbug', 1);";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_instances (network_user_id, network_username, is_public) VALUES (19, 'linkbaiter', 1);";
- $this->db->exec($q);
-
- //Add a bunch of posts
- $counter = 0;
- while ($counter < 40) {
- $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ($counter, 13, 'ev', 'Ev Williams', 'avatar.jpg', 'This is post $counter', 'web', '2006-01-01 00:$pseudo_minute:00', ".rand(0, 4).", 5);";
- $this->db->exec($q);
- $counter++;
- }
-
- //Add some photo posts
- $counter = 0;
- while ($counter < 40) {
- $post_id = $counter + 40;
- $pseudo_minute = str_pad($counter, 2, "0", STR_PAD_LEFT);
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ($post_id, 18, 'shutterbug', 'Shutter Bug', 'avatar.jpg', 'This is image post $counter', 'web', '2006-01-02 00:$pseudo_minute:00', 0, 0);";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_links (url, expanded_url, title, clicks, post_id, is_image) VALUES ('http://example.com/".$counter."', 'http://example.com/".$counter.".jpg', '', 0, $post_id, 1);";
- $this->db->exec($q);
-
- $counter++;
- }
-
- //Add some link posts
- $counter = 0;
- while ($counter < 40) {
- $post_id = $counter + 80;
- $pseudo_minute = str_pad(($counter), 2, "0", STR_PAD_LEFT);
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES ($post_id, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is link post $counter', 'web', '2006-03-01 00:$pseudo_minute:00', 0, 0);";
- $this->db->exec($q);
-
- $q = "INSERT INTO tt_links (url, expanded_url, title, clicks, post_id, is_image) VALUES ('http://example.com/".$counter."', 'http://example.com/".$counter.".html', 'Link $counter', 0, $post_id, 0);";
- $this->db->exec($q);
-
- $counter++;
- }
-
- }
-
- function tearDown() {
- parent::tearDown();
- $this->logger->close();
-
- }
-
-
-
- function testGetPageOneOfPublicPosts() {
- //Instantiate DAO
- $pdao = new PostDAO($this->db, $this->logger);
-
- //Get page 1 containing 15 public posts
- $page_of_posts = $pdao->getPostsByPublicInstances(1, 15);
-
- //Assert DAO returns 15 posts
- $this->assertTrue(sizeof($page_of_posts) == 15);
-
- //Assert first post 1 contains the right text
- $this->assertTrue($page_of_posts[0]->post_text == "This is post 39");
-
- //Asert last post 15 contains the right text
- $this->assertTrue($page_of_posts[14]->post_text == "This is post 25");
- }
-
- function testGetPageTwoOfPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getPostsByPublicInstances(2, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 15);
- $this->assertTrue($page_of_posts[0]->post_text == "This is post 24");
- $this->assertTrue($page_of_posts[14]->post_text == "This is post 10");
- }
-
- function testGetPageThreeOfPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getPostsByPublicInstances(3, 15);
-
- //Assert DAO returns 10 posts
- $this->assertTrue(sizeof($page_of_posts) == 10);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is post 9");
- $this->assertTrue($page_of_posts[9]->post_text == "This is post 0");
- }
-
- function testGetTotalPagesAndPostsByPublicInstances() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $totals = $pdao->getTotalPagesAndPostsByPublicInstances(15);
-
- $this->assertTrue($totals["total_posts"] == 40);
- $this->assertTrue($totals["total_pages"] == 3);
- }
-
- //Start Public Photo Tests
- function testGetPageOneOfPhotoPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getPhotoPostsByPublicInstances(1, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 15);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is image post 39");
-
- $this->assertTrue($page_of_posts[14]->post_text == "This is image post 25");
-
- }
-
- function testGetPageTwoOfPhotoPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getPhotoPostsByPublicInstances(2, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 15);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is image post 24");
-
- $this->assertTrue($page_of_posts[14]->post_text == "This is image post 10");
-
- }
-
- function testGetPageThreeOfPhotoPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getPhotoPostsByPublicInstances(3, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 10);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is image post 9");
-
- $this->assertTrue($page_of_posts[9]->post_text == "This is image post 0");
-
- }
-
- function testGetTotalPhotoPagesAndPostsByPublicInstances() {
- $pdao = new PostDAO($this->db, $this->logger);
- $totals = $pdao->getTotalPhotoPagesAndPostsByPublicInstances(15);
-
- $this->assertTrue($totals["total_posts"] == 40);
- $this->assertTrue($totals["total_pages"] == 3);
- }
-
- //Start Public Link Tests
- function testGetPageOneOfLinkPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getLinkPostsByPublicInstances(1, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 15);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is link post 39");
-
- $this->assertTrue($page_of_posts[14]->post_text == "This is link post 25");
-
- }
-
- function testGetPageTwoOfLinkPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getLinkPostsByPublicInstances(2, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 15);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is link post 24");
-
- $this->assertTrue($page_of_posts[14]->post_text == "This is link post 10");
-
- }
-
- function testGetPageThreeOfLinkPublicPosts() {
- $pdao = new PostDAO($this->db, $this->logger);
-
- $page_of_posts = $pdao->getLinkPostsByPublicInstances(3, 15);
-
- $this->assertTrue(sizeof($page_of_posts) == 10);
-
- $this->assertTrue($page_of_posts[0]->post_text == "This is link post 9");
-
- $this->assertTrue($page_of_posts[9]->post_text == "This is link post 0");
-
- }
-
- function testGetTotalLinkPagesAndPostsByPublicInstances() {
- $pdao = new PostDAO($this->db, $this->logger);
- $totals = $pdao->getTotalLinkPagesAndPostsByPublicInstances(15);
-
- $this->assertTrue($totals["total_posts"] == 40);
- $this->assertTrue($totals["total_pages"] == 3);
- }
-
- function testGetTotalPostsByUser() {
- $pdao = new PostDAO($this->db, $this->logger);
- $total_posts = $pdao->getTotalPostsByUser(13);
- $this->assertTrue($total_posts == 40);
- }
-
- function testAssignParent() {
- //Add two "parent" posts
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (550, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 1', 'web', '2006-03-01 00:01:00', 1, 0);";
- $this->db->exec($q);
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache) VALUES (551, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is parent post 2', 'web', '2006-03-01 00:01:00', 0, 0);";
- $this->db->exec($q);
-
- //Add a post with the parent post 550
- $q = "INSERT INTO tt_posts (post_id, author_user_id, author_username, author_fullname, author_avatar, post_text, source, pub_date, mention_count_cache, retweet_count_cache, in_reply_to_post_id) VALUES (552, 19, 'linkbaiter', 'Link Baiter', 'avatar.jpg', 'This is a reply with the wrong parent', 'web', '2006-03-01 00:01:00', 0, 0, 550);";
- $this->db->exec($q);
-
- $pdao = new PostDAO($this->db, $this->logger);
-
- $post = $pdao->getPost(552);
- //Assert parent post is 550
- $this->assertEqual($post->in_reply_to_post_id, 550);
-
- //Change parent post to 551
- $pdao->assignParent(551, 552);
- $child_post = $pdao->getPost(552);
- //Assert parent post is now 551
- $this->assertEqual($child_post->in_reply_to_post_id, 551);
-
- //Assert old parent post has one fewer reply total
- $old_parent = $pdao->getPost(550);
- $this->assertEqual($old_parent->mention_count_cache, 0);
-
- //Assert new parent post has one more reply total
- $new_parent = $pdao->getPost(551);
- $this->assertEqual($new_parent->mention_count_cache, 1);
-
- }
-}
-?>
@@ -0,0 +1,54 @@
+<?php
+require_once dirname(__FILE__).'/config.tests.inc.php';
+ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.$INCLUDE_PATH);
+require_once $SOURCE_ROOT_PATH.'extlib/simpletest/autorun.php';
+require_once $SOURCE_ROOT_PATH.'extlib/simpletest/web_tester.php';
+require_once $SOURCE_ROOT_PATH.'extlib/Loremipsum/LoremIpsum.class.php';
+
+
+require_once $SOURCE_ROOT_PATH.'tests/classes/class.ThinkTankUnitTestCase.php';
+require_once $SOURCE_ROOT_PATH.'webapp/model/class.PDODAO.php';
+require_once $SOURCE_ROOT_PATH.'webapp/model/class.PostErrorMySQLDAO.php';
+require_once $SOURCE_ROOT_PATH.'webapp/model/class.DAOFactory.php';
+
+/**
+ * Test PostErrorMySQLDAO
+ *
+ * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
+ *
+ */
+class TestOfPostErrorMySQLDAO extends ThinkTankUnitTestCase {
+
+ function _construct() {
+ $this->UnitTestCase('PostErrorMySQLDAO class test');
+ }
+
+ function setUp() {
+ parent::setUp();
+ }
+
+ function tearDown() {
+ parent::tearDown();
+ }
+
+ /**
+ * Test constructor
+ */
+ function testConstructor(){
+ $dao = new PostErrorMySQLDAO();
+ $this->assertTrue(isset($dao));
+
+ }
+
+ /**
+ * Test error insertion
+ */
+ function testInsert() {
+ $dao = new PostErrorMySQLDAO();
+ $result = $dao->insertError(10, 404, 'Status not found', 930061);
+ $this->assertEqual($result, 1);
+
+ $result = $dao->insertError(11, 403, 'You are not autorized to see this status', 930061);
+ $this->assertEqual($result, 2);
+ }
+}
Oops, something went wrong.

0 comments on commit 28e5a78

Please sign in to comment.