Example #1
0
 public function testIfWillFilterByAndStatusAndSearch()
 {
     $nums = $this->makeData();
     $criteria = new SearchCriteria();
     $criteria->addCond('status', '==', m::StatusInactive);
     $criteria->search('Vienna');
     $dp = new SearchProvider(m::class);
     $dp->setCriteria($criteria);
     $this->assertSame(2, $dp->getItemCount(), 'That current result set has items');
 }
 public function testIfWillFindDocumentsAndSetItsIndexName()
 {
     $model = $this->prepare();
     $criteria = new SearchCriteria();
     $criteria->search('shanghai');
     $dp = new SearchProvider($model);
     $dp->setCriteria($criteria);
     $results = $dp->getData();
     $this->assertGreaterThan(0, count($results), 'That something was found');
     foreach ($results as $result) {
         /* @var $result ModelWithIndex */
         $index = $result->getIndex();
         codecept_debug($index);
         $this->assertInternalType('string', $index, 'That found result has set index');
     }
 }
 public function testIfWillFindDocumentsAndSetItsScore()
 {
     $model = $this->prepare();
     $criteria = new SearchCriteria();
     $criteria->search('shanghai');
     $dp = new SearchProvider($model);
     $dp->setCriteria($criteria);
     $results = $dp->getData();
     $this->assertGreaterThan(0, count($results), 'That something was found');
     foreach ($results as $result) {
         /* @var $result ModelWithScore */
         $score = $result->getScore();
         codecept_debug($score);
         $this->assertGreaterThan(0, $score, 'That found result has some score');
     }
 }
 public function testIfWillFindProperlyCountWithSearchProviderPagination()
 {
     $model = $this->prepare();
     $criteria = new SearchCriteria();
     $criteria->search('shanghai');
     $pagination = new Pagination();
     $pagination->setSize(2);
     $dp = new SearchProvider($model);
     $dp->setPagination($pagination);
     $dp->setCriteria($criteria);
     $this->assertSame(7, $dp->getTotalItemCount(), 'That total is 7 items');
     $this->assertSame(2, $dp->getItemCount(), 'That current result set has 2 items');
     $results = $dp->getData();
     $this->assertSame(2, count($results), 'That 2 result was returned');
     $this->assertTrue(array_key_exists(0, $results), 'That results starts with key 0');
     foreach ($results as $i => $result) {
         $this->assertInstanceOf(SimpleModel::class, $result, "That result {$i} has proper type");
         $this->assertSame('Shanghai', $result->title, "That title is properly populated");
     }
 }