Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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