[ 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/ -> searchengine_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/searchengine.class.php" );
   6  
   7      /**
   8       * \ingroup Test
   9       *
  10       * Test cases for the SearchEngine class
  11       */
  12      class SearchEngine_Test extends LifeTypeTestCase
  13      {
  14          var $user;
  15          var $blog;
  16          var $articles;
  17          var $cat;
  18          var $art1;
  19          var $art2;
  20          
  21          /**
  22           * @private
  23           * Set up the test data
  24           */
  25  		function setUp()
  26          {
  27              // create the test data
  28              $this->user = TestTools::createUser();
  29              $this->blog = TestTools::createBlog( $this->user->getId());
  30              $this->cat  = TestTools::createArticleCategory( $this->blog->getId());
  31              
  32              // create a post with current date
  33              $this->art1 = TestTools::createArticle( $this->blog->getId(), $this->user->getId(), Array( $this->cat->getId()));
  34              // and one with future date
  35              $t = new Timestamp();
  36              $t->addSeconds( 60 * 60 * 10 );
  37              $this->art2 = TestTools::createArticle( $this->blog->getId(), $this->user->getId(), Array( $this->cat->getId()), POST_STATUS_PUBLISHED, $t );    
  38          }
  39          
  40          /**
  41           * @private
  42           * Delete the test data
  43           */        
  44  		function tearDown()
  45          {
  46              TestTools::deleteDaoTestData(
  47                  Array( $this->user, $this->blog, $this->cat, $this->art1, $this->art2 )
  48              );
  49          }
  50          
  51          /**
  52           * make sure that future posts are not returned as search results
  53           */
  54  		function testSearchIgnoreFuturePosts()
  55          {
  56              // check that when searching for this specific string, we only get one match (there should only be one test article)
  57              $searchEngine = new SearchEngine();
  58              $results = $searchEngine->search( $this->blog->getId(), "test article", POST_STATUS_PUBLISHED, false );            
  59              $this->assertEquals( 1, count( $results ), "There should only be one article in the search results" );
  60              
  61              // check that the article with the future date is not part of the results
  62              foreach( $results as $result ) {
  63                  if( $result->getType() == SEARCH_RESULT_ARTICLE ) {
  64                      $article = $result->getArticle();
  65                      $this->assertFalse( ($article->getId() == $this->art2->getId()), "The future article was found as part of the search results!" );
  66                  }
  67              }
  68              
  69              // and finally check that the amount of search results returned is valid
  70              $this->assertEquals( 1, $searchEngine->getNumSearchResults( $this->blog->getId(), "test article", POST_STATUS_PUBLISHED, false ),
  71                                   "The future article was counted by SearchEngine::getNumSearchResults()!" );
  72          }
  73          
  74          /**
  75           * make sure that future posts are not returned as search results when
  76           * doing site-wide searches
  77           */
  78  		function testSiteSearchIgnoreFuturePosts()
  79          {
  80              // check that when searching for this specific string, we only get one match (there should only be one test article)
  81              $searchEngine = new SearchEngine();
  82              $results = $searchEngine->siteSearch( "test article", SEARCH_ARTICLE, POST_STATUS_PUBLISHED, false );
  83              $this->assertEquals( 1, count( $results ), "There should only be one article in the search results" );
  84              
  85              // check that the article with the future date is not part of the results
  86              foreach( $results as $result ) {
  87                  if( $result->getType() == SEARCH_RESULT_ARTICLE ) {
  88                      $article = $result->getArticle();
  89                      $this->assertFalse( ($article->getId() == $this->art2->getId()), "The future article was found as part of the search results!" );
  90                  }
  91              }
  92              
  93              // and finally check that the amount of search results returned is valid
  94              $this->assertEquals( 1, $searchEngine->getNumSiteSearchResults( "test article", SEARCH_ARTICLE, POST_STATUS_PUBLISHED, false ),
  95                                   "The future article was counted by SearchEngine::getNumSiteSearchResults()!" );            
  96          }
  97      }
  98  ?>


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