MediaViewTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * MediaViewTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  15. * @package Cake.Test.Case.View
  16. * @since CakePHP(tm) v 1.2.0.4206
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Controller', 'Controller');
  20. App::uses('MediaView', 'View');
  21. App::uses('CakeResponse', 'Network');
  22. /**
  23. * MediaViewTest class
  24. *
  25. * @package Cake.Test.Case.View
  26. */
  27. class MediaViewTest extends CakeTestCase {
  28. /**
  29. * setUp method
  30. *
  31. * @return void
  32. */
  33. public function setUp() {
  34. parent::setUp();
  35. $this->MediaView = new MediaView();
  36. $this->MediaView->response = $this->getMock('CakeResponse', array(
  37. 'cache',
  38. 'type',
  39. 'disableCache',
  40. 'file',
  41. 'send',
  42. 'compress',
  43. ));
  44. }
  45. /**
  46. * tearDown method
  47. *
  48. * @return void
  49. */
  50. public function tearDown() {
  51. parent::tearDown();
  52. unset($this->MediaView);
  53. }
  54. /**
  55. * testRender method
  56. *
  57. * @return void
  58. */
  59. public function testRender() {
  60. $vars = array(
  61. 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
  62. 'id' => 'test_asset.css'
  63. );
  64. $this->MediaView->viewVars = $vars;
  65. $this->MediaView->response->expects($this->once())
  66. ->method('disableCache');
  67. $this->MediaView->response->expects($this->once())
  68. ->method('file')
  69. ->with(
  70. $vars['path'] . $vars['id'],
  71. array('name' => null, 'download' => null)
  72. );
  73. $this->MediaView->response->expects($this->once())
  74. ->method('send');
  75. $result = $this->MediaView->render();
  76. $this->assertTrue($result);
  77. }
  78. /**
  79. * Test render() when caching is on.
  80. *
  81. * @return void
  82. */
  83. public function testRenderCachingAndName() {
  84. $vars = array(
  85. 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
  86. 'id' => 'test_asset.css',
  87. 'cache' => '+1 day',
  88. 'name' => 'something_special',
  89. 'download' => true,
  90. );
  91. $this->MediaView->viewVars = $vars;
  92. $this->MediaView->response->expects($this->never())
  93. ->method('disableCache');
  94. $this->MediaView->response->expects($this->once())
  95. ->method('cache')
  96. ->with($this->anything(), $vars['cache']);
  97. $this->MediaView->response->expects($this->once())
  98. ->method('file')
  99. ->with(
  100. $vars['path'] . $vars['id'],
  101. array(
  102. 'name' => 'something_special.css',
  103. 'download' => true
  104. )
  105. );
  106. $this->MediaView->response->expects($this->once())
  107. ->method('send');
  108. $result = $this->MediaView->render();
  109. $this->assertTrue($result);
  110. }
  111. /**
  112. * Test downloading files with UPPERCASE extensions.
  113. *
  114. * @return void
  115. */
  116. public function testRenderUpperExtension() {
  117. $this->MediaView->viewVars = array(
  118. 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
  119. 'id' => 'test_2.JPG'
  120. );
  121. $this->MediaView->response->expects($this->any())
  122. ->method('type')
  123. ->with('jpg')
  124. ->will($this->returnArgument(0));
  125. $this->MediaView->response->expects($this->at(0))
  126. ->method('send')
  127. ->will($this->returnValue(true));
  128. $this->MediaView->render();
  129. }
  130. }