$t->diag('sfPropelFinderPager issues with GroupBy'); $finder = sfPropelFinder::from('Article')->groupBy('Title'); $pager = new sfPropelFinderPager('Article', 2); $pager->setFinder($finder); $pager->init(); $t->is($con->getLastExecutedQuery(), propel_sql('SELECT COUNT([P13*][P12article.ID]) FROM article'), 'sfPropelFinderPager::init() removes groupBy clauses and issues a COUNT'); $pager->getResults(); $t->is($con->getLastExecutedQuery(), 'SELECT article.ID, article.TITLE, article.CATEGORY_ID FROM article GROUP BY article.TITLE LIMIT 2', 'sfPropelFinderPager::getResults() does not remove groupBy clauses and issues a SELECT'); $t->diag('sfPropelFinderPager issues with object finders classes'); class ArticleFinder extends sfPropelFinder { protected $class = 'Article'; } $finder = new ArticleFinder(); try { $pager = $finder->paginate(); $t->pass('Children of sfPropelFinder can use paginate()'); } catch(sfException $e) { $t->fail('Children of sfPropelFinder can use paginate()'); } $t->diag('sfPropelFinderPager issues with repeated criterions'); $finder = sfPropelFinder::from('Article')-> where('Title', 'foo')-> where('CategoryId', 1);
} $finder = sfDoctrineFinder::from('DArticle')-> join('DComment')-> groupBy('DArticle.Id')-> withColumn('COUNT(DComment.ID)', 'NbComments')-> orderBy('NbComments'); $article = $finder->findOne(); $t->is($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id, COUNT(d2.id) AS d2__0 FROM d_article d INNER JOIN d_comment d2 ON d.id = d2.article_id GROUP BY d.id ORDER BY d2__0 ASC LIMIT 1', 'Columns added with withColumn() can be used for sorting'); $t->diag('sfDoctrineFinder::with() issues with object finders classes'); class ArticleFinder extends sfDoctrineFinder { protected $class = 'DArticle'; } $finder = new ArticleFinder; try { $finder->join('DCategory')->find(); $t->pass('Relations lookup work also on finder children objects'); } catch (Exception $e) { $t->fail('Relations lookup work also on finder children objects'); } try { $finder->with('DCategory')->find(); $t->pass('Relations lookup work also on finder children objects'); } catch (Exception $e)
$t->is($finder->getClass(), 'Article', 'setClass() and getClass() are accesors to the protected $class property'); $article = $finder->findOne(); $t->isa_ok($article, 'Article', 'A finder instanciated directly with a class returns the correct objects'); $t->is($article->getTitle(), 'foo', 'A finder can be instanciated without parameter, and initialized later after defining its peer class'); $articles = sfPropelFinder::from('Article')->find(); $t->is(count($articles), 3, 'from() allows direct chaining of conditions'); class ArticleFinder extends sfPropelFinder { protected $class = 'Article'; } $finder = new ArticleFinder(); $article = $finder->findOne(); $t->isa_ok($article, 'Article', 'A finder extending sfPropelFinder can be used directly if defining the $class property'); $finder = new ArticleFinder(); $articles = $finder->find(); $t->is(count($articles), 3, 'A finder extending sfPropelFinder can be used directly if defining the $class property'); ArticlePeer::doDeleteAll(); CategoryPeer::doDeleteAll(); $category1 = new Category(); $category1->setName('cat1'); $category1->save(); $category2 = new Category(); $category2->setName('cat2'); $category2->save(); $article1 = new Article(); $article1->setTitle('aaaaa'); $article1->setCategory($category1); $article1->save();