diff --git a/application/libraries/Todo.php b/application/libraries/Todo.php index 6449b1d..0b105a6 100755 --- a/application/libraries/Todo.php +++ b/application/libraries/Todo.php @@ -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; } diff --git a/application/models/task_model.php b/application/models/task_model.php index 115d43c..ac818f8 100755 --- a/application/models/task_model.php +++ b/application/models/task_model.php @@ -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) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bb4fe4d..5094830 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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 { diff --git a/tests/libs/TodoLibNoFixturesTest.php b/tests/libs/TodoLibNoFixturesTest.php new file mode 100644 index 0000000..1b6f673 --- /dev/null +++ b/tests/libs/TodoLibNoFixturesTest.php @@ -0,0 +1,126 @@ +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 diff --git a/tests/libs/TodoLibTest.php b/tests/libs/TodoLibTest.php index 4a932f6..391d584 100755 --- a/tests/libs/TodoLibTest.php +++ b/tests/libs/TodoLibTest.php @@ -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' diff --git a/tests/models/TaskModelTest.php b/tests/models/TaskModelTest.php index e67102e..c933676 100755 --- a/tests/models/TaskModelTest.php +++ b/tests/models/TaskModelTest.php @@ -514,20 +514,20 @@ class TaskModelTest extends Todo_TestCase { 'Don\'t pass status id' => [ 'task_id' => 97, 'status_id' => NULL, - 'expected' => T5 . ''. NL . - T5 . '' . NL . - T5 . '' . NL . + 'expected' => T5 . '' . NL . T5 . '' . NL . - T5 . '' . NL + T5 . ''. NL . + T5 . '' . NL . + T5 . '' . NL ], 'Pass status id' => [ 'task_id' => 155, 'status_id' => 5, - 'expected' => T5. ''. NL . - T5 . '' . NL . - T5 . '' . NL . + 'expected' => T5 . '' . NL . T5 . '' . NL . - T5 . '' . NL + T5. ''. NL . + T5 . '' . NL . + T5 . '' . 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 diff --git a/tests/system/PHPTest.php b/tests/system/PHPTest.php index 2666a2d..f6fc5ac 100755 --- a/tests/system/PHPTest.php +++ b/tests/system/PHPTest.php @@ -8,6 +8,6 @@ class PHPTest extends CIUnit_TestCase { public function testPhpVersion() { - $this->assertTrue(phpversion() > 5.4); + $this->assertTrue(phpversion() >= 5.4); } }