CacheManagerTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_CacheManagerTest::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. * Zend_Controller_Front
  35. */
  36. require_once 'Zend/Controller/Front.php';
  37. /**
  38. * Zend_Application_Resource_Cachemanager
  39. */
  40. require_once 'Zend/Application/Resource/Cachemanager.php';
  41. /**
  42. * @category Zend
  43. * @package Zend_Application
  44. * @subpackage UnitTests
  45. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  46. * @license http://framework.zend.com/license/new-bsd New BSD License
  47. * @group Zend_Application
  48. */
  49. class Zend_Application_Resource_CacheManagerTest extends PHPUnit_Framework_TestCase
  50. {
  51. public static function main()
  52. {
  53. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. public function setUp()
  57. {
  58. // Store original autoloaders
  59. $this->loaders = spl_autoload_functions();
  60. if (!is_array($this->loaders)) {
  61. // spl_autoload_functions does not return empty array when no
  62. // autoloaders registered...
  63. $this->loaders = array();
  64. }
  65. Zend_Loader_Autoloader::resetInstance();
  66. $this->autoloader = Zend_Loader_Autoloader::getInstance();
  67. $this->application = new Zend_Application('testing');
  68. require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
  69. $this->bootstrap = new ZfAppBootstrap($this->application);
  70. }
  71. public function tearDown()
  72. {
  73. // Restore original autoloaders
  74. $loaders = spl_autoload_functions();
  75. foreach ($loaders as $loader) {
  76. spl_autoload_unregister($loader);
  77. }
  78. foreach ($this->loaders as $loader) {
  79. spl_autoload_register($loader);
  80. }
  81. Zend_Controller_Front::getInstance()->resetInstance();
  82. // Reset autoloader instance so it doesn't affect other tests
  83. Zend_Loader_Autoloader::resetInstance();
  84. }
  85. public function testInitializationCreatesCacheManagerInstance()
  86. {
  87. $resource = new Zend_Application_Resource_Cachemanager(array());
  88. $resource->init();
  89. $this->assertTrue($resource->getCachemanager() instanceof Zend_Cache_Manager);
  90. }
  91. public function testShouldReturnCacheManagerWhenComplete()
  92. {
  93. $resource = new Zend_Application_Resource_Cachemanager(array());
  94. $manager = $resource->init();
  95. $this->assertTrue($manager instanceof Zend_Cache_Manager);
  96. }
  97. public function testShouldMergeConfigsIfOptionsPassedForDefaultCacheTemplate()
  98. {
  99. $options = array(
  100. 'page' => array(
  101. 'backend' => array(
  102. 'options' => array(
  103. 'cache_dir' => '/foo'
  104. )
  105. )
  106. )
  107. );
  108. $resource = new Zend_Application_Resource_Cachemanager($options);
  109. $manager = $resource->init();
  110. $cacheTemplate = $manager->getCacheTemplate('page');
  111. $this->assertEquals('/foo', $cacheTemplate['backend']['options']['cache_dir']);
  112. }
  113. public function testShouldCreateNewCacheTemplateIfConfigNotMatchesADefaultTemplate()
  114. {
  115. $options = array(
  116. 'foo' => array(
  117. 'backend' => array(
  118. 'options' => array(
  119. 'cache_dir' => '/foo'
  120. )
  121. )
  122. )
  123. );
  124. $resource = new Zend_Application_Resource_Cachemanager($options);
  125. $manager = $resource->init();
  126. $cacheTemplate = $manager->getCacheTemplate('foo');
  127. $this->assertSame($options['foo'], $cacheTemplate);
  128. }
  129. }
  130. if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_CacheManagerTest::main') {
  131. Zend_Application_Resource_CacheManagerTest::main();
  132. }