123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /**
- * MediaViewTest file
- *
- * PHP 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @package Cake.Test.Case.View
- * @since CakePHP(tm) v 1.2.0.4206
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- App::uses('Controller', 'Controller');
- App::uses('MediaView', 'View');
- App::uses('CakeResponse', 'Network');
- /**
- * MediaViewTest class
- *
- * @package Cake.Test.Case.View
- */
- class MediaViewTest extends CakeTestCase {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->MediaView = new MediaView();
- $this->MediaView->response = $this->getMock('CakeResponse', array(
- 'cache',
- 'type',
- 'disableCache',
- 'file',
- 'send',
- 'compress',
- ));
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->MediaView);
- }
- /**
- * testRender method
- *
- * @return void
- */
- public function testRender() {
- $vars = array(
- 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
- 'id' => 'test_asset.css'
- );
- $this->MediaView->viewVars = $vars;
- $this->MediaView->response->expects($this->once())
- ->method('disableCache');
- $this->MediaView->response->expects($this->once())
- ->method('file')
- ->with(
- $vars['path'] . $vars['id'],
- array('name' => null, 'download' => null)
- );
- $this->MediaView->response->expects($this->once())
- ->method('send');
- $result = $this->MediaView->render();
- $this->assertTrue($result);
- }
- /**
- * Test render() when caching is on.
- *
- * @return void
- */
- public function testRenderCachingAndName() {
- $vars = array(
- 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
- 'id' => 'test_asset.css',
- 'cache' => '+1 day',
- 'name' => 'something_special',
- 'download' => true,
- );
- $this->MediaView->viewVars = $vars;
- $this->MediaView->response->expects($this->never())
- ->method('disableCache');
- $this->MediaView->response->expects($this->once())
- ->method('cache')
- ->with($this->anything(), $vars['cache']);
- $this->MediaView->response->expects($this->once())
- ->method('file')
- ->with(
- $vars['path'] . $vars['id'],
- array(
- 'name' => 'something_special.css',
- 'download' => true
- )
- );
- $this->MediaView->response->expects($this->once())
- ->method('send');
- $result = $this->MediaView->render();
- $this->assertTrue($result);
- }
- /**
- * Test downloading files with UPPERCASE extensions.
- *
- * @return void
- */
- public function testRenderUpperExtension() {
- $this->MediaView->viewVars = array(
- 'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
- 'id' => 'test_2.JPG'
- );
- $this->MediaView->response->expects($this->any())
- ->method('type')
- ->with('jpg')
- ->will($this->returnArgument(0));
- $this->MediaView->response->expects($this->at(0))
- ->method('send')
- ->will($this->returnValue(true));
- $this->MediaView->render();
- }
- }
|