[eluser]chobo[/eluser]
I got Simpletest to work, but I'm having trouble setting a session variable in a test for testing a function. When I try to set a session variable I get the following error.
Code:
Unexpected PHP error [Cannot modify header information - headers already sent] severity [E_WARNING] in [S:\Site\CodeIgniter_1.5.4\system\libraries\Session.php line 282]
Test File Code:
Code:
<?php
// test controller
require_once APPPATH . 'libraries/SimpleAuth.php';
// When run as a whole the test cases in the test suite must have unique names
class AuthTest extends UnitTestCase
{
public function __construct()
{
parent::__construct();
$this->UnitTestCase("Authentication Tests");
}
/*
* Test is CI object is being referenced
*
*/
public function testCIObject()
{
$auth = new SimpleAuth();
$this->assertNotNull($auth->obj, 'CI Global object (obj) is null');
}
/*
* Tests the login check
*
*/
public function testLoginCheck()
{
$auth = new SimpleAuth();
$auth->obj->session->set_userdata('logged_in', true); // Throws error on this line
$this->assertEqual($auth->isLoggedIn(), true);
}
}
?>
Part of SimpleAuth library I am testing
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class SimpleAuth {
public $obj;
/*
* Get global CI instance
*
*/
public function __construct()
{
$this->obj =& get_instance();
}
//-------------------------------------- Login methods -----------------------/
/*
* Checks to see if user is logged in
*
* @return boolean
*/
public function isLoggedIn()
{
if ($this->obj->session) {
if ($this->obj->session->userdata('logged_in')) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}