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