PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/form/sfLuceneFormTest.php

https://bitbucket.org/anycode/sfluceneplugin
PHP | 79 lines | 49 code | 17 blank | 13 comment | 0 complexity | f77bf72d49823dcdee2d7c08e32a23ae MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the sfLucenePlugin package
  4. * (c) 2007 - 2008 Carl Vondrick <carl@carlsoft.net>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * @package sfLucenePlugin
  11. * @subpackage Test
  12. * @author Carl Vondrick
  13. * @version SVN: $Id: sfLuceneFormTest.php 7108 2008-01-20 07:44:42Z Carl.Vondrick $
  14. */
  15. require dirname(__FILE__) . '/../../bootstrap/unit.php';
  16. $t = new limeade_test(9, limeade_output::get());
  17. $limeade = new limeade_sf($t);
  18. $app = $limeade->bootstrap();
  19. class DummyForm extends sfLuceneForm
  20. {
  21. public $setupCount = 0, $configureCount = 0;
  22. public function configure()
  23. {
  24. $this->configureCount++;
  25. }
  26. public function setup()
  27. {
  28. $this->setupCount++;
  29. }
  30. }
  31. $t->diag('testing constructor');
  32. try {
  33. $form = new DummyForm();
  34. $t->pass('__construct() with no arguments does not throw an exception');
  35. } catch (Exception $e) {
  36. $t->fail('__construct() with no arguments does not throw an exception');
  37. }
  38. $t->diag('testing categories');
  39. try {
  40. $form->setCategories('foo');
  41. $t->fail('->setCategories() rejects invalid inputs');
  42. } catch (Exception $e) {
  43. $t->pass('->setCategories() rejects invalid inputs');
  44. }
  45. $formFreeze = clone $form;
  46. try {
  47. $form->setCategories(array('foo', 'bar', 'baz'));
  48. $t->pass('->setCategories() accepts valid inputs');
  49. } catch (Exception $e) {
  50. $t->fail('->setCategories() accepts valid inputs');
  51. }
  52. $t->is($form->hasCategories(), true, '->hasCategories() returns true when categories are set');
  53. $t->is($form->setupCount, $formFreeze->setupCount + 1, '->setCategories() runs ->setup()');
  54. $t->is($form->configureCount, $formFreeze->configureCount + 1, '->setCategories() runs ->configure()');
  55. $t->is_deeply($form->getCategories(), array('foo', 'bar', 'baz'), '->getCategories() returns the categories');
  56. try {
  57. $form->setCategories(array());
  58. $t->pass('->setCategories() accepts an empty array');
  59. } catch (Exception $e) {
  60. $t->fail('->setCategories() accepts valid inputs');
  61. }
  62. $t->is($form->hasCategories(), false, '->hasCategories() returns true when categories are set');