PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/code/ryzom/tools/server/www/webtt/cake/tests/cases/libs/view/media.test.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 180 lines | 60 code | 17 blank | 103 comment | 2 complexity | 4bd630f86db9c63cae8baea6b6df7ed8 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * ThemeViewTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake
  16. * @subpackage cake.tests.cases.libs
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. App::import('Core', array('Media', 'Controller'));
  21. if (!class_exists('ErrorHandler')) {
  22. App::import('Core', array('Error'));
  23. }
  24. if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
  25. define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
  26. }
  27. /**
  28. * ThemePostsController class
  29. *
  30. * @package cake
  31. * @subpackage cake.tests.cases.libs.view
  32. */
  33. class MediaController extends Controller {
  34. /**
  35. * name property
  36. *
  37. * @var string 'Media'
  38. * @access public
  39. */
  40. var $name = 'Media';
  41. /**
  42. * index download
  43. *
  44. * @access public
  45. * @return void
  46. */
  47. function download() {
  48. $path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS .'css' . DS;
  49. $id = 'test_asset.css';
  50. $extension = 'css';
  51. $this->set(compact('path', 'id', 'extension'));
  52. }
  53. }
  54. /**
  55. * TestMediaView class
  56. *
  57. * @package cake
  58. * @subpackage cake.tests.cases.libs.view
  59. */
  60. class TestMediaView extends MediaView {
  61. /**
  62. * headers public property as a copy from protected property _headers
  63. *
  64. * @var array
  65. * @access public
  66. */
  67. var $headers = array();
  68. /**
  69. * active property to mock the status of a remote connection
  70. *
  71. * @var boolean true
  72. * @access public
  73. */
  74. var $active = true;
  75. function _output() {
  76. $this->headers = $this->_headers;
  77. }
  78. /**
  79. * _isActive method. Usted de $active property to mock an active (true) connection,
  80. * or an aborted (false) one
  81. *
  82. * @access protected
  83. * @return void
  84. */
  85. function _isActive() {
  86. return $this->active;
  87. }
  88. /**
  89. * _clearBuffer method
  90. *
  91. * @access protected
  92. * @return void
  93. */
  94. function _clearBuffer() {
  95. return true;
  96. }
  97. /**
  98. * _flushBuffer method
  99. *
  100. * @access protected
  101. * @return void
  102. */
  103. function _flushBuffer() {
  104. }
  105. }
  106. /**
  107. * ThemeViewTest class
  108. *
  109. * @package cake
  110. * @subpackage cake.tests.cases.libs
  111. */
  112. class MediaViewTest extends CakeTestCase {
  113. /**
  114. * startTest method
  115. *
  116. * @access public
  117. * @return void
  118. */
  119. function startTest() {
  120. Router::reload();
  121. $this->Controller =& new Controller();
  122. $this->MediaController =& new MediaController();
  123. $this->MediaController->viewPath = 'posts';
  124. $this->MediaController->download();
  125. $this->MediaView =& new TestMediaView($this->MediaController);
  126. }
  127. /**
  128. * endTest method
  129. *
  130. * @access public
  131. * @return void
  132. */
  133. function endTest() {
  134. unset($this->MediaView);
  135. unset($this->MediaController);
  136. unset($this->Controller);
  137. ClassRegistry::flush();
  138. }
  139. /**
  140. * testRender method
  141. *
  142. * @access public
  143. * @return void
  144. */
  145. function testRender() {
  146. ob_start();
  147. $result = $this->MediaView->render();
  148. $output = ob_get_clean();
  149. $this->assertTrue($result !== false);
  150. $this->assertEqual($output, 'this is the test asset css file');
  151. }
  152. /**
  153. * testConnectionAborted method
  154. *
  155. * @access public
  156. * @return void
  157. */
  158. function testConnectionAborted() {
  159. $this->MediaView->active = false;
  160. $result = $this->MediaView->render();
  161. $this->assertFalse($result);
  162. }
  163. }