Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 1
<?php
2
/**
3
 * ControllerAuthorizeTest file
4
 *
5
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
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://cakephp.org CakePHP(tm) Project
14
 * @package       Cake.Test.Case.Controller.Component.Auth
15
 * @since         CakePHP(tm) v 2.0
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
 
19
App::uses('Controller', 'Controller');
20
App::uses('ControllerAuthorize', 'Controller/Component/Auth');
21
App::uses('CakeRequest', 'Network');
22
App::uses('CakeResponse', 'Network');
23
 
24
/**
25
 * Class ControllerAuthorizeTest
26
 *
27
 * @package       Cake.Test.Case.Controller.Component.Auth
28
 */
29
class ControllerAuthorizeTest extends CakeTestCase {
30
 
31
/**
32
 * setup
33
 *
34
 * @return void
35
 */
36
	public function setUp() {
37
		parent::setUp();
38
		$this->controller = $this->getMock('Controller', array('isAuthorized'), array(), '', false);
39
		$this->components = $this->getMock('ComponentCollection');
40
		$this->components->expects($this->any())
41
			->method('getController')
42
			->will($this->returnValue($this->controller));
43
 
44
		$this->auth = new ControllerAuthorize($this->components);
45
	}
46
 
47
/**
48
 * @expectedException PHPUnit_Framework_Error
49
 * @return void
50
 */
51
	public function testControllerTypeError() {
52
		$this->auth->controller(new StdClass());
53
	}
54
 
55
/**
56
 * @expectedException CakeException
57
 * @return void
58
 */
59
	public function testControllerErrorOnMissingMethod() {
60
		$this->auth->controller(new Controller());
61
	}
62
 
63
/**
64
 * test failure
65
 *
66
 * @return void
67
 */
68
	public function testAuthorizeFailure() {
69
		$user = array();
70
		$request = new CakeRequest('/posts/index', false);
71
		$this->assertFalse($this->auth->authorize($user, $request));
72
	}
73
 
74
/**
75
 * test isAuthorized working.
76
 *
77
 * @return void
78
 */
79
	public function testAuthorizeSuccess() {
80
		$user = array('User' => array('username' => 'mark'));
81
		$request = new CakeRequest('/posts/index', false);
82
 
83
		$this->controller->expects($this->once())
84
			->method('isAuthorized')
85
			->with($user)
86
			->will($this->returnValue(true));
87
 
88
		$this->assertTrue($this->auth->authorize($user, $request));
89
	}
90
 
91
}