[pLog-svn] r6833 - plog/branches/lifetype-1.2/class/test/tests/dao

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Feb 21 17:42:28 EST 2009


Author: jondaley
Date: 2009-02-21 17:42:28 -0500 (Sat, 21 Feb 2009)
New Revision: 6833

Modified:
   plog/branches/lifetype-1.2/class/test/tests/dao/article_test.class.php
   plog/branches/lifetype-1.2/class/test/tests/dao/commentscommon_test.class.php
Log:
testtools stuff is handy for not littering the database with junk

Modified: plog/branches/lifetype-1.2/class/test/tests/dao/article_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/dao/article_test.class.php	2009-02-21 22:42:05 UTC (rev 6832)
+++ plog/branches/lifetype-1.2/class/test/tests/dao/article_test.class.php	2009-02-21 22:42:28 UTC (rev 6833)
@@ -1,8 +1,7 @@
 <?php
 
 	lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
-	lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" );
-	lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/test/helpers/testtools.class.php" );	
 	lt_include( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
 
 	/**
@@ -14,23 +13,19 @@
 	{
 		function setUp()
 		{
-                // 
-                // Note: if you are going to copy this code for another test, note that this code
-                // doesn't ever add this article to the database, since if it did, it could
-                // potentially overwrite your real blog data...
-                //
-                // build a dummy Article object			
-			$this->article = new Article(
-				"dummy topic",
-				"dummy text",
-				Array( 1 ),   // a dummy category
-				Array( 1 ),   // a dummy user
-				1,  // a dummy blog
-				POST_STATUS_PUBLISHED,  // published status
-				0   // not read yet
-			);	
+			// create the scenario
+			$this->user = TestTools::createUser();
+			$this->blog = TestTools::createBlog( $this->user->getId());
+			$this->cat  = TestTools::createArticleCategory( $this->blog->getId());
+			$this->article = TestTools::createArticle( $this->blog->getId(), $this->user->getId(),
+                                                       Array( $this->cat->getId()));
 		}
-		
+
+        function tearDown(){
+			TestTools::deleteDaoTestData(Array($this->article, $this->cat, $this->user));
+			TestTools::deleteBlog( $this->blog );
+        }
+        
 		/** 
 		 * regression test for mantis case 986 (http://bugs.lifetype.net/view.php?id=986)
 		 * and for method Article::hasExtendedText in general

Modified: plog/branches/lifetype-1.2/class/test/tests/dao/commentscommon_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/dao/commentscommon_test.class.php	2009-02-21 22:42:05 UTC (rev 6832)
+++ plog/branches/lifetype-1.2/class/test/tests/dao/commentscommon_test.class.php	2009-02-21 22:42:28 UTC (rev 6833)
@@ -22,36 +22,46 @@
 	 */
 	class CommentsCommon_Test extends LifeTypeTestCase
 	{
+        function setUp(){
+			// create the scenario
+			$this->user = TestTools::createUser();
+			$this->blog = TestTools::createBlog( $this->user->getId());
+			$this->cat  = TestTools::createArticleCategory( $this->blog->getId());
+			$this->article = TestTools::createArticle( $this->blog->getId(), $this->user->getId(),
+                                                       Array( $this->cat->getId()));
+        }
 
+        function tearDown(){
+			// destroy the test data
+			TestTools::deleteDaoTestData(Array($this->article, $this->cat, $this->user));
+			TestTools::deleteBlog($this->blog);
+        }
+
+        
         function testGetNumPostComments()
 		{
 
-			// create the scenario
-			$user = TestTools::createUser();
-			$blog = TestTools::createBlog( $user->getId());
-			$cat  = TestTools::createArticleCategory( $blog->getId());
-			$article = TestTools::createArticle( $blog->getId(), $user->getId(), Array( $cat->getId()));
 
             // Add comments
             $timestamp = new Timestamp();
-            $comment1 = new UserComment($article->getId(),
-                                        $article->getBlogId(),
+            $comment1 = new UserComment($this->article->getId(),
+                                        $this->article->getBlogId(),
                                         0, // dummy parent
                                         "dummy topic",
                                         "dummy text",
                                         $timestamp->getTimestamp());
             
             $timestamp = new Timestamp();
-            $comment2 = new UserComment($article->getId(),
-                                        $article->getBlogId(),
+            $comment2 = new UserComment($this->article->getId(),
+                                        $this->article->getBlogId(),
                                         0, // dummy parent
                                         "dummy topic 2",
                                         "dummy text 2",
                                         $timestamp->getTimestamp());
 
             $timestamp = new Timestamp();
-            $comment3 = new UserComment($article->getId(),
-                                        $article->getBlogId(),
+            $comment3 = new UserComment($this->article->getId(),
+                                        $this->article->getBlogId(),
                                         0, // dummy parent
                                         "dummy topic 2",
                                         "spam",
@@ -67,8 +77,8 @@
             $timestamp = new Timestamp();
             $trackback1 = new Trackback("fake url",
                                         "this is a title",
-                                        $article->getId(),
-                                        $article->getBlogId(),
+                                        $this->article->getId(),
+                                        $this->article->getBlogId(),
                                         "excerpt from my blog",
                                         "my blog name",
                                         $timestamp->getTimestamp(),
@@ -77,8 +87,8 @@
             $timestamp = new Timestamp();
             $trackback2 = new Trackback("fake url 2",
                                         "this is a title",
-                                        $article->getId(),
-                                        $article->getBlogId(),
+                                        $this->article->getId(),
+                                        $this->article->getBlogId(),
                                         "excerpt from my blog",
                                         "my blog name",
                                         $timestamp->getTimestamp(),
@@ -88,8 +98,8 @@
             $timestamp = new Timestamp();
             $trackback3 = new Trackback("fake url 3",
                                         "this is a title",
-                                        $article->getId(),
-                                        $article->getBlogId(),
+                                        $this->article->getId(),
+                                        $this->article->getBlogId(),
                                         "excerpt from my blog",
                                         "my blog name",
                                         $timestamp->getTimestamp(),
@@ -99,8 +109,8 @@
             $timestamp = new Timestamp();
             $trackback4 = new Trackback("fake url 4",
                                         "this is a title",
-                                        $article->getId(),
-                                        $article->getBlogId(),
+                                        $this->article->getId(),
+                                        $this->article->getBlogId(),
                                         "excerpt from my blog",
                                         "my blog name",
                                         $timestamp->getTimestamp(),
@@ -118,33 +128,31 @@
             $this->assertTrue($comments->addComment($trackback3), "Couldn't add test trackback 3");
             $this->assertTrue($comments->addComment($trackback4), "Couldn't add test trackback 4");
             
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_ANY);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_ANY);
             $this->assertTrue($num == 7, "Wrong number of comments/trackbacks (all) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_ANY);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_ANY);
             $this->assertTrue($num == 3, "Wrong number of comments/trackbacks (nonspam) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_ANY);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_ANY);
             $this->assertTrue($num == 4, "Wrong number of comments/trackbacks (spam) ". $num);
 
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_COMMENT);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_COMMENT);
             $this->assertTrue($num == 3, "Wrong number of comments (all) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_COMMENT);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_COMMENT);
             $this->assertTrue($num == 2, "Wrong number of comments (nonspam) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_COMMENT);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_COMMENT);
             $this->assertTrue($num == 1, "Wrong number of comments (spam) ". $num);
 
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_TRACKBACK);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_TRACKBACK);
             $this->assertTrue($num == 4, "Wrong number of trackbacks (all) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_TRACKBACK);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_TRACKBACK);
             $this->assertTrue($num == 1, "Wrong number of trackbacks (nonspam) ". $num);
-            $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_TRACKBACK);
+            $num = $comments->getNumPostComments($this->article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_TRACKBACK);
             $this->assertTrue($num == 3, "Wrong number of trackbacks (spam) ". $num);
 
             
-			// delete the temporary data
-			TestTools::deleteDaoTestData( Array( $comment1, $comment2, $comment3,
-                                                 $trackback1, $trackback2, $trackback3, $trackback4,
-                                                 $article, $cat, $user));
-			TestTools::deleteBlog( $blog );
+                // delete the temporary data
+			TestTools::deleteDaoTestData(Array($comment1, $comment2, $comment3,
+                                               $trackback1, $trackback2, $trackback3, $trackback4));
 		}
 		
 		/**
@@ -154,19 +162,15 @@
 		 */
 		function testUpdateCommentWithTimeOffsets()
 		{
-			// create the scenario
-			$user = TestTools::createUser();
-			$blog = TestTools::createBlog( $user->getId());
-			$cat  = TestTools::createArticleCategory( $blog->getId());
-			$article = TestTools::createArticle( $blog->getId(), $user->getId(), Array( $cat->getId()));
-			
 			// update the time offset settings for the blog
-			$blog->setValue( "time_offset", "+3" );
+			$this->blog->setValue( "time_offset", "+3" );
 			$blogs = new Blogs();
-			$blogs->updateBlog( $blog );
+			$blogs->updateBlog($this->blog);
 			
 			// create the comment and save it to the database
-			$comment = new UserComment( $article->getId(), $blog->getId(), 0, "test comment", "test comment body" );
+			$comment = new UserComment( $this->article->getId(),
+                                        $this->blog->getId(),
+                                        0, "test comment", "test comment body" );
 			$comments = new ArticleComments();
 			$comments->addComment( $comment );
 			
@@ -182,8 +186,7 @@
 			$this->assertEquals( $origTime->getTimestamp(), $newTime->getTimestamp(), "Comment times are not the same!" );
 			
 			// destroy the test data
-			TestTools::deleteDaoTestData( Array( $comment, $comment2, $article, $cat, $user));
-			TestTools::deleteBlog( $blog );
+			TestTools::deleteDaoTestData(Array($comment, $comment2));
 		}
 	}
 ?>



More information about the pLog-svn mailing list