Commit 6591c934 by Timothy J Warren

Mysql compatability tests and fixes

parent 98c55a78
......@@ -304,7 +304,7 @@ class Todo {
public function validate_pass()
{
$err = array();
$user = $this->CI->session->userdata('uid');
$user = (int) $this->CI->session->userdata('uid');
$pass = $this->CI->input->post('pass');
$pass1 = $this->CI->input->post('pass1');
$old_pass = $this->CI->input->post('old_pass');
......@@ -315,6 +315,7 @@ class Todo {
//Check for current password in the database
$user_check = $this->CI->db->select('password')
->from('user')
->where('id', $user)
->get();
$row = $user_check->row();
......@@ -663,14 +664,12 @@ class Todo {
{
$query = $this->CI->db->select('name')
->from('group')
->where('id', $group_id)
->where('id', (int) $group_id)
->get();
$qrow = $query->row();
$name = $qrow->name;
return $name;
return $qrow->name;
}
......
......@@ -889,6 +889,7 @@ class Task_model extends CI_Model {
//Get the list of statuses
$query = $this->db->select('id, value as desc')
->from('status')
->order_by('id')
->get();
foreach($query->result() as $row)
......
......@@ -17,6 +17,9 @@ class Welcome extends CIU_Controller {}
/**
* Base TestSuite
*
* @method bool assertEquals(mixed $expected, mixed $actual)
* @method bool assertNotEquals(mixed $expected, mixed $actual)
*/
class Todo_TestCase extends CIUnit_TestCase {
......
<?php
/**
* Split of some methods that don't require database from TodoLibTest
* Not having to load fixtures should make these run a lot faster
*/
class TodoLibNoFixturesTest extends Todo_TestCase {
public function setUp()
{
parent::setUp();
$this->CI->load->library('todo');
}
public function testCryptPass()
{
$expected = '$2y$10$qW8HlbNDNEJx1GqmYW9APOYOqo5apV8stjNcV/xunsvnjTYJBTc0m';
$actual = $this->CI->todo->crypt_pass('guest');
$this->assertNotEquals($expected, $actual,
"Password has should be different every time it is used because of Bcrypt salt");
}
public function dataKanjiNum()
{
return [
'non-numeric' => [
'input' => 'string',
'expected' => '〇'
],
'zero' => [
'input' => 0,
'expected' => '〇'
],
'one' => [
'input' => 1,
'expected' => '一'
],
'tens' => [
'input' => 34,
'expected' => '三十四'
],
'hundreds' => [
'input' => 968,
'expected' => '九百六十八'
],
'thousands' => [
'input' => 1024,
'expected' => '千二十四'
],
'ten thousands' => [
'input' => 11275,
'expected' => '万千二百七十五'
],
'hundred thousands' => [
'input' => 658753,
'expected' => '六十五万八千七百五十三'
],
'millions' => [
'input' => 9876543,
'expected' => '九百八十七万六千五百四十三'
],
'ten_millions' => [
'input' => 98765432,
'expected' => '九千八百七十六万五千四百三十二'
],
'hundred_millions' => [
'input' => 987654321,
'expected' => '九億八千七百六十五万四千三百二十一'
]
];
}
/**
* @dataProvider dataKanjiNum
*/
public function testKanjiNum($input, $expected)
{
$actual = $this->CI->todo->kanji_num($input);
$this->assertEquals($expected, $actual);
}
public function dataRedirect303()
{
return [
'full url redirect' => [
'url' => 'http://www.example.com',
'headers' => [
array (
'HTTP/1.1 303 See Other',
true,
),
array (
'Location:http://www.example.com',
true,
)
]
],
'route redirect' => [
'url' => 'task/list',
'headers' => [
array (
'HTTP/1.1 303 See Other',
true,
),
array (
'Location:https://todo.timshomepage.net/task/list',
true,
)
]
]
];
}
/**
* @dataProvider dataRedirect303
*/
public function testRedirect303($url, $headers)
{
$this->CI->todo->redirect_303($url);
$actual = $this->CI->output->get_headers();
$this->assertEquals($headers, $actual);
}
}
// End of TodoLibNoFixturesTest
\ No newline at end of file
......@@ -4,8 +4,8 @@ class TodoLibTest extends Todo_TestCase {
protected $tables = [
'todo_priority' => 'todo_priority',
'todo_user' => 'todo_user',
'todo_group' => 'todo_group',
'todo_user' => 'todo_user',
'todo_category' => 'todo_category',
'todo_group_users_link' => 'todo_group_users_link',
'todo_user_friend_link' => 'todo_user_friend_link',
......@@ -15,140 +15,9 @@ class TodoLibTest extends Todo_TestCase {
{
parent::setUp();
$this->CI->load->library('todo');
}
public function testGetUserFromId()
{
$expected = 'timw4mail';
$actual = $this->CI->todo->get_user_from_id(1);
$this->assertEquals($expected, $actual);
}
public function testCryptPass()
{
$expected = '$2y$10$qW8HlbNDNEJx1GqmYW9APOYOqo5apV8stjNcV/xunsvnjTYJBTc0m';
$actual = $this->CI->todo->crypt_pass('guest');
$this->assertNotEquals($expected, $actual,
"Password has should be different every time it is used because of Bcrypt salt");
}
public function dataKanjiNum()
{
return [
'non-numeric' => [
'input' => 'string',
'expected' => '〇'
],
'zero' => [
'input' => 0,
'expected' => '〇'
],
'one' => [
'input' => 1,
'expected' => '一'
],
'tens' => [
'input' => 34,
'expected' => '三十四'
],
'hundreds' => [
'input' => 968,
'expected' => '九百六十八'
],
'thousands' => [
'input' => 1024,
'expected' => '千二十四'
],
'ten thousands' => [
'input' => 11275,
'expected' => '万千二百七十五'
],
'hundred thousands' => [
'input' => 658753,
'expected' => '六十五万八千七百五十三'
],
'millions' => [
'input' => 9876543,
'expected' => '九百八十七万六千五百四十三'
],
'ten_millions' => [
'input' => 98765432,
'expected' => '九千八百七十六万五千四百三十二'
],
'hundred_millions' => [
'input' => 987654321,
'expected' => '九億八千七百六十五万四千三百二十一'
]
];
}
/**
* @dataProvider dataKanjiNum
*/
public function testKanjiNum($input, $expected)
{
$actual = $this->CI->todo->kanji_num($input);
$this->assertEquals($expected, $actual);
}
public function dataRedirect303()
{
return [
'full url redirect' => [
'url' => 'http://www.example.com',
'headers' => [
array (
'HTTP/1.1 303 See Other',
true,
),
array (
'Location:http://www.example.com',
true,
)
]
],
'route redirect' => [
'url' => 'task/list',
'headers' => [
array (
'HTTP/1.1 303 See Other',
true,
),
array (
'Location:https://todo.timshomepage.net/task/list',
true,
)
]
]
];
}
/**
* @dataProvider dataRedirect303
*/
public function testRedirect303($url, $headers)
{
$this->CI->todo->redirect_303($url);
$actual = $this->CI->output->get_headers();
$this->assertEquals($headers, $actual);
}
public function testGetFriendRequests()
{
$this->create_session();
$this->CI->session->set_userdata([
'username' => 'timw4mail',
'uid' => 1
]);
$expected = 1;
$actual = $this->CI->todo->get_friend_requests();
$this->assertEquals($expected, $actual);
// Hack to fix problem with CodeIgniter in this specific context
if ($this->CI->db->conn_id === FALSE) $this->CI->db->db_connect();
}
public function dataValidatePass()
......@@ -196,6 +65,7 @@ class TodoLibTest extends Todo_TestCase {
'uid' => 3
]);
$_POST = [];
$_POST = $post;
$actual = $this->CI->todo->validate_pass();
......@@ -203,6 +73,29 @@ class TodoLibTest extends Todo_TestCase {
$this->assertEquals($expected, $actual);
}
public function testGetUserFromId()
{
$expected = 'timw4mail';
$actual = $this->CI->todo->get_user_from_id(1);
$this->assertEquals($expected, $actual);
}
public function testGetFriendRequests()
{
$this->create_session();
$this->CI->session->set_userdata([
'username' => 'timw4mail',
'uid' => 1
]);
$expected = 1;
$actual = $this->CI->todo->get_friend_requests();
$this->assertEquals($expected, $actual);
}
public function testCategoryList()
{
$this->create_session();
......@@ -435,10 +328,10 @@ class TodoLibTest extends Todo_TestCase {
'group_id' => 11,
'expected' => 'timw4mail'
],
[
/*[
'group_id' => 0,
'expected' => 'global'
],
],*/
[
'group_id' => 62,
'expected' => 'shared'
......
......@@ -514,20 +514,20 @@ class TaskModelTest extends Todo_TestCase {
'Don\'t pass status id' => [
'task_id' => 97,
'status_id' => NULL,
'expected' => T5 . '<option value="3" selected="selected">In Progress</option>'. NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5">Canceled</option>' . NL .
'expected' => T5 . '<option value="1">Created</option>' . NL .
T5 . '<option value="2">Completed</option>' . NL .
T5 . '<option value="1">Created</option>' . NL
T5 . '<option value="3" selected="selected">In Progress</option>'. NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5">Canceled</option>' . NL
],
'Pass status id' => [
'task_id' => 155,
'status_id' => 5,
'expected' => T5. '<option value="3">In Progress</option>'. NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5" selected="selected">Canceled</option>' . NL .
'expected' => T5 . '<option value="1">Created</option>' . NL .
T5 . '<option value="2">Completed</option>' . NL .
T5 . '<option value="1">Created</option>' . NL
T5. '<option value="3">In Progress</option>'. NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5" selected="selected">Canceled</option>' . NL
]
];
}
......@@ -620,4 +620,5 @@ class TaskModelTest extends Todo_TestCase {
$actual = $this->CI->task_model->get_category_select($task_id);
$this->assertEquals($expected, $actual);
}
}
\ No newline at end of file
}
// End of TaskModelTest.php
\ No newline at end of file
......@@ -8,6 +8,6 @@ class PHPTest extends CIUnit_TestCase {
public function testPhpVersion()
{
$this->assertTrue(phpversion() > 5.4);
$this->assertTrue(phpversion() >= 5.4);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment