2019-07-17 20:08:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
|
|
|
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
|
|
|
* @author Keyboard Monkey Ltd
|
|
|
|
* @since CommunityID 0.9
|
|
|
|
* @package CommunityID
|
|
|
|
* @packager Keyboard Monkeys
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once dirname(__FILE__) . '/../../../TestHarness.php';
|
|
|
|
|
|
|
|
class MessageusersControllerTests extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private $_response;
|
2019-07-17 20:19:00 +00:00
|
|
|
private $_user;
|
2019-07-17 20:08:50 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
TestHarness::setUp();
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->returnResponse(true);
|
2019-07-17 20:08:50 +00:00
|
|
|
$this->_response = new Zend_Controller_Response_Http();
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setResponse($this->_response);
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$users = new Users_Model_Users();
|
2019-07-17 20:19:00 +00:00
|
|
|
$this->_user = $users->createRow();
|
|
|
|
$this->_user->id = 23;
|
|
|
|
$this->_user->role = Users_Model_User::ROLE_ADMIN;
|
|
|
|
$this->_user->username = 'testadmin';
|
|
|
|
Zend_Registry::set('user', $this->_user);
|
2019-07-17 20:08:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexGuestUserAction()
|
|
|
|
{
|
2019-07-17 20:19:00 +00:00
|
|
|
$this->_user->role = Users_Model_User::ROLE_GUEST;
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers'));
|
2019-07-17 20:19:00 +00:00
|
|
|
try {
|
|
|
|
Application::dispatch();
|
|
|
|
} catch (Monkeys_AccessDeniedException $e) {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fail('Expected Monkeys_AccessDeniedException was not raised');
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexRegisteredUserAction()
|
|
|
|
{
|
2019-07-17 20:19:00 +00:00
|
|
|
$this->_user->role = Users_Model_User::ROLE_REGISTERED;
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers'));
|
2019-07-17 20:19:00 +00:00
|
|
|
try {
|
|
|
|
Application::dispatch();
|
|
|
|
} catch (Monkeys_AccessDeniedException $e) {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fail('Expected Monkeys_AccessDeniedException was not raised');
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIndexAction()
|
|
|
|
{
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers'));
|
|
|
|
Application::dispatch();
|
2019-07-17 20:08:50 +00:00
|
|
|
|
|
|
|
$this->assertContains('</form>', $this->_response->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveActionWithEmptySubject()
|
|
|
|
{
|
|
|
|
$_POST = array(
|
|
|
|
'messageType' => 'rich',
|
|
|
|
'subject' => '',
|
|
|
|
'cc' => '',
|
|
|
|
'bodyPlain' => '',
|
|
|
|
'bodyHTML' => 'Hello <strong>world</strong>',
|
|
|
|
);
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers/send'));
|
|
|
|
Application::dispatch();
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$this->assertContains('Value is required and can\'t be empty', $this->_response->getBody());
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveActionWithBadCC()
|
|
|
|
{
|
|
|
|
$_POST = array(
|
|
|
|
'messageType' => 'rich',
|
|
|
|
'subject' => 'whateva',
|
|
|
|
'cc' => 'asdfdf',
|
|
|
|
'bodyPlain' => '',
|
|
|
|
'bodyHTML' => 'Hello <strong>world</strong>',
|
|
|
|
);
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers/send'));
|
|
|
|
Application::dispatch();
|
2019-07-17 20:08:50 +00:00
|
|
|
|
|
|
|
$this->assertContains('CC field must be a comma-separated list of valid E-mails', $this->_response->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveGuestUser()
|
|
|
|
{
|
2019-07-17 20:19:00 +00:00
|
|
|
$this->_user->role = Users_Model_User::ROLE_GUEST;
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers/send'));
|
2019-07-17 20:19:00 +00:00
|
|
|
try {
|
|
|
|
Application::dispatch();
|
|
|
|
} catch (Monkeys_AccessDeniedException $e) {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fail('Expected Monkeys_AccessDeniedException was not raised');
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveRegisteredUser()
|
|
|
|
{
|
2019-07-17 20:19:00 +00:00
|
|
|
$this->_user->role = Users_Model_User::ROLE_REGISTERED;
|
2019-07-17 20:08:50 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers/send'));
|
2019-07-17 20:19:00 +00:00
|
|
|
try {
|
|
|
|
Application::dispatch();
|
|
|
|
} catch (Monkeys_AccessDeniedException $e) {
|
|
|
|
$this->assertTrue(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fail('Expected Monkeys_AccessDeniedException was not raised');
|
2019-07-17 20:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveSuccessfull()
|
|
|
|
{
|
|
|
|
$_POST = array(
|
|
|
|
'messageType' => 'rich',
|
|
|
|
'subject' => 'whateva',
|
|
|
|
'cc' => 'one@mailinator.com, two@mailinator.com',
|
|
|
|
'bodyPlain' => '',
|
|
|
|
'bodyHTML' => 'Hello <strong>world</strong>',
|
|
|
|
);
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::$front->setRequest(new TestRequest('/messageusers/send'));
|
|
|
|
Application::$mockLogger->events = array();
|
2019-07-17 20:08:50 +00:00
|
|
|
try {
|
2019-07-17 20:16:19 +00:00
|
|
|
Application::dispatch();
|
2019-07-17 20:08:50 +00:00
|
|
|
} catch (Zend_Controller_Response_Exception $e) {
|
|
|
|
// I still don't know how to avoid the "headers already sent" problem here...
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$lastLog = array_pop(Application::$mockLogger->events);
|
2019-07-17 20:08:50 +00:00
|
|
|
$this->assertEquals("redirected to ''", $lastLog['message']);
|
|
|
|
}
|
|
|
|
}
|