DatePickerTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "Zend/Locale.php";
  24. require_once "ZendX/JQuery/View/Helper/DatePicker.php";
  25. class ZendX_JQuery_View_DatePickerTest extends ZendX_JQuery_View_jQueryTestCase
  26. {
  27. public function testCallingInViewEnablesJQueryHelper()
  28. {
  29. $element = $this->view->datePicker("element", "");
  30. $this->assertTrue($this->jquery->isEnabled());
  31. $this->assertTrue($this->jquery->uiIsEnabled());
  32. }
  33. public function testShouldAppendToJqueryHelper()
  34. {
  35. $element = $this->view->datePicker("elem1", "", array("option" => "true"));
  36. $jquery = $this->view->jQuery()->__toString();
  37. $this->assertContains('datepicker(', $jquery);
  38. $this->assertContains('"option":"true"', $jquery);
  39. }
  40. public function testShouldCreateInputField()
  41. {
  42. $element = $this->view->datePicker("elem1", "01.01.2007");
  43. $this->assertEquals(array('$("#elem1").datepicker({});'), $this->view->jQuery()->getOnLoadActions());
  44. $this->assertContains("<input", $element);
  45. $this->assertContains('id="elem1"', $element);
  46. $this->assertContains('value="01.01.2007"', $element);
  47. }
  48. public function testDatePickerSupportsLocaleDe()
  49. {
  50. $view = $this->getView();
  51. $locale = new Zend_Locale('de');
  52. Zend_Registry::set('Zend_Locale', $locale);
  53. $view->datePicker("dp1");
  54. $this->assertEquals(array(
  55. '$("#dp1").datepicker({"dateFormat":"dd.mm.yy"});',
  56. ), $view->jQuery()->getOnLoadActions());
  57. }
  58. public function testDatePickerSupportsLocaleEn()
  59. {
  60. $view = $this->getView();
  61. $locale = new Zend_Locale('en');
  62. Zend_Registry::set('Zend_Locale', $locale);
  63. $view->datePicker("dp2");
  64. $this->assertEquals(array(
  65. '$("#dp2").datepicker({"dateFormat":"M d, yy"});',
  66. ), $view->jQuery()->getOnLoadActions());
  67. }
  68. public function testDatePickerSupportsLocaleFr()
  69. {
  70. $view = $this->getView();
  71. $locale = new Zend_Locale('fr');
  72. Zend_Registry::set('Zend_Locale', $locale);
  73. $view->datePicker("dp3");
  74. $this->assertEquals(array(
  75. '$("#dp3").datepicker({"dateFormat":"d M yy"});',
  76. ), $view->jQuery()->getOnLoadActions());
  77. }
  78. /**
  79. * @group ZF-5615
  80. */
  81. public function testDatePickerLocalization()
  82. {
  83. $dpFormat = ZendX_JQuery_View_Helper_DatePicker::resolveZendLocaleToDatePickerFormat("MMM d, yyyy");
  84. $this->assertEquals("M d, yy", $dpFormat, "'MMM d, yyyy' has to be converted to 'M d, yy'.");
  85. }
  86. }