public
Last active

Test AnnouncementsController::isAuthorized()

  • Download Gist
TestAnnouncementsController.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?php
App::uses('AnnouncementsController', 'Controller');
 
class MockAnnouncementsController extends AnnouncementsController {
var $name = 'Announcements';
var $autoRender = false;
 
/*
function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
}
 
function render($action = null, $layout = null, $file = null) {
$this->renderedAction = $action;
}
 
function _stop($status = 0) {
$this->stopped = $status;
}
*/
 
function login($username, $password='') {
$User = ClassRegistry::init('User');
$user = $User->find('first', array('conditions' => array('username' => $username)));
$this->Auth->login($user);
}
}
 
class AnnouncementsControllerTest extends ControllerTestCase {
 
public $fixtures = array(
'app.user',
'app.logon',
'app.role',
'app.role_user',
'app.equipment',
'app.equipment_type',
'app.equipment_users',
'app.quicklist',
'app.timezone',
'app.announcement',
);
 
public function setUp() {
parent::setUp();
}
 
public function tearDown() {
// put anything needed here
 
parent::tearDown();
}
 
public function testIsAuthorized() {
$controller = new MockAnnouncementsController;
$controller->constructClasses();
$controller->login('admin');
$this->assertTrue($controller->isAuthorized());
 
$controller = new MockAnnouncementsController;
$controller->constructClasses();
$controller->login('user2');
$this->assertFalse($controller->isAuthorized());
}
 
public function testAdd() {
}
 
public function testEdit() {
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.