Created
August 9, 2012 14:53
-
-
Save lsiden/3304880 to your computer and use it in GitHub Desktop.
Test AnnouncementsController::isAuthorized()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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