From 98c55a78ad05879af7dddc9a1711b90fdec74e1c Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 13 Aug 2014 15:57:24 -0400 Subject: [PATCH] Rename 'desc' column of checklist table to 'description', and update associated tests and views --- .travis.yml | 3 ++- application/libraries/Todo.php | 6 ++++-- application/models/friend_model.php | 2 +- application/models/task_model.php | 21 +++++++++---------- .../third_party/CIUnit/libraries/Fixture.php | 17 ++++++++------- application/views/task/ajax_checklist.php | 2 +- application/views/task/checklist_view.php | 2 +- composer.json | 13 +++++++++++- ...813145709_rename_desc_column_migration.php | 15 +++++++++++++ tests/bootstrap.php | 3 +++ tests/fixtures/todo_checklist_fixt.yml | 4 ++-- tests/fixtures/todo_item_comments_fixt.yml | 2 +- tests/libs/TodoLibTest.php | 4 ++-- tests/models/TaskModelTest.php | 6 +++--- web/index.php | 1 + 15 files changed, 67 insertions(+), 34 deletions(-) create mode 100644 migrations/20140813145709_rename_desc_column_migration.php diff --git a/.travis.yml b/.travis.yml index 9a1aaff..6f119ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ language: php php: + - 5.4 - 5.5 - 5.6 - hhvm install: - - composer install + - composer install --dev --no-progress env: - DB=mysql diff --git a/application/libraries/Todo.php b/application/libraries/Todo.php index 2d33dab..6449b1d 100755 --- a/application/libraries/Todo.php +++ b/application/libraries/Todo.php @@ -424,6 +424,7 @@ class Todo { ->where('user_id', $user_id) ->where('name !=', $username) ->where('is_admin', 1) + ->order_by('name') ->get(); return $groups->result_array(); @@ -510,7 +511,7 @@ class Todo { $friends = $this->CI->db ->select('user_friend_id,user_friend_link.user_id as uid,user.username') ->from('todo_user_friend_link') - ->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner') + ->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner') ->where('confirmed', FRIEND_CONFIRMED) ->where('username !=', $username) @@ -541,6 +542,7 @@ class Todo { ->select('user_id') ->from('group_users_link') ->where('group_id', $group_id) + ->order_by('user_id') ->get(); return $friends->result_array(); @@ -678,7 +680,7 @@ class Todo { * Kanji Num * * Converts arabic to chinese number - * @param int $number + * @param int $orig_number * @return string */ public function kanji_num($orig_number) diff --git a/application/models/friend_model.php b/application/models/friend_model.php index b945398..44c1ecf 100755 --- a/application/models/friend_model.php +++ b/application/models/friend_model.php @@ -29,7 +29,7 @@ class Friend_model extends CI_Model { $friends = $this->db ->select('user_friend_id,user_friend_link.user_id as uid,user.username,user.email') ->from('todo_user_friend_link') - ->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner') + ->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner') ->group_start() ->where_in('todo_user_friend_link.user_id', $user_id) diff --git a/application/models/task_model.php b/application/models/task_model.php index cfd5a9e..115d43c 100755 --- a/application/models/task_model.php +++ b/application/models/task_model.php @@ -116,7 +116,7 @@ class Task_model extends CI_Model { public function get_checklist($task_id) { //Get the checklist for the current task from the database - $chk = $this->db->select('id, task_id, "desc", is_checked') + $chk = $this->db->select('id, task_id, description, is_checked') ->from('checklist') ->where('task_id', $task_id) ->order_by('is_checked', 'asc') @@ -138,35 +138,33 @@ class Task_model extends CI_Model { public function add_checklist_item() { $task_id = (int)$this->input->post('task_id'); - $desc = xss_clean($this->input->post('desc')); + $desc = $this->input->post('desc', TRUE); //Check if the current item already exists. - $exists = $this->db->select('task_id, "desc"') + $exists = $this->db->select('task_id, description') ->from('checklist') ->where('task_id', $task_id) - ->where('"desc"', $desc) + ->where('description', $desc) ->get(); if($exists->num_rows() < 1) { //Insert the item $this->db->set('task_id', $task_id) - ->set('"desc"', $desc) + ->set('description', $desc) ->insert('checklist'); //Return the row - $return = $this->db->select('id, task_id, "desc", is_checked') + $return = $this->db->select('id, task_id, description, is_checked') ->from('checklist') ->where('task_id', $task_id) - ->where('"desc"', $desc) + ->where('description', $desc) ->get(); return $return->row_array(); } - else - { - return FALSE; - } + + return FALSE; } // -------------------------------------------------------------------------- @@ -235,6 +233,7 @@ class Task_model extends CI_Model { * * Retrieves the user's archived tasks from the database * + * @param int $page * @param int $per_page * @return array */ diff --git a/application/third_party/CIUnit/libraries/Fixture.php b/application/third_party/CIUnit/libraries/Fixture.php index cae4785..274c95a 100755 --- a/application/third_party/CIUnit/libraries/Fixture.php +++ b/application/third_party/CIUnit/libraries/Fixture.php @@ -20,13 +20,6 @@ class Fixture { { exit('can\'t load fixture library class when not in test mode!'); } - - // Turn off foreign key checks for mysql so test tables can be easily truncated - if (getenv('DB') === 'mysql') - { - $this->_assign_db(); - $this->CI->db->simple_query('SET foreign_key_checks = 0;'); - } } /** @@ -87,6 +80,9 @@ class Fixture { private function truncate($table) { + // Turn off foreign key checks for mysql so test tables can be easily truncated + if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 0;'); + $sql = 'TRUNCATE TABLE ' . $table; if (getenv('DB') !== 'mysql') @@ -94,7 +90,12 @@ class Fixture { $sql .= ' CASCADE'; } - return $this->CI->db->simple_query($sql); + $res = $this->CI->db->simple_query($sql); + + // Reset foreign key checks + //if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 1;'); + + return $res; } } diff --git a/application/views/task/ajax_checklist.php b/application/views/task/ajax_checklist.php index 2f3ffcd..68252a0 100755 --- a/application/views/task/ajax_checklist.php +++ b/application/views/task/ajax_checklist.php @@ -1,5 +1,5 @@
  • /> -    +   
  • \ No newline at end of file diff --git a/application/views/task/checklist_view.php b/application/views/task/checklist_view.php index a98d3fc..5c1a598 100755 --- a/application/views/task/checklist_view.php +++ b/application/views/task/checklist_view.php @@ -7,7 +7,7 @@
  • /> -    +   
  • diff --git a/composer.json b/composer.json index b4c0e0f..f6c07c9 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,16 @@ { + "name":"timw4mail/tims-todo", + "type":"project", + "license": "BSD-3-Clause", + "authors": [{ + "name": "Timothy J. Warren", + "email": "tim@timshomepage.net", + "homepage": "https://timshomepage.net", + "role": "Developer" + }], "require": { - "robmorgan/phinx": "*" + "php": ">=5.4", + "robmorgan/phinx": "*", + "ircmaxell/password-compat": "1.0.*" } } \ No newline at end of file diff --git a/migrations/20140813145709_rename_desc_column_migration.php b/migrations/20140813145709_rename_desc_column_migration.php new file mode 100644 index 0000000..ae328ef --- /dev/null +++ b/migrations/20140813145709_rename_desc_column_migration.php @@ -0,0 +1,15 @@ +table('todo_checklist') + ->renameColumn('desc', 'description'); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 70116f0..bb4fe4d 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,8 @@ '7', + 'user_id' => '3', ), array ( - 'user_id' => '3', + 'user_id' => '7', ) ]; $actual = $this->CI->todo->get_friends_in_group(62); diff --git a/tests/models/TaskModelTest.php b/tests/models/TaskModelTest.php index c92a41e..e67102e 100755 --- a/tests/models/TaskModelTest.php +++ b/tests/models/TaskModelTest.php @@ -427,7 +427,7 @@ class TaskModelTest extends Todo_TestCase { 'user_id' => '3', 'item_id' => '97', 'comment' => 'This is a test comment', - 'time_posted' => '1405457296', + 'time_posted' => '1405457299', 'email' => 'guest@timshomepage.net', 'status' => 'In Progress', ), @@ -452,13 +452,13 @@ class TaskModelTest extends Todo_TestCase { array ( 'id' => '18', 'task_id' => '97', - 'desc' => 'Share this task', + 'description' => 'Share this task', 'is_checked' => '1', ), array ( 'id' => '136', 'task_id' => '97', - 'desc' => 'Allow un-sharing', + 'description' => 'Allow un-sharing', 'is_checked' => '1', ), ]; diff --git a/web/index.php b/web/index.php index 1893fbc..da86bd1 100755 --- a/web/index.php +++ b/web/index.php @@ -271,6 +271,7 @@ define('VIEWPATH', $view_folder); * * And away we go... */ +require_once '../vendor/autoload.php'; require_once BASEPATH.'core/CodeIgniter.php'; /* End of file index.php */