[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/test/tests/dao/ -> commentscommon_test.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/test/helpers/testtools.class.php" );    
   5      lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   7      lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
   9      lt_include( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
  13      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  14      lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
  15      lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
  16      lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
  17  
  18      /**
  19       * \ingroup Test
  20       *
  21       * Test cases for the CommentsCommon class
  22       */
  23      class CommentsCommon_Test extends LifeTypeTestCase
  24      {
  25  
  26          function testGetNumPostComments()
  27          {
  28  
  29              // create a user
  30              $users = new Users();
  31              $randomName = md5(time());
  32              $user = new UserInfo($randomName, "blah", "test@not-a-real-address.net", "", "Full Name");
  33              $this->assertTrue($users->addUser($user), "Couldn't add test user");
  34              
  35              // create a blog
  36              $blogs = new Blogs();
  37              $randomName = md5(time());
  38              $blog = new BlogInfo( $randomName, $user->getId(), "About blog random blog", new BlogSettings());
  39              $this->assertTrue($blogs->addBlog( $blog ), "Couldn't add test blog");
  40  
  41              // add an article
  42              $articles = new Articles();
  43              $article = new Article(
  44                  "dummy topic",
  45                  "dummy text",
  46                  Array( 1 ),   // a dummy category (I don't need a category here)
  47                  $user->getId(), // our user we created above
  48                  $blog->getId(),  // our blog we created above
  49                  POST_STATUS_PUBLISHED,  // published status
  50                  0   // not read yet
  51                  );
  52              $this->assertTrue($articles->addArticle($article), "Couldn't add test article");
  53  
  54              // Add comments
  55              $timestamp = new Timestamp();
  56              $comment1 = new UserComment($article->getId(),
  57                                          $article->getBlogId(),
  58                                          0, // dummy parent
  59                                          "dummy topic",
  60                                          "dummy text",
  61                                          $timestamp->getTimestamp());
  62              
  63              $timestamp = new Timestamp();
  64              $comment2 = new UserComment($article->getId(),
  65                                          $article->getBlogId(),
  66                                          0, // dummy parent
  67                                          "dummy topic 2",
  68                                          "dummy text 2",
  69                                          $timestamp->getTimestamp());
  70  
  71              $timestamp = new Timestamp();
  72              $comment3 = new UserComment($article->getId(),
  73                                          $article->getBlogId(),
  74                                          0, // dummy parent
  75                                          "dummy topic 2",
  76                                          "spam",
  77                                          $timestamp->getTimestamp(),
  78                                          "username",
  79                                          "",
  80                                          "",
  81                                          "0.0.0.0",
  82                                          0,
  83                                          COMMENT_STATUS_SPAM);
  84  
  85                  // add trackbacks
  86              $timestamp = new Timestamp();
  87              $trackback1 = new Trackback("fake url",
  88                                          "this is a title",
  89                                          $article->getId(),
  90                                          $article->getBlogId(),
  91                                          "excerpt from my blog",
  92                                          "my blog name",
  93                                          $timestamp->getTimestamp(),
  94                                          "0.0.0.0");
  95  
  96              $timestamp = new Timestamp();
  97              $trackback2 = new Trackback("fake url 2",
  98                                          "this is a title",
  99                                          $article->getId(),
 100                                          $article->getBlogId(),
 101                                          "excerpt from my blog",
 102                                          "my blog name",
 103                                          $timestamp->getTimestamp(),
 104                                          "0.0.0.0",
 105                                          0,
 106                                          COMMENT_STATUS_SPAM);
 107              $timestamp = new Timestamp();
 108              $trackback3 = new Trackback("fake url 3",
 109                                          "this is a title",
 110                                          $article->getId(),
 111                                          $article->getBlogId(),
 112                                          "excerpt from my blog",
 113                                          "my blog name",
 114                                          $timestamp->getTimestamp(),
 115                                          "0.0.0.0",
 116                                          0,
 117                                          COMMENT_STATUS_SPAM);
 118              $timestamp = new Timestamp();
 119              $trackback4 = new Trackback("fake url 4",
 120                                          "this is a title",
 121                                          $article->getId(),
 122                                          $article->getBlogId(),
 123                                          "excerpt from my blog",
 124                                          "my blog name",
 125                                          $timestamp->getTimestamp(),
 126                                          "0.0.0.0",
 127                                          0,
 128                                          COMMENT_STATUS_SPAM);
 129  
 130  
 131              $comments = new CommentsCommon();
 132              $this->assertTrue($comments->addComment($comment1), "Couldn't add test comment 1");
 133              $this->assertTrue($comments->addComment($comment2), "Couldn't add test comment 2");
 134              $this->assertTrue($comments->addComment($comment3), "Couldn't add test comment 3");
 135              $this->assertTrue($comments->addComment($trackback1), "Couldn't add test trackback 1");
 136              $this->assertTrue($comments->addComment($trackback2), "Couldn't add test trackback 2");
 137              $this->assertTrue($comments->addComment($trackback3), "Couldn't add test trackback 3");
 138              $this->assertTrue($comments->addComment($trackback4), "Couldn't add test trackback 4");
 139  
 140              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_ANY);
 141              $this->assertTrue($num == 7, "Wrong number of comments/trackbacks (all) ". $num);
 142              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_ANY);
 143              $this->assertTrue($num == 3, "Wrong number of comments/trackbacks (nonspam) ". $num);
 144              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_ANY);
 145              $this->assertTrue($num == 4, "Wrong number of comments/trackbacks (spam) ". $num);
 146  
 147              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_COMMENT);
 148              $this->assertTrue($num == 3, "Wrong number of comments (all) ". $num);
 149              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_COMMENT);
 150              $this->assertTrue($num == 2, "Wrong number of comments (nonspam) ". $num);
 151              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_COMMENT);
 152              $this->assertTrue($num == 1, "Wrong number of comments (spam) ". $num);
 153  
 154              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_ALL, COMMENT_TYPE_TRACKBACK);
 155              $this->assertTrue($num == 4, "Wrong number of trackbacks (all) ". $num);
 156              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_NONSPAM, COMMENT_TYPE_TRACKBACK);
 157              $this->assertTrue($num == 1, "Wrong number of trackbacks (nonspam) ". $num);
 158              $num = $comments->getNumPostComments($article->getId(), COMMENT_STATUS_SPAM, COMMENT_TYPE_TRACKBACK);
 159              $this->assertTrue($num == 3, "Wrong number of trackbacks (spam) ". $num);
 160  
 161              
 162              // delete the temporary blogs
 163              $blogs->deleteBlog($blog->getId());
 164              $users->deleteUser($user->getId());
 165          }
 166          
 167          /**
 168           * Test case for mantis bug http://bugs.lifetype.net/view.php?id=1144
 169           *
 170           * Dates with time offset being saved to the database
 171           */
 172  		function testUpdateCommentWithTimeOffsets()
 173          {
 174              // create the scenario
 175              $user = TestTools::createUser();
 176              $blog = TestTools::createBlog( $user->getId());
 177              $cat  = TestTools::createArticleCategory( $blog->getId());
 178              $article = TestTools::createArticle( $blog->getId(), $user->getId(), Array( $cat->getId()));
 179              
 180              // update the time offset settings for the blog
 181              $blog->setValue( "time_offset", "+3" );
 182              $blogs = new Blogs();
 183              $blogs->updateBlog( $blog );
 184              
 185              // create the comment and save it to the database
 186              $comment = new UserComment( $article->getId(), $blog->getId(), 0, "test comment", "test comment body" );
 187              $comments = new ArticleComments();
 188              $comments->addComment( $comment );
 189              
 190              // now get the time
 191              $origTime = $comment->getTimestamp();
 192              
 193              // update the comment and reload the comment
 194              $comments->updateComment( $comment );
 195              $comment2 = $comments->getComment( $comment->getId());
 196              $newTime = $comment2->getTimestamp();
 197              
 198              // check that dates are the same
 199              $this->assertEquals( $origTime->getTimestamp(), $newTime->getTimestamp(), "Comment times are not the same!" );
 200              
 201              // destroy the test data
 202              TestTools::deleteDaoTestData( Array( $user, $blog, $cat, $article, $comment, $comment2 ));
 203          }
 204      }
 205  ?>
 206  
 207  


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics