Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 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
		$result = $this->MediaView->render();
84
		$this->assertTrue($result);
85
	}
86
 
87
/**
88
 * Test render() when caching is on.
89
 *
90
 * @return void
91
 */
92
	public function testRenderCachingAndName() {
93
		$vars = array(
94
			'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,
95
			'id' => 'test_asset.css',
96
			'cache' => '+1 day',
97
			'name' => 'something_special',
98
			'download' => true,
99
		);
100
		$this->MediaView->viewVars = $vars;
101
 
102
		$this->MediaView->response->expects($this->never())
103
			->method('disableCache');
104
 
105
		$this->MediaView->response->expects($this->once())
106
			->method('cache')
107
			->with($this->anything(), $vars['cache']);
108
 
109
		$this->MediaView->response->expects($this->once())
110
			->method('file')
111
			->with(
112
				$vars['path'] . $vars['id'],
113
				array(
114
					'name' => 'something_special.css',
115
					'download' => true
116
				)
117
			);
118
 
119
		$this->MediaView->response->expects($this->once())
120
			->method('send');
121
 
122
		$result = $this->MediaView->render();
123
		$this->assertTrue($result);
124
	}
125
 
126
/**
127
 * Test downloading files with UPPERCASE extensions.
128
 *
129
 * @return void
130
 */
131
	public function testRenderUpperExtension() {
132
		$this->MediaView->viewVars = array(
133
			'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,
134
			'id' => 'test_2.JPG'
135
		);
136
 
137
		$this->MediaView->response->expects($this->any())
138
			->method('type')
139
			->with('jpg')
140
			->will($this->returnArgument(0));
141
 
142
		$this->MediaView->response->expects($this->at(0))
143
			->method('send')
144
			->will($this->returnValue(true));
145
 
146
		$this->MediaView->render();
147
	}
148
 
149
}