AutoCompleteTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category ZendX
  16. * @package ZendX_JQuery
  17. * @subpackage View
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once "jQueryTestCase.php";
  23. require_once "ZendX/JQuery/View/Helper/AutoComplete.php";
  24. class ZendX_JQuery_View_AutoCompleteTest extends ZendX_JQuery_View_jQueryTestCase
  25. {
  26. public function testCallingInViewEnablesJQueryHelper()
  27. {
  28. $element = $this->view->autoComplete("element", "", array('data' => array('test')));
  29. $this->assertTrue($this->jquery->isEnabled());
  30. $this->assertTrue($this->jquery->uiIsEnabled());
  31. }
  32. public function testShouldAppendToJqueryHelper()
  33. {
  34. $element = $this->view->autoComplete("elem1", "Default", array('option' => 'true', 'data' => array('test')), array());
  35. $jquery = $this->view->jQuery()->__toString();
  36. $this->assertContains('autocomplete(', $jquery);
  37. $this->assertContains('"option":"true"', $jquery);
  38. }
  39. /**
  40. * @expectedException ZendX_JQuery_Exception
  41. */
  42. public function testShouldAllowAutoCompleteOnlyWithSourceOption()
  43. {
  44. $element = $this->view->autoComplete("elem1");
  45. }
  46. public function testShouldCreateInputField()
  47. {
  48. $element = $this->view->autoComplete("elem1", "Default", array('source' => array('Test')));
  49. $this->assertEquals(array('$("#elem1").autocomplete({"source":["Test"]});'), $this->view->jQuery()->getOnLoadActions());
  50. $this->assertContains("<input", $element);
  51. $this->assertContains('id="elem1"', $element);
  52. $this->assertContains('value="Default"', $element);
  53. }
  54. }