2010-04-13 15:34:13 -04:30
|
|
|
<?php
|
|
|
|
/**
|
2011-10-10 23:18:48 +02:00
|
|
|
* MediaViewTest file
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
2012-04-26 19:49:18 -07:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 20:59:49 +09:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
2010-10-03 12:31:21 -04:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 21:22:51 +09:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 12:31:21 -04:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
2013-02-08 20:59:49 +09:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-26 19:49:18 -07:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.View
|
2010-04-13 15:34:13 -04:30
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2013-05-31 00:11:14 +02:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-04-13 15:34:13 -04:30
|
|
|
*/
|
2010-12-10 01:53:27 -04:30
|
|
|
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('MediaView', 'View');
|
|
|
|
App::uses('CakeResponse', 'Network');
|
2010-04-13 15:34:13 -04:30
|
|
|
|
|
|
|
/**
|
2010-10-03 23:30:02 -04:30
|
|
|
* MediaViewTest class
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.View
|
2010-04-13 15:34:13 -04:30
|
|
|
*/
|
|
|
|
class MediaViewTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
2010-09-25 21:36:49 -04:00
|
|
|
* setUp method
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function setUp() {
|
2010-09-25 21:36:49 -04:00
|
|
|
parent::setUp();
|
2012-07-11 01:33:40 +05:30
|
|
|
$this->MediaView = new MediaView();
|
|
|
|
$this->MediaView->response = $this->getMock('CakeResponse', array(
|
2012-11-24 15:44:52 -05:00
|
|
|
'cache',
|
2012-07-11 01:33:40 +05:30
|
|
|
'type',
|
2012-11-24 16:29:39 -05:00
|
|
|
'disableCache',
|
|
|
|
'file',
|
|
|
|
'send',
|
|
|
|
'compress',
|
2012-07-11 01:33:40 +05:30
|
|
|
));
|
2010-04-13 15:34:13 -04:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-11 07:50:54 -07:00
|
|
|
* tearDown method
|
2010-04-13 15:34:13 -04:30
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function tearDown() {
|
2010-09-25 21:36:49 -04:00
|
|
|
parent::tearDown();
|
2010-04-13 15:34:13 -04:30
|
|
|
unset($this->MediaView);
|
2010-10-03 23:30:02 -04:30
|
|
|
}
|
|
|
|
|
2010-04-13 15:34:13 -04:30
|
|
|
/**
|
|
|
|
* testRender method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testRender() {
|
2012-11-24 16:29:39 -05:00
|
|
|
$vars = array(
|
2012-03-15 22:50:05 -04:00
|
|
|
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
|
2012-07-11 01:33:40 +05:30
|
|
|
'id' => 'test_asset.css'
|
2010-10-03 23:30:02 -04:30
|
|
|
);
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->viewVars = $vars;
|
2011-02-27 06:31:15 +05:30
|
|
|
|
|
|
|
$this->MediaView->response->expects($this->once())
|
2012-11-24 16:29:39 -05:00
|
|
|
->method('disableCache');
|
2011-02-27 06:31:15 +05:30
|
|
|
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->response->expects($this->once())
|
|
|
|
->method('file')
|
|
|
|
->with(
|
|
|
|
$vars['path'] . $vars['id'],
|
|
|
|
array('name' => null, 'download' => null)
|
|
|
|
);
|
2011-04-24 23:31:44 -04:00
|
|
|
|
2014-02-06 02:41:36 +05:30
|
|
|
$this->MediaView->render();
|
2011-04-24 23:31:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-24 16:29:39 -05:00
|
|
|
* Test render() when caching is on.
|
2011-04-24 23:31:44 -04:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-11-24 16:29:39 -05:00
|
|
|
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,
|
2011-04-24 23:31:44 -04:00
|
|
|
);
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->viewVars = $vars;
|
2011-04-24 23:31:44 -04:00
|
|
|
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->response->expects($this->never())
|
|
|
|
->method('disableCache');
|
2012-07-11 01:33:40 +05:30
|
|
|
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->response->expects($this->once())
|
|
|
|
->method('cache')
|
|
|
|
->with($this->anything(), $vars['cache']);
|
2011-04-24 23:31:44 -04:00
|
|
|
|
2012-11-24 16:29:39 -05:00
|
|
|
$this->MediaView->response->expects($this->once())
|
|
|
|
->method('file')
|
|
|
|
->with(
|
|
|
|
$vars['path'] . $vars['id'],
|
|
|
|
array(
|
|
|
|
'name' => 'something_special.css',
|
|
|
|
'download' => true
|
|
|
|
)
|
|
|
|
);
|
2011-04-24 23:31:44 -04:00
|
|
|
|
2014-02-06 02:41:36 +05:30
|
|
|
$this->MediaView->render();
|
2010-04-13 15:34:13 -04:30
|
|
|
}
|
2011-06-23 12:48:06 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test downloading files with UPPERCASE extensions.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-08 01:08:04 +05:30
|
|
|
public function testRenderUpperExtension() {
|
2011-06-23 12:48:06 -07:00
|
|
|
$this->MediaView->viewVars = array(
|
2012-03-15 22:50:05 -04:00
|
|
|
'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
|
2012-07-11 01:33:40 +05:30
|
|
|
'id' => 'test_2.JPG'
|
2012-02-08 01:08:04 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
$this->MediaView->response->expects($this->any())
|
|
|
|
->method('type')
|
|
|
|
->with('jpg')
|
|
|
|
->will($this->returnArgument(0));
|
|
|
|
|
|
|
|
$this->MediaView->render();
|
|
|
|
}
|
|
|
|
|
2010-04-13 15:34:13 -04:30
|
|
|
}
|