| | 357 | |
|---|
| | 358 | $t->diag('delete()'); |
|---|
| | 359 | |
|---|
| | 360 | Doctrine_Query::create()->delete()->from('DArticle')->execute(); |
|---|
| | 361 | $finder = new sfDoctrineFinder('DArticle'); |
|---|
| | 362 | $nbDeleted = $finder->delete(); |
|---|
| | 363 | $t->is($nbDeleted, 0, 'delete() on an empty finder with no results returns 0'); |
|---|
| | 364 | $article2 = new DArticle(); |
|---|
| | 365 | $article2->setTitle('foo2'); |
|---|
| | 366 | $article2->save(); |
|---|
| | 367 | $article3 = new DArticle(); |
|---|
| | 368 | $article3->setTitle('foo3'); |
|---|
| | 369 | $article3->save(); |
|---|
| | 370 | $finder = new sfDoctrineFinder('DArticle'); |
|---|
| | 371 | $nbDeleted = $finder->delete(); |
|---|
| | 372 | $t->is($nbDeleted, 2, 'delete() deletes records from the table and returns the number of deleted rows'); |
|---|
| | 373 | $finder = new sfDoctrineFinder('DArticle'); |
|---|
| | 374 | $nbArticles = $finder->count(); |
|---|
| | 375 | $t->is($nbArticles, 0, 'delete() on an empty finder deletes all rows'); |
|---|
| | 376 | $article2 = new DArticle(); |
|---|
| | 377 | $article2->setTitle('foo2'); |
|---|
| | 378 | $article2->save(); |
|---|
| | 379 | $article3 = new DArticle(); |
|---|
| | 380 | $article3->setTitle('foo3'); |
|---|
| | 381 | $article3->save(); |
|---|
| | 382 | $finder = new sfDoctrineFinder('DArticle'); |
|---|
| | 383 | $nbDeleted = $finder->where('Title', 'foo2')->delete(); |
|---|
| | 384 | $t->is($nbDeleted, 1, 'delete() deletes all rows found by a finder'); |
|---|
| | 385 | $nbArticles = $finder->count(); |
|---|
| | 386 | $t->is($nbArticles, 1, 'delete() does not delete rows not found by the finder'); |
|---|
| | 387 | |
|---|
| | 388 | $t->diag('where()'); |
|---|
| | 389 | |
|---|
| | 390 | Doctrine_Query::create()->delete()->from('DArticle')->execute(); |
|---|
| | 391 | $article1 = new DArticle(); |
|---|
| | 392 | $article1->setTitle('abc'); |
|---|
| | 393 | $article1->save(); |
|---|
| | 394 | $article2 = new DArticle(); |
|---|
| | 395 | $article2->setTitle('def'); |
|---|
| | 396 | $article2->save(); |
|---|
| | 397 | $article3 = new DArticle(); |
|---|
| | 398 | $article3->setTitle('bbc'); |
|---|
| | 399 | $article3->save(); |
|---|
| | 400 | $article = sfDoctrineFinder::from('DArticle')->where('Title', 'abc')->findOne(); |
|---|
| | 401 | $t->is($article->getId(), $article1->getId(), 'where() accepts a simple CamelCase column name like ClassName'); |
|---|
| | 402 | try |
|---|
| | 403 | { |
|---|
| | 404 | $article = sfDoctrineFinder::from('DArticle')->where('Foo', 'abc')->find(); |
|---|
| | 405 | $t->fail('where() throws an exception when the column is not found (but only after calling find())'); |
|---|
| | 406 | } |
|---|
| | 407 | catch (Exception $e) |
|---|
| | 408 | { |
|---|
| | 409 | $t->pass('where() throws an exception when the column is not found (but only after calling find())'); |
|---|
| | 410 | } |
|---|
| | 411 | $article = sfDoctrineFinder::from('DArticle')->where('DArticle.Title', 'abc')->findOne(); |
|---|
| | 412 | $t->is($article->getId(), $article1->getId(), 'where() accepts a complete column name ClassName.ColumnName'); |
|---|
| | 413 | $article = sfDoctrineFinder::from('DArticle')->where('DArticle_Title', 'abc')->findOne(); |
|---|
| | 414 | $t->is($article->getId(), $article1->getId(), 'where() accepts a complete column name ClassName_ColumnName'); |
|---|
| | 415 | $article = sfDoctrineFinder::from('DArticle')->where('d.Title', 'abc')->findOne(); |
|---|
| | 416 | $t->is($article->getId(), $article1->getId(), 'where() accepts a complete column name ClassShortcut.ColumnName'); |
|---|
| | 417 | $article = sfDoctrineFinder::from('DArticle b')->where('b.Title', 'abc')->findOne(); |
|---|
| | 418 | $t->is($article->getId(), $article1->getId(), 'where() accepts a complete column name ClassAlias.ColumnName'); |
|---|
| | 419 | $article = sfDoctrineFinder::from('DArticle')->where('Title', 'def')->findOne(); |
|---|
| | 420 | $t->is($article->getId(), $article2->getId(), 'where() adds a WHERE condition on the column given as first argument'); |
|---|
| | 421 | $articles = sfDoctrineFinder::from('DArticle')->where('Title', ' LIKE ', '%bc')->find(); |
|---|
| | 422 | $t->is(count($articles), 2, 'where() accepts a comparator as second argument when three arguments are given'); |
|---|
| | 423 | $articles = sfDoctrineFinder::from('DArticle')->where('Title', 'like', '%bc')->find(); |
|---|
| | 424 | $t->is(count($articles), 2, 'where() accepts a text comparator and is permissive on syntax'); |
|---|
| | 425 | $articles = sfDoctrineFinder::from('DArticle')->where('Title', 'is not null', null)->find(); |
|---|
| | 426 | $t->is(count($articles), 3, 'where() accepts a text comparator and is permissive on syntax'); |
|---|
| | 427 | $articles = sfDoctrineFinder::from('DArticle')->where('Title', ' in ', array('abc', 'def'))->find(); |
|---|
| | 428 | $t->is(count($articles), 2, 'where() accepts a "in" comparator'); |
|---|
| | 429 | |
|---|
| | 430 | try |
|---|
| | 431 | { |
|---|
| | 432 | $article = sfDoctrineFinder::from('DArticle')->whereFoo('abc')->find(); |
|---|
| | 433 | $t->fail('whereXXX() throws an exception when the XXX column is not found (but only after calling find())'); |
|---|
| | 434 | } |
|---|
| | 435 | catch (Exception $e) |
|---|
| | 436 | { |
|---|
| | 437 | $t->pass('whereXXX() throws an exception when the XXX column is not found (but only after calling find())'); |
|---|
| | 438 | } |
|---|
| | 439 | |
|---|
| | 440 | try |
|---|
| | 441 | { |
|---|
| | 442 | $article = sfDoctrineFinder::from('DArticle')->wherecategoryid('abc')->find(); |
|---|
| | 443 | $t->fail('whereXXX() expects a column name in CamelCase'); |
|---|
| | 444 | } |
|---|
| | 445 | catch (Exception $e) |
|---|
| | 446 | { |
|---|
| | 447 | $t->pass('whereXXX() expects a column name in CamelCase'); |
|---|
| | 448 | } |
|---|
| | 449 | |
|---|
| | 450 | try |
|---|
| | 451 | { |
|---|
| | 452 | $article = sfDoctrineFinder::from('DArticle')->whereCategoryId('abc')->find(); |
|---|
| | 453 | $t->pass('whereXXX() expects a column name in CamelCase'); |
|---|
| | 454 | } |
|---|
| | 455 | catch (Exception $e) |
|---|
| | 456 | { |
|---|
| | 457 | $t->fail('whereXXX() expects a column name in CamelCase'); |
|---|
| | 458 | } |
|---|
| | 459 | |
|---|
| | 460 | try |
|---|
| | 461 | { |
|---|
| | 462 | $article = sfDoctrineFinder::from('DArticle')->whereTitle('abc', 'def', 'ghi', 'jkl')->find(); |
|---|
| | 463 | $t->fail('whereXXX() throws an exception when called with more than three parameters'); |
|---|
| | 464 | } |
|---|
| | 465 | catch (Exception $e) |
|---|
| | 466 | { |
|---|
| | 467 | $t->pass('whereXXX() throws an exception when called with more than three parameters'); |
|---|
| | 468 | } |
|---|
| | 469 | |
|---|
| | 470 | $article = sfDoctrineFinder::from('DArticle')->whereTitle('abc')->findOne(); |
|---|
| | 471 | $t->is($article->getId(), $article1->getId(), 'whereXXX() adds a where condition according to the XXX column name'); |
|---|
| | 472 | $article = sfDoctrineFinder::from('DArticle')->whereDArticle_Title('abc')->findOne(); |
|---|
| | 473 | $t->is($article->getId(), $article1->getId(), 'whereXXX() accepts a complete column name like whereClassName_ColumnName()'); |
|---|
| | 474 | $article = sfDoctrineFinder::from('DArticle')->whereTitle('def')->findOne(); |
|---|
| | 475 | $t->is($article->getId(), $article2->getId(), 'whereXXX() adds a WHERE condition on the XXX column'); |
|---|
| | 476 | $articles = sfDoctrineFinder::from('DArticle')->whereTitle('like', '%bc')->find(); |
|---|
| | 477 | $t->is(count($articles), 2, 'whereXXX() accepts a comparator as first argument when two arguments are given'); |
|---|