[pLog-svn] r4314 - plog/branches/lifetype-1.1.3/class/test/tests/dao
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Thu Nov 16 14:08:24 GMT 2006
Author: jondaley
Date: 2006-11-16 14:08:22 +0000 (Thu, 16 Nov 2006)
New Revision: 4314
Modified:
plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php
Log:
nifty. now it works. (and found another bug)
Modified: plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php
===================================================================
--- plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php 2006-11-16 13:14:33 UTC (rev 4313)
+++ plog/branches/lifetype-1.1.3/class/test/tests/dao/commentscommon_test.class.php 2006-11-16 14:08:22 UTC (rev 4314)
@@ -1,12 +1,18 @@
<?php
include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/trackbacks.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/articles.class.php" );
include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+ include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
/**
* \ingroup Test
@@ -15,52 +21,149 @@
*/
class CommentsCommon_Test extends LifeTypeTestCase
{
- function setUp()
+
+ function testGetNumPostComments()
{
- $this->articles = new Articles();
+ // create a user
+ $users = new Users();
+ $randomName = md5(time());
+ $user = new UserInfo($randomName, "blah", "test at not-a-real-address.net", "", "Full Name");
+ $this->assertTrue($users->addUser($user), "Couldn't add test user");
+
+ // create a blog
+ $blogs = new Blogs();
+ $randomName = md5(time());
+ $blog = new BlogInfo( $randomName, $user->getId(), "About blog random blog", new BlogSettings());
+ $this->assertTrue($blogs->addBlog( $blog ), "Couldn't add test blog");
- // build a dummy Article object -- need a better way to build this, if we are going to add it to the database, so your blog doesn't get messed up.
- $this->article = new Article(
+ // add an article
+ $articles = new Articles();
+ $article = new Article(
"dummy topic",
"dummy text",
- Array( 1 ), // a dummy category
- Array( 1 ), // a dummy user
- 1, // a dummy blog
+ Array( 1 ), // a dummy category (I don't need a category here)
+ $user->getId(), // our user we created above
+ $blog->getId(), // our blog we created above
POST_STATUS_PUBLISHED, // published status
0 // not read yet
);
+ $this->assertTrue($articles->addArticle($article), "Couldn't add test article");
+
+ // Add comments
+ $timestamp = new Timestamp();
+ $comment1 = new UserComment($article->getId(),
+ $article->getBlogId(),
+ 0, // dummy parent
+ "dummy topic",
+ "dummy text",
+ $timestamp->getTimestamp());
$timestamp = new Timestamp();
- $this->comment1 = new UserComment($this->article->getId(),
- $this->article->getBlogId(),
- 0, // dummy parent
- "dummy topic",
- "dummy text",
- $timestamp->getTimestamp());
+ $comment2 = new UserComment($article->getId(),
+ $article->getBlogId(),
+ 0, // dummy parent
+ "dummy topic 2",
+ "dummy text 2",
+ $timestamp->getTimestamp());
+
$timestamp = new Timestamp();
- $this->comment2 = new UserComment($this->article->getId(),
- $this->article->getBlogId(),
- 0, // dummy parent
- "dummy topic 2",
- "dummy text 2",
- $timestamp->getTimestamp());
+ $comment3 = new UserComment($article->getId(),
+ $article->getBlogId(),
+ 0, // dummy parent
+ "dummy topic 2",
+ "spam",
+ $timestamp->getTimestamp(),
+ "username",
+ "",
+ "",
+ "0.0.0.0",
+ 0,
+ COMMENT_STATUS_SPAM);
- $this->comments = new ArticleComments();
+ // add trackbacks
+ $timestamp = new Timestamp();
+ $trackback1 = new Trackback("fake url",
+ "this is a title",
+ $article->getId(),
+ $article->getBlogId(),
+ "excerpt from my blog",
+ "my blog name",
+ $timestamp->getTimestamp(),
+ "0.0.0.0");
- }
+ $timestamp = new Timestamp();
+ $trackback2 = new Trackback("fake url 2",
+ "this is a title",
+ $article->getId(),
+ $article->getBlogId(),
+ "excerpt from my blog",
+ "my blog name",
+ $timestamp->getTimestamp(),
+ "0.0.0.0",
+ 0,
+ COMMENT_STATUS_SPAM);
+ $timestamp = new Timestamp();
+ $trackback3 = new Trackback("fake url 3",
+ "this is a title",
+ $article->getId(),
+ $article->getBlogId(),
+ "excerpt from my blog",
+ "my blog name",
+ $timestamp->getTimestamp(),
+ "0.0.0.0",
+ 0,
+ COMMENT_STATUS_SPAM);
+ $timestamp = new Timestamp();
+ $trackback4 = new Trackback("fake url 4",
+ "this is a title",
+ $article->getId(),
+ $article->getBlogId(),
+ "excerpt from my blog",
+ "my blog name",
+ $timestamp->getTimestamp(),
+ "0.0.0.0",
+ 0,
+ COMMENT_STATUS_SPAM);
+ $comments = new CommentsCommon();
+ $this->assertTrue($comments->addComment($comment1), "Couldn't add test comment 1");
+ $this->assertTrue($comments->addComment($comment2), "Couldn't add test comment 2");
+ $this->assertTrue($comments->addComment($comment3), "Couldn't add test comment 3");
+ $this->assertTrue($comments->addComment($trackback1), "Couldn't add test trackback 1");
+ $this->assertTrue($comments->addComment($trackback2), "Couldn't add test trackback 2");
+ $this->assertTrue($comments->addComment($trackback3), "Couldn't add test trackback 3");
+ $this->assertTrue($comments->addComment($trackback4), "Couldn't add test trackback 4");
- function testAddComment(){
-// $this->assertTrue($this->articles->addArticle($this->article), "Couldn't add article");
-// $this->assertTrue($this->article->getId() != null, "Article ID is null");
-// $this->assertTrue($this->comment1->getArticleId() != null, "Can't find articleId from comment");
-// $this->assertTrue($this->comment2->getArticleId() != null, "Can't find articleId from comment");
+ $num = $comments->getNumPostComments($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);
+ $this->assertTrue($num == 3, "Wrong number of comments/trackbacks (nonspam) ". $num);
+ $num = $comments->getNumPostComments($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);
+ $this->assertTrue($num == 3, "Wrong number of comments (all) ". $num);
+ $num = $comments->getNumPostComments($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);
+ $this->assertTrue($num == 1, "Wrong number of comments (spam) ". $num);
+
+ $num = $comments->getNumPostComments($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);
+ $this->assertTrue($num == 1, "Wrong number of trackbacks (nonspam) ". $num);
+ $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_TRACKBACK);
+ $this->assertTrue($num == 3, "Wrong number of trackbacks (spam) ". $num);
+
-// $this->assertTrue($this->comments->addComment( $this->comment1 ), "Couldn't add comment1");
-// $this->assertTrue($this->comments->addComment( $this->comment2 ), "Couldn't add comment2");
- }
+ // delete the temporary blogs
+ $blogs->deleteBlog($blog->getId());
+ $users->deleteUser($user->getId());
+ }
+
}
-?>
\ No newline at end of file
+?>
+
+
More information about the pLog-svn
mailing list