JqueryTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 Zend
  16. * @package ZendX_Application
  17. * @subpackage UnitTests
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'ZendX_Application_Resource_JqueryTest::main');
  24. }
  25. /**
  26. * Test helper
  27. */
  28. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  29. /**
  30. * Zend_Loader_Autoloader
  31. */
  32. require_once 'Zend/Loader/Autoloader.php';
  33. /**
  34. * @category Zend
  35. * @package ZendX_Application
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_Application
  40. */
  41. class ZendX_Application_Resource_JqueryTest extends PHPUnit_Framework_TestCase
  42. {
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. public function setUp()
  49. {
  50. // Store original autoloaders
  51. $this->loaders = spl_autoload_functions();
  52. if (!is_array($this->loaders)) {
  53. // spl_autoload_functions does not return empty array when no
  54. // autoloaders registered...
  55. $this->loaders = array();
  56. }
  57. Zend_Loader_Autoloader::resetInstance();
  58. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  59. $this->application = new Zend_Application('testing');
  60. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  61. Zend_Registry::_unsetInstance();
  62. ZendX_JQuery_View_Helper_JQuery::disableNoConflictMode();
  63. }
  64. public function tearDown()
  65. {
  66. // Restore original autoloaders
  67. $loaders = spl_autoload_functions();
  68. foreach ($loaders as $loader) {
  69. spl_autoload_unregister($loader);
  70. }
  71. foreach ($this->loaders as $loader) {
  72. spl_autoload_register($loader);
  73. }
  74. // Reset autoloader instance so it doesn't affect other tests
  75. Zend_Loader_Autoloader::resetInstance();
  76. ZendX_JQuery_View_Helper_JQuery::disableNoConflictMode();
  77. }
  78. public function testInitializationInitializesJqueryObject()
  79. {
  80. $this->bootstrap->registerPluginResource('view');
  81. $resource = new ZendX_Application_Resource_Jquery(array());
  82. $resource->setBootstrap($this->bootstrap);
  83. $res = $resource->init();
  84. $this->assertTrue($res instanceof ZendX_JQuery_View_Helper_JQuery_Container);
  85. $this->assertSame($res, $resource->getJquery());
  86. }
  87. public function testOptionsArePassedOn()
  88. {
  89. $options = array(
  90. 'noconflictmode' => true,
  91. 'version' => '1.2.3',
  92. 'localpath' => '/foo/bar/',
  93. 'ui_version' => '2.3.4',
  94. 'uilocalpath' => '/bar/foo/',
  95. 'cdn_ssl' => true,
  96. 'rendermode' => 192,
  97. 'javascriptfile' => '/fooBar.js',
  98. 'javascriptfiles' => array('johndoe.js','janedoe.js'),
  99. 'stylesheet' => '/fooBar.css',
  100. 'stylesheets' => array('johndoe.css','janedoe.css'),
  101. );
  102. $this->bootstrap->registerPluginResource('view');
  103. $resource = new ZendX_Application_Resource_Jquery(array());
  104. $resource->setBootstrap($this->bootstrap);
  105. $resource->setOptions($options);
  106. $res = $resource->init();
  107. $this->assertTrue(ZendX_JQuery_View_Helper_JQuery::getNoConflictMode());
  108. $this->assertEquals('1.2.3', $res->getVersion());
  109. $this->assertEquals('/foo/bar/', $res->getLocalPath());
  110. $this->assertEquals('2.3.4', $res->getUiVersion());
  111. $this->assertEquals('/bar/foo/', $res->getUiLocalPath());
  112. $this->assertTrue($res->getCdnSsl());
  113. $this->assertEquals(192, $res->getRenderMode());
  114. $this->assertEquals(array('/fooBar.css', 'johndoe.css', 'janedoe.css'),
  115. $res->getStylesheets());
  116. $this->assertEquals(array('/fooBar.js', 'johndoe.js', 'janedoe.js'),
  117. $res->getJavascriptFiles());
  118. }
  119. public function testAliasOptionsArePassedOn()
  120. {
  121. $options = array(
  122. 'uiversion' => '3.4.5',
  123. 'ui_localpath' => '/f00/b4r/',
  124. 'render_mode' => 187,
  125. );
  126. $this->bootstrap->registerPluginResource('view');
  127. $resource = new ZendX_Application_Resource_Jquery(array());
  128. $resource->setBootstrap($this->bootstrap);
  129. $resource->setOptions($options);
  130. $res = $resource->init();
  131. $this->assertEquals('3.4.5', $res->getUiVersion());
  132. $this->assertEquals('/f00/b4r/', $res->getUiLocalPath());
  133. $this->assertEquals(187, $res->getRenderMode());
  134. }
  135. /**
  136. * @group ZF-10254
  137. */
  138. public function testIfUiDisableEnableViewHelperJquery()
  139. {
  140. $options = array(
  141. 'uienable' => false,
  142. 'enable' => true
  143. );
  144. $this->bootstrap->registerPluginResource('view');
  145. $resource = new ZendX_Application_Resource_Jquery(array());
  146. $resource->setBootstrap($this->bootstrap);
  147. $resource->setOptions($options);
  148. $res = $resource->init();
  149. $this->assertTrue($res->isEnabled());
  150. $this->assertFalse($res->uiIsEnabled());
  151. $resource = new ZendX_Application_Resource_Jquery(array());
  152. $resource->setBootstrap($this->bootstrap);
  153. $res = $resource->init();
  154. $this->assertTrue($res->isEnabled());
  155. $this->assertTrue($res->uiIsEnabled());
  156. $resource = new ZendX_Application_Resource_Jquery(array());
  157. $resource->setBootstrap($this->bootstrap);
  158. $resource->setOptions(array('uienable' => false));
  159. $res = $resource->init();
  160. $this->assertTrue($res->isEnabled());
  161. $this->assertFalse($res->uiIsEnabled());
  162. $resource = new ZendX_Application_Resource_Jquery(array());
  163. $resource->setBootstrap($this->bootstrap);
  164. $resource->setOptions(array('enable' => false));
  165. $res = $resource->init();
  166. $this->assertFalse($res->isEnabled());
  167. $this->assertFalse($res->uiIsEnabled());
  168. }
  169. }
  170. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LocaleTest::main') {
  171. Zend_Application_Resource_LocaleTest::main();
  172. }