unit test

This commit is contained in:
Claude 2013-02-06 19:55:46 +01:00
parent 6b5054a436
commit 1bc81304cb
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?php
/**
* Class and Function List:
* Function list:
* - __construct()
* - index()
* Classes list:
* - Unittest extends CI_Controller
*/
class Unittest extends CI_Controller
{
function __construct()
{
parent::__construct();
//protection
if ($_SERVER['HTTP_HOST'] != 'stikked')
{
exit;
}
}
function index()
{
$this->load->library('unit_test');
$this->load->model('pastes');
//self test
$test = 1 + 1;
$expected_result = 2;
$test_name = 'Self test: Adds one plus one';
$this->unit->run($test, $expected_result, $test_name);
//manipulation: create paste
$_POST['code'] = '<?php echo "hello world!";';
$_POST['lang'] = 'php';
$_POST['title'] = 'hello world';
$_POST['name'] = 'stikkeduser';
$pid = $this->pastes->createPaste();
//paste created, has pid
$test = $pid;
$expected_result = 'is_string';
$test_name = 'Create paste, has pid';
$this->unit->run($test, $expected_result, $test_name);
$pid = str_replace('view/', '', $pid);
//manipulation: delete paste
$this->pastes->delete_paste($pid);
//report
echo $this->unit->report();
}
}

View File

@ -15,6 +15,7 @@
* - getTrends() * - getTrends()
* - getSpamLists() * - getSpamLists()
* - cron() * - cron()
* - delete_paste()
* - random_paste() * - random_paste()
* Classes list: * Classes list:
* - Pastes extends CI_Model * - Pastes extends CI_Model
@ -490,6 +491,13 @@ class Pastes extends CI_Model
return; return;
} }
function delete_paste($pid)
{
$this->db->where('pid', $pid);
$this->db->delete('pastes');
return;
}
function random_paste() function random_paste()
{ {
$this->load->library('process'); $this->load->library('process');