[pLog-svn] r4189 - plog/branches/lifetype-1.1.2/class/test/helpers

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Oct 26 21:53:58 GMT 2006


Author: oscar
Date: 2006-10-26 21:53:57 +0000 (Thu, 26 Oct 2006)
New Revision: 4189

Modified:
   plog/branches/lifetype-1.1.2/class/test/helpers/testtools.class.php
Log:
added a method to generate a full testing scenario (user, blog, articles and categories)


Modified: plog/branches/lifetype-1.1.2/class/test/helpers/testtools.class.php
===================================================================
--- plog/branches/lifetype-1.1.2/class/test/helpers/testtools.class.php	2006-10-26 07:48:00 UTC (rev 4188)
+++ plog/branches/lifetype-1.1.2/class/test/helpers/testtools.class.php	2006-10-26 21:53:57 UTC (rev 4189)
@@ -114,6 +114,67 @@
 		}
 		
 		/**
+		 * Creates a clean scenario for tests, including one blog, one user, one or more different articles and
+		 * one or more different article categories
+		 *
+		 * @param params An array
+		 * @return Returns an array with several different fields containing the user (owner), blog, categories
+		 * and articles.
+		 */
+		function createBlogScenario( $params = Array())
+		{
+			$numArticles = isset( $params["num_articles"] ) ? $params["num_articles"] : 1;
+			$numCategories = isset( $params["num_categories"] ) ? $params["num_categories"] : 1;
+			
+			// create the user
+			$user = TestTools::createUser();
+			// create the blog
+			$blog = TestTools::createBlog( $user->getId());
+			// create the categories
+			$i = 0;
+			$categories = Array();
+			while( $i < $numCategories ) {
+				$categories[$i] = TestTools::createArticleCategory( $blog->getId());
+				$i++;				
+			}
+			// create the articles
+			$i = 0;
+
+			while( $i < $numArticles ) {
+				// select the categories
+				if( $numCategories == 1 )
+					$catIds = Array( $categories[0]->getId());
+				else {
+					// pick a random number between 1 and $numCategories
+					$maxNum = rand( 1, $numCategories );
+					$j = 0;
+					while( $j < $maxNum ) {
+						$pos = rand( 0, $numCategories-1 );
+						$catIds[] = $categories[$pos]->getId();
+						$j++;
+					}
+				}
+				$articles[$i] = TestTools::createArticle( $blog->getId(), $user->getId(), $catIds, POST_STATUS_PUBLISHED );
+				$i++;
+				$catIds = Array();
+			}
+			
+			$result = Array();
+			$result["user"] = $user;
+			$result["blog"] = $blog;
+			$i = 0;
+			// need to reload the category so that the article counters are correct
+			$articleCategories = new ArticleCategories();
+			foreach( $categories as $cat ) {
+				$result["categories"][$i] = $articleCategories->getCategory( $cat->getId());
+				$i++;				
+			}
+			$result["articles"] = $articles;
+			
+			return( $result );
+		}
+		
+		/**
 		 * Deletes any test data created
 		 *
 		 * @param data An array with DAO objects



More information about the pLog-svn mailing list