returnResponse(true);
$this->_response = new Zend_Controller_Response_Http();
Setup::$front->setResponse($this->_response);
$users = new Users();
$user = $users->createRow();
$user->id = 23;
$user->role = User::ROLE_ADMIN;
$user->username = 'testadmin';
Zend_Registry::set('user', $user);
}
/**
* @expectedException Monkeys_AccessDeniedException
*/
public function testIndexGuestUserAction()
{
Zend_Registry::get('user')->role = User::ROLE_GUEST;
Setup::$front->setRequest(new TestRequest('/messageusers'));
Setup::dispatch();
}
/**
* @expectedException Monkeys_AccessDeniedException
*/
public function testIndexRegisteredUserAction()
{
Zend_Registry::get('user')->role = User::ROLE_REGISTERED;
Setup::$front->setRequest(new TestRequest('/messageusers'));
Setup::dispatch();
}
public function testIndexAction()
{
Setup::$front->setRequest(new TestRequest('/messageusers'));
Setup::dispatch();
$this->assertContains('', $this->_response->getBody());
}
public function testSaveActionWithEmptySubject()
{
$_POST = array(
'messageType' => 'rich',
'subject' => '',
'cc' => '',
'bodyPlain' => '',
'bodyHTML' => 'Hello world',
);
Setup::$front->setRequest(new TestRequest('/messageusers/send'));
Setup::dispatch();
$this->assertContains('Value is empty, but a non-empty value is required', $this->_response->getBody());
}
public function testSaveActionWithBadCC()
{
$_POST = array(
'messageType' => 'rich',
'subject' => 'whateva',
'cc' => 'asdfdf',
'bodyPlain' => '',
'bodyHTML' => 'Hello world',
);
Setup::$front->setRequest(new TestRequest('/messageusers/send'));
Setup::dispatch();
$this->assertContains('CC field must be a comma-separated list of valid E-mails', $this->_response->getBody());
}
/**
* @expectedException Monkeys_AccessDeniedException
*/
public function testSaveGuestUser()
{
Zend_Registry::get('user')->role = User::ROLE_GUEST;
Setup::$front->setRequest(new TestRequest('/messageusers/send'));
Setup::dispatch();
}
/**
* @expectedException Monkeys_AccessDeniedException
*/
public function testSaveRegisteredUser()
{
Zend_Registry::get('user')->role = User::ROLE_REGISTERED;
Setup::$front->setRequest(new TestRequest('/messageusers/send'));
Setup::dispatch();
}
public function testSaveSuccessfull()
{
$_POST = array(
'messageType' => 'rich',
'subject' => 'whateva',
'cc' => 'one@mailinator.com, two@mailinator.com',
'bodyPlain' => '',
'bodyHTML' => 'Hello world',
);
Setup::$front->setRequest(new TestRequest('/messageusers/send'));
Setup::$mockLogger->events = array();
try {
Setup::dispatch();
} catch (Zend_Controller_Response_Exception $e) {
// I still don't know how to avoid the "headers already sent" problem here...
}
$lastLog = array_pop(Setup::$mockLogger->events);
$this->assertEquals("redirected to ''", $lastLog['message']);
}
}