Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Test AnnouncementsController::isAuthorized()
<?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() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.