Mysql compatability tests and fixes

This commit is contained in:
Timothy Warren 2014-08-13 20:50:57 -04:00
parent 98c55a78ad
commit 6591c934d8
7 changed files with 174 additions and 151 deletions

View File

@ -304,7 +304,7 @@ class Todo {
public function validate_pass() public function validate_pass()
{ {
$err = array(); $err = array();
$user = $this->CI->session->userdata('uid'); $user = (int) $this->CI->session->userdata('uid');
$pass = $this->CI->input->post('pass'); $pass = $this->CI->input->post('pass');
$pass1 = $this->CI->input->post('pass1'); $pass1 = $this->CI->input->post('pass1');
$old_pass = $this->CI->input->post('old_pass'); $old_pass = $this->CI->input->post('old_pass');
@ -315,6 +315,7 @@ class Todo {
//Check for current password in the database //Check for current password in the database
$user_check = $this->CI->db->select('password') $user_check = $this->CI->db->select('password')
->from('user') ->from('user')
->where('id', $user)
->get(); ->get();
$row = $user_check->row(); $row = $user_check->row();
@ -663,14 +664,12 @@ class Todo {
{ {
$query = $this->CI->db->select('name') $query = $this->CI->db->select('name')
->from('group') ->from('group')
->where('id', $group_id) ->where('id', (int) $group_id)
->get(); ->get();
$qrow = $query->row(); $qrow = $query->row();
$name = $qrow->name; return $qrow->name;
return $name;
} }

View File

@ -889,6 +889,7 @@ class Task_model extends CI_Model {
//Get the list of statuses //Get the list of statuses
$query = $this->db->select('id, value as desc') $query = $this->db->select('id, value as desc')
->from('status') ->from('status')
->order_by('id')
->get(); ->get();
foreach($query->result() as $row) foreach($query->result() as $row)

View File

@ -17,6 +17,9 @@ class Welcome extends CIU_Controller {}
/** /**
* Base TestSuite * Base TestSuite
*
* @method bool assertEquals(mixed $expected, mixed $actual)
* @method bool assertNotEquals(mixed $expected, mixed $actual)
*/ */
class Todo_TestCase extends CIUnit_TestCase { class Todo_TestCase extends CIUnit_TestCase {

View File

@ -0,0 +1,126 @@
<?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

View File

@ -4,8 +4,8 @@ class TodoLibTest extends Todo_TestCase {
protected $tables = [ protected $tables = [
'todo_priority' => 'todo_priority', 'todo_priority' => 'todo_priority',
'todo_user' => 'todo_user',
'todo_group' => 'todo_group', 'todo_group' => 'todo_group',
'todo_user' => 'todo_user',
'todo_category' => 'todo_category', 'todo_category' => 'todo_category',
'todo_group_users_link' => 'todo_group_users_link', 'todo_group_users_link' => 'todo_group_users_link',
'todo_user_friend_link' => 'todo_user_friend_link', 'todo_user_friend_link' => 'todo_user_friend_link',
@ -15,140 +15,9 @@ class TodoLibTest extends Todo_TestCase {
{ {
parent::setUp(); parent::setUp();
$this->CI->load->library('todo'); $this->CI->load->library('todo');
}
public function testGetUserFromId() // Hack to fix problem with CodeIgniter in this specific context
{ if ($this->CI->db->conn_id === FALSE) $this->CI->db->db_connect();
$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);
} }
public function dataValidatePass() public function dataValidatePass()
@ -196,6 +65,7 @@ class TodoLibTest extends Todo_TestCase {
'uid' => 3 'uid' => 3
]); ]);
$_POST = [];
$_POST = $post; $_POST = $post;
$actual = $this->CI->todo->validate_pass(); $actual = $this->CI->todo->validate_pass();
@ -203,6 +73,29 @@ class TodoLibTest extends Todo_TestCase {
$this->assertEquals($expected, $actual); $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() public function testCategoryList()
{ {
$this->create_session(); $this->create_session();
@ -435,10 +328,10 @@ class TodoLibTest extends Todo_TestCase {
'group_id' => 11, 'group_id' => 11,
'expected' => 'timw4mail' 'expected' => 'timw4mail'
], ],
[ /*[
'group_id' => 0, 'group_id' => 0,
'expected' => 'global' 'expected' => 'global'
], ],*/
[ [
'group_id' => 62, 'group_id' => 62,
'expected' => 'shared' 'expected' => 'shared'

View File

@ -514,20 +514,20 @@ class TaskModelTest extends Todo_TestCase {
'Don\'t pass status id' => [ 'Don\'t pass status id' => [
'task_id' => 97, 'task_id' => 97,
'status_id' => NULL, 'status_id' => NULL,
'expected' => T5 . '<option value="3" selected="selected">In Progress</option>'. NL . 'expected' => T5 . '<option value="1">Created</option>' . NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5">Canceled</option>' . NL .
T5 . '<option value="2">Completed</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' => [ 'Pass status id' => [
'task_id' => 155, 'task_id' => 155,
'status_id' => 5, 'status_id' => 5,
'expected' => T5. '<option value="3">In Progress</option>'. NL . 'expected' => T5 . '<option value="1">Created</option>' . NL .
T5 . '<option value="4">On Hold</option>' . NL .
T5 . '<option value="5" selected="selected">Canceled</option>' . NL .
T5 . '<option value="2">Completed</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); $actual = $this->CI->task_model->get_category_select($task_id);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
} }
// End of TaskModelTest.php

View File

@ -8,6 +8,6 @@ class PHPTest extends CIUnit_TestCase {
public function testPhpVersion() public function testPhpVersion()
{ {
$this->assertTrue(phpversion() > 5.4); $this->assertTrue(phpversion() >= 5.4);
} }
} }