[pLog-svn] r4026 - plog/branches/lifetype-1.1.1/class/test/helpers

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Sep 23 10:47:04 GMT 2006


Author: oscar
Date: 2006-09-23 10:47:03 +0000 (Sat, 23 Sep 2006)
New Revision: 4026

Added:
   plog/branches/lifetype-1.1.1/class/test/helpers/testtools.class.php
Log:
added a new class with a few useful methods for test cases, such as creating and deleting test data


Added: plog/branches/lifetype-1.1.1/class/test/helpers/testtools.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/test/helpers/testtools.class.php	2006-09-23 10:14:05 UTC (rev 4025)
+++ plog/branches/lifetype-1.1.1/class/test/helpers/testtools.class.php	2006-09-23 10:47:03 UTC (rev 4026)
@@ -0,0 +1,150 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );		
+	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );		
+	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );	
+	include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+	include_once( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );		
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Several used methods that are used throughout the test cases
+	 */
+	class TestTools
+	{
+		/** 
+		 * Creates a temporary blog
+		 *
+		 * @param ownerId Id of the owner
+		 * @return A BlogInfo object if successful or false otherwise
+		 */
+		function createBlog( $ownerId )
+		{
+			$blog = new BlogInfo(
+				"Test blog ".md5(time()),
+				$ownerId,
+				"About test blog",
+				""
+			);
+			
+			$blogs = new Blogs();
+			if( $blogs->addBlog( $blog ))
+				return $blog;
+			else
+				return false;
+		}
+		
+		/**
+		 * Creates a temporary user
+		 *
+		 * @return A UserInfo object if successful or false otherwise
+		 */
+		function createUser()
+		{
+			$user = new UserInfo(
+				md5(time()),
+				"password",
+				"test at user.com",
+				"About test user",
+				"Test User"				
+			);
+			
+			$users = new Users();
+			if( $users->addUser( $user ))
+				return( $user );
+			else
+				return( false );
+		}
+		
+		/**
+		 * Create a temporary article
+		 *
+		 * @param blogId Id of the blog to which this article belongs
+		 * @param categories An array with category ids
+		 * @param status A valid status for the article, POST_STATUS_PUBLISHED if none specified
+		 * @param date A Timestamp, the current date will be used if none specified
+		 * @return An Article object if successful or false otherwise
+		 */
+		function createArticle( $blogId, $userId, $categoryIds, $status = POST_STATUS_PUBLISHED, $date = null )
+		{
+			$article = new Article(
+				"Topic of test article",
+				"Text of test article",
+				$categoryIds,
+				$userId,
+				$blogId,
+				$status,
+				0				
+			);
+			if( $date != null ) {
+				$article->setDateObject( $date );
+			}
+			
+			$articles = new Articles();
+			if( $articles->addArticle( $article ))
+				return( $article );
+			else
+				return( false );
+		}
+		
+		/**
+		 * Create a temporary article category
+		 *
+		 * @param blogId 
+		 * @return An ArticleCategory object or false otherwise
+		 */
+		function createArticleCategory( $blogId )
+		{
+			$cat = new ArticleCategory(
+				"Test category ".md5(time()),
+				"",
+				$blogId,
+				true
+			);
+			
+			$cats = new ArticleCategories();
+			if( $cats->addArticleCategory( $cat )) 
+				return( $cat );
+			else
+				return( false );
+		}
+		
+		/**
+		 * Deletes any test data created
+		 *
+		 * @param data An array with DAO objects
+		 */
+		function deleteDaoTestData( $data )
+		{
+			foreach( $data as $item ) {
+				// check the item class and act accordingly
+				$className = strtolower( get_class( $item ));
+				if( $className == "article" ) {
+					$articles = new Articles();
+					$articles->deleteArticle( $item->getId(), $item->getUserId(), $item->getBlogId(), true );
+				}
+				elseif( $className == "bloginfo" ) {
+					$blogs = new Blogs();
+					$blogs->deleteBlog( $item->getId());
+				}
+				elseif( $className == "articlecategory" ) {
+					$cats = new ArticleCategories();
+					$cats->deleteCategory( $item->getId(), $item->getBlogId());
+				}
+				elseif( $className == "userinfo" ) {
+					$users = new Users();
+					$users->deleteUser( $item->getId());
+				}
+				else {
+					print("Unrecognized object of class $className" );
+					print_r( $item );
+					die();
+				}
+			}
+		}
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list