[ 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/summary/dao/ -> summarystats_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/dao/article.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   6      lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );    
   7      lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
   8      lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );    
   9      lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
  10      lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
  11      lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  12      lt_include( PLOG_CLASS_PATH."class/dao/userstatus.class.php" );        
  13      lt_include( PLOG_CLASS_PATH."class/summary/dao/summarystats.class.php" );
  14  
  15      /**
  16       * Unit test cases for the SummaryStats class
  17       */
  18      class SummaryStats_Test extends LifeTypeTestCase
  19      {
  20          /**
  21           * dummy blog we'll be using during the tests
  22           */
  23          var $blog;
  24          
  25          /**
  26           * dummy blog owner
  27           */
  28          var $owner;
  29          
  30          /**
  31           * dummy category
  32           */
  33          var $cat;
  34          
  35          /**
  36           * URL pointing to this server's xmlrpc.php
  37           */
  38          
  39  		function setUp()
  40          {
  41              // create the blog owner
  42              $this->owner = new UserInfo( md5(time()),   // name
  43                                           "password",   // password
  44                                           "whatever@whatever.com",  // email address
  45                                            "",    // about
  46                                           "" );
  47              $users = new Users();
  48              if( !$users->addUser( $this->owner )) {
  49                  throw( new Exception( "Error adding test user" ));
  50                  die();
  51              }
  52              
  53              // create the test blog
  54              $blogs = new Blogs();
  55              $this->blog = null;
  56              $this->blog = new BlogInfo( "test blog",
  57                                          $this->owner->getId(),
  58                                          "",
  59                                          new BlogSettings());
  60              if( !$blogs->addBlog( $this->blog )) {
  61                  throw( new Exception( "Error adding test blog!" ));
  62                  die();
  63              }
  64              
  65              // add a default category
  66              $this->cat = new ArticleCategory( "General", 
  67                                          "",
  68                                          $this->blog->getId(),
  69                                          true );
  70              $cats = new ArticleCategories();
  71              if( !$cats->addArticleCategory( $this->cat )) {
  72                  throw(  new Exception( "Error adding test category!" ));
  73                  die();
  74              }
  75          }
  76          
  77  		function tearDown()
  78          {
  79              $users = new Users();
  80              $users->deleteUser( $this->owner->getId());
  81              
  82              $blogs = new Blogs();
  83              $blogs->deleteBlog( $this->blog->getId());
  84              
  85              $cats = new ArticleCategories();
  86              $cats->deleteCategory( $this->cat->getId(), $this->blog->getId());
  87          }        
  88          
  89          /**
  90           * Test case for SummaryStats::getRecentArticles and mantis case 1052 
  91           * (http://bugs.lifetype.net/view.php?id=1052)
  92           */
  93  		function testGetRecentArticlesIgnoreFuturePosts()
  94          {
  95              // create a new post first
  96              $article = new Article(
  97                  "topic",
  98                  "text",
  99                  Array( $this->cat->getId()),
 100                  $this->owner->getId(),
 101                  $this->blog->getId(),
 102                  POST_STATUS_PUBLISHED,
 103                  0
 104                  );
 105              // set the date within 5 minutes
 106              //$t = Timestamp::getTimestampWithOffset( new Timestamp(), 2 );
 107              $t = new Timestamp();
 108              $t->addSeconds( 5 * 60 );
 109              $article->setDateObject( $t );
 110  
 111              // save the article and check
 112              $articles = new Articles();
 113              $this->assertTrue( $articles->addArticle( $article ), "Unable to add a new test article" );
 114  
 115              // load the list of recent posts and check that the one we've just added, which
 116              // has a date in the future, isn't there
 117              $stats = new SummaryStats();
 118              $posts = $stats->getRecentArticles();
 119              $i = 0;
 120              $found = false;                
 121              while( $i < count( $posts ) && !$found ) {
 122                  $found = ($posts[$i]->getId() == $article->getId());
 123                  $i++;
 124              }
 125              
 126              $this->assertFalse( $found, "A post with date in the future was returned by getRecentPosts" );
 127              
 128              $this->assertTrue( $articles->deleteArticle( $article->getId(), $this->owner->getId(), $this->blog->getId()));
 129          }
 130      }
 131  ?>


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