2
0

LocaleTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 Zend_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', 'Zend_Application_Resource_LocaleTest::main');
  24. }
  25. /**
  26. * Zend_Loader_Autoloader
  27. */
  28. require_once 'Zend/Loader/Autoloader.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Application
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Application
  36. */
  37. class Zend_Application_Resource_LocaleTest extends PHPUnit_Framework_TestCase
  38. {
  39. public static function main()
  40. {
  41. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  42. $result = PHPUnit_TextUI_TestRunner::run($suite);
  43. }
  44. public function setUp()
  45. {
  46. // Store original autoloaders
  47. $this->loaders = spl_autoload_functions();
  48. if (!is_array($this->loaders)) {
  49. // spl_autoload_functions does not return empty array when no
  50. // autoloaders registered...
  51. $this->loaders = array();
  52. }
  53. Zend_Loader_Autoloader::resetInstance();
  54. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  55. $this->application = new Zend_Application('testing');
  56. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  57. Zend_Registry::_unsetInstance();
  58. }
  59. public function tearDown()
  60. {
  61. // Restore original autoloaders
  62. $loaders = spl_autoload_functions();
  63. foreach ($loaders as $loader) {
  64. spl_autoload_unregister($loader);
  65. }
  66. foreach ($this->loaders as $loader) {
  67. spl_autoload_register($loader);
  68. }
  69. // Reset autoloader instance so it doesn't affect other tests
  70. Zend_Loader_Autoloader::resetInstance();
  71. }
  72. public function testInitializationInitializesLocaleObject()
  73. {
  74. $resource = new Zend_Application_Resource_Locale(array());
  75. $resource->init();
  76. $this->assertTrue($resource->getLocale() instanceof Zend_Locale);
  77. }
  78. public function testInitializationReturnsLocaleObject()
  79. {
  80. $resource = new Zend_Application_Resource_Locale(array());
  81. $resource->setBootstrap($this->bootstrap);
  82. $test = $resource->init();
  83. $this->assertTrue($test instanceof Zend_Locale);
  84. }
  85. public function testOptionsPassedToResourceAreUsedToSetLocaleState()
  86. {
  87. $options = array(
  88. 'default' => 'kok_IN',
  89. 'registry_key' => 'Foo_Bar',
  90. 'force' => true
  91. );
  92. $resource = new Zend_Application_Resource_Locale($options);
  93. $resource->setBootstrap($this->bootstrap);
  94. $resource->init();
  95. $locale = $resource->getLocale();
  96. $this->assertEquals('kok_IN', $locale->__toString());
  97. $this->assertTrue(Zend_Registry::isRegistered('Foo_Bar'));
  98. $this->assertSame(Zend_Registry::get('Foo_Bar'), $locale);
  99. }
  100. public function testOptionsPassedToResourceAreUsedToSetLocaleState1()
  101. {
  102. $options = array(
  103. 'default' => 'kok_IN',
  104. );
  105. $resource = new Zend_Application_Resource_Locale($options);
  106. $resource->setBootstrap($this->bootstrap);
  107. $resource->init();
  108. $locale = $resource->getLocale();
  109. // This test will fail if your configured locale is kok_IN
  110. $this->assertFalse('kok_IN' == $locale->__toString());
  111. $this->assertSame(Zend_Registry::get('Zend_Locale'), $locale);
  112. }
  113. /**
  114. * @group ZF-7058
  115. */
  116. public function testSetCache()
  117. {
  118. $cache = Zend_Cache::factory('Core', 'Black Hole', array(
  119. 'lifetime' => 120,
  120. 'automatic_serialization' => true
  121. ));
  122. $config = array(
  123. 'default' => 'fr_FR',
  124. 'cache' => $cache,
  125. );
  126. $resource = new Zend_Application_Resource_Locale($config);
  127. $resource->init();
  128. $backend = Zend_Locale::getCache()->getBackend();
  129. $this->assertInstanceOf('Zend_Cache_Backend_BlackHole', $backend);
  130. Zend_Locale::removeCache();
  131. }
  132. /**
  133. * @group ZF-7058
  134. */
  135. public function testSetCacheFromCacheManager()
  136. {
  137. $configCache = array(
  138. 'memory' => array(
  139. 'frontend' => array(
  140. 'name' => 'Core',
  141. 'options' => array(
  142. 'lifetime' => 120,
  143. 'automatic_serialization' => true
  144. )
  145. ),
  146. 'backend' => array(
  147. 'name' => 'Black Hole'
  148. )
  149. )
  150. );
  151. $this->bootstrap->registerPluginResource('cachemanager', $configCache);
  152. $this->assertFalse(Zend_Locale::hasCache());
  153. $config = array(
  154. 'bootstrap' => $this->bootstrap,
  155. 'cache' => 'memory',
  156. );
  157. $resource = new Zend_Application_Resource_Locale($config);
  158. $resource->init();
  159. $this->assertTrue(Zend_Locale::hasCache());
  160. Zend_Locale::removeCache();
  161. }
  162. }
  163. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LocaleTest::main') {
  164. Zend_Application_Resource_LocaleTest::main();
  165. }