2
0

TranslateTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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-2008 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_TranslateTest::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 Zend_Application
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Application_Resource_TranslateTest extends PHPUnit_Framework_TestCase
  41. {
  42. private $_translationOptions = array('data' => array(
  43. 'message1' => 'message1',
  44. 'message2' => 'message2',
  45. 'message3' => 'message3'
  46. ));
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. public function setUp()
  53. {
  54. // Store original autoloaders
  55. $this->loaders = spl_autoload_functions();
  56. if (!is_array($this->loaders)) {
  57. // spl_autoload_functions does not return empty array when no
  58. // autoloaders registered...
  59. $this->loaders = array();
  60. }
  61. Zend_Loader_Autoloader::resetInstance();
  62. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  63. $this->application = new Zend_Application('testing');
  64. $this->bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
  65. Zend_Registry::_unsetInstance();
  66. }
  67. public function tearDown()
  68. {
  69. // Restore original autoloaders
  70. $loaders = spl_autoload_functions();
  71. foreach ($loaders as $loader) {
  72. spl_autoload_unregister($loader);
  73. }
  74. foreach ($this->loaders as $loader) {
  75. spl_autoload_register($loader);
  76. }
  77. // Reset autoloader instance so it doesn't affect other tests
  78. Zend_Loader_Autoloader::resetInstance();
  79. }
  80. public function testInitializationInitializesTranslateObject()
  81. {
  82. $resource = new Zend_Application_Resource_Translate($this->_translationOptions);
  83. $resource->setBootstrap($this->bootstrap);
  84. $resource->init();
  85. $this->assertTrue($resource->getTranslate() instanceof Zend_Translate);
  86. }
  87. public function testInitializationReturnsLocaleObject()
  88. {
  89. $resource = new Zend_Application_Resource_Translate($this->_translationOptions);
  90. $resource->setBootstrap($this->bootstrap);
  91. $test = $resource->init();
  92. $this->assertTrue($test instanceof Zend_Translate);
  93. }
  94. public function testOptionsPassedToResourceAreUsedToSetLocaleState()
  95. {
  96. $resource = new Zend_Application_Resource_Translate($this->_translationOptions);
  97. $resource->setBootstrap($this->bootstrap);
  98. $resource->init();
  99. $translate = $resource->getTranslate();
  100. $this->assertTrue(Zend_Registry::isRegistered('Zend_Translate'));
  101. $this->assertSame(Zend_Registry::get('Zend_Translate'), $translate);
  102. }
  103. public function testResourceThrowsExceptionWithoutData()
  104. {
  105. try {
  106. $resource = new Zend_Application_Resource_Translate();
  107. $resource->getTranslate();
  108. $this->fail('Expected Zend_Application_Resource_Exception');
  109. } catch (Zend_Application_Resource_Exception $e) {
  110. $this->assertType('Zend_Application_Resource_Exception', $e);
  111. }
  112. }
  113. }
  114. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_TranslateTest::main') {
  115. Zend_Application_Resource_TranslateTest::main();
  116. }