$article3 = new DArticle();
$article3->setTitle('foo3');
$article3->save();
$finder = new sfDoctrineFinder('DArticle');
$article = $finder->findPk($article2->getId());
$t->is($article->getTitle(), 'foo2', 'findPk() returns the object with the primary key matching the argument');
$t->ok(!is_array($article), 'findPk() returns a single object when passed a single primary key');
$finder = new sfDoctrineFinder('DArticle');
$article = $finder->findPk(76543787654);
$t->is($article, null, 'findPk() returns null if the primary key is not found');
$finder = new sfDoctrineFinder('DArticle');
$articles = $finder->findPk(array($article2->getId(), $article1->getId()));
$t->isa_ok($articles, 'Doctrine_Collection', 'findPk() returns a collection of objects when passed an array of primary keys');
$t->is(count($articles), 2, 'findPk() returns the objects with the primary keys matching the arguments');
$article = $finder->with('Category')->findPk($article2->getId());
$t->cmp_ok(strpos($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id, d2.id AS d2__id, d2.name AS d2__name FROM d_article d INNER JOIN d_category d2 ON d.category_id = d2.id'), '===', 0, 'findPk() is compatible with with()');
Doctrine_Query::create()->delete()->from('DArticle')->execute();
$article1 = new DArticle();
$article1->setTitle('foo');
$article1->save();
$articlei18n1 = new DArticleI18n();
$articlei18n1->setCulture('fr');
$articlei18n1->setContent('Bar');
$articlei18n1->setId($article1->getId());
$articlei18n1->save();
try {
    $articleI18n = sfDoctrineFinder::from('DArticleI18n')->findPk($articlei18n1->getId());
    $t->fail('findPk() expects an array of values for objects with composite primary keys');
} catch (Exception $e) {
    $t->pass('findPk() expects an array of values for objects with composite primary keys');
}
$finder = new sfDoctrineFinder('DArticle');
$articles = $finder->filter(array(
  'title' => '*foo*',
  'category_id' => '1'
), true)->find();

$t->is($finder->getLatestQuery(), $query, 'filter() converts underscore column names to CamelCase when the second argument is true');

$finder = new sfDoctrineFinder('DArticle');
$finder->filter(array(
  'Title' => '*foo*',
  'CategoryId' => '1'
), false, array('Title'))->find();

$t->is($finder->getLatestQuery(), 'SELECT d.id AS d__id, d.title AS d__title, d.category_id AS d__category_id FROM d_article d WHERE d.title LIKE \'%foo%\'', 'filter() ignores column names that are not part of the third argument if passed');

$called = false;

class myArticleFinder extends DbFinder
{
  protected $class = 'DArticle';
  
  public function filterByTitle($value)
  {
    global $called;
    $called = $value;
  }
}

$finder = new myArticleFinder();