CommunityID/tests/modules/default/controllers/HistoryControllerTests.php

92 lines
2.7 KiB
PHP
Raw Normal View History

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 HistoryControllerTests extends PHPUnit_Framework_TestCase
{
private $_response;
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:08:50 +00:00
$user = $users->createRow();
$user->id = 23;
2019-07-17 20:19:00 +00:00
$user->role = Users_Model_User::ROLE_REGISTERED;
2019-07-17 20:08:50 +00:00
$user->username = 'testuser';
Zend_Registry::set('user', $user);
}
public function testIndexGuestUserAction()
{
2019-07-17 20:16:19 +00:00
Zend_Registry::get('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('/history'));
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('/history'));
Application::dispatch();
2019-07-17 20:08:50 +00:00
$this->assertContains('COMMID.history', $this->_response->getBody());
}
public function testListAction()
{
$request = new TestRequest('/history/list?startIndex=0&results=15');
$request->setHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
2019-07-17 20:16:19 +00:00
Application::$front->setRequest($request);
Application::dispatch();
2019-07-17 20:08:50 +00:00
$this->assertRegExp(
'#\{("__className":"stdClass",)?"recordsReturned":\d+,"totalRecords":\d+,"startIndex":"\d+",("sort":null,)?"dir":"asc","records":\[.*\]\}#',
$this->_response->getBody()
);
}
/**
* Weak test, till I set up a mock db obj to avoid touching the db
*/
public function testClearAction()
{
$request = new TestRequest('/history/clear');
$request->setHeader('X_REQUESTED_WITH', 'XMLHttpRequest');
2019-07-17 20:16:19 +00:00
Application::$front->setRequest($request);
Application::dispatch();
2019-07-17 20:08:50 +00:00
$this->assertRegExp(
'{"code":200}',
$this->_response->getBody()
);
}
2019-07-17 20:19:00 +00:00
public function tearDown()
{
// I know this is done again in setUp(), but if I don't do it here too,
// hell breaks appart
Application::cleanUp();
}
2019-07-17 20:08:50 +00:00
}