Browse Source

Rename 'desc' column of checklist table to 'description', and update associated tests and views

Timothy J. Warren 3 years ago
parent
commit
98c55a78ad

+ 2 - 1
.travis.yml View File

@@ -1,12 +1,13 @@
1 1
 language: php
2 2
 
3 3
 php:
4
+  - 5.4
4 5
   - 5.5
5 6
   - 5.6
6 7
   - hhvm
7 8
 
8 9
 install:
9
-  - composer install
10
+  - composer install --dev --no-progress
10 11
 
11 12
 env:
12 13
   - DB=mysql

+ 4 - 2
application/libraries/Todo.php View File

@@ -424,6 +424,7 @@ class Todo {
424 424
 			->where('user_id', $user_id)
425 425
 			->where('name !=', $username)
426 426
 			->where('is_admin', 1)
427
+			->order_by('name')
427 428
 			->get();
428 429
 
429 430
 		return $groups->result_array();
@@ -510,7 +511,7 @@ class Todo {
510 511
 		$friends = $this->CI->db
511 512
 			->select('user_friend_id,user_friend_link.user_id as uid,user.username')
512 513
 			->from('todo_user_friend_link')
513
-			->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner')
514
+			->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner')
514 515
 			->where('confirmed', FRIEND_CONFIRMED)
515 516
 			->where('username !=', $username)
516 517
 
@@ -541,6 +542,7 @@ class Todo {
541 542
 					->select('user_id')
542 543
 					->from('group_users_link')
543 544
 					->where('group_id', $group_id)
545
+					->order_by('user_id')
544 546
 					->get();
545 547
 
546 548
 		return $friends->result_array();
@@ -678,7 +680,7 @@ class Todo {
678 680
 	 * Kanji Num
679 681
 	 *
680 682
 	 * Converts arabic to chinese number
681
-	 * @param int $number
683
+	 * @param int $orig_number
682 684
 	 * @return string
683 685
 	 */
684 686
 	public function kanji_num($orig_number)

+ 1 - 1
application/models/friend_model.php View File

@@ -29,7 +29,7 @@ class Friend_model extends CI_Model {
29 29
 		$friends = $this->db
30 30
 			->select('user_friend_id,user_friend_link.user_id as uid,user.username,user.email')
31 31
 			->from('todo_user_friend_link')
32
-			->join('user', 'user.id=user_friend_link.user_friend_id OR "todo_user"."id"="todo_user_friend_link"."user_id"', 'inner')
32
+			->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner')
33 33
 
34 34
 			->group_start()
35 35
 			->where_in('todo_user_friend_link.user_id', $user_id)

+ 10 - 11
application/models/task_model.php View File

@@ -116,7 +116,7 @@ class Task_model extends CI_Model {
116 116
 	public function get_checklist($task_id)
117 117
 	{
118 118
 		//Get the checklist for the current task from the database
119
-		$chk = $this->db->select('id, task_id, "desc", is_checked')
119
+		$chk = $this->db->select('id, task_id, description, is_checked')
120 120
 			->from('checklist')
121 121
 			->where('task_id', $task_id)
122 122
 			->order_by('is_checked', 'asc')
@@ -138,35 +138,33 @@ class Task_model extends CI_Model {
138 138
 	public function add_checklist_item()
139 139
 	{
140 140
 		$task_id = (int)$this->input->post('task_id');
141
-		$desc = xss_clean($this->input->post('desc'));
141
+		$desc = $this->input->post('desc', TRUE);
142 142
 
143 143
 		//Check if the current item already exists.
144
-		$exists = $this->db->select('task_id, "desc"')
144
+		$exists = $this->db->select('task_id, description')
145 145
 			->from('checklist')
146 146
 			->where('task_id', $task_id)
147
-			->where('"desc"', $desc)
147
+			->where('description', $desc)
148 148
 			->get();
149 149
 
150 150
 		if($exists->num_rows() < 1)
151 151
 		{
152 152
 			//Insert the item
153 153
 			$this->db->set('task_id', $task_id)
154
-				->set('"desc"', $desc)
154
+				->set('description', $desc)
155 155
 				->insert('checklist');
156 156
 
157 157
 			//Return the row
158
-			$return = $this->db->select('id, task_id, "desc", is_checked')
158
+			$return = $this->db->select('id, task_id, description, is_checked')
159 159
 				->from('checklist')
160 160
 				->where('task_id', $task_id)
161
-				->where('"desc"', $desc)
161
+				->where('description', $desc)
162 162
 				->get();
163 163
 
164 164
 			return $return->row_array();
165 165
 		}
166
-		else
167
-		{
168
-			return FALSE;
169
-		}
166
+
167
+		return FALSE;
170 168
 	}
171 169
 
172 170
 	// --------------------------------------------------------------------------
@@ -235,6 +233,7 @@ class Task_model extends CI_Model {
235 233
 	 *
236 234
 	 * Retrieves the user's archived tasks from the database
237 235
 	 *
236
+	 * @param int $page
238 237
 	 * @param int $per_page
239 238
 	 * @return array
240 239
 	 */

+ 9 - 8
application/third_party/CIUnit/libraries/Fixture.php View File

@@ -20,13 +20,6 @@ class Fixture {
20 20
 		{
21 21
 			exit('can\'t load fixture library class when not in test mode!');
22 22
 		}
23
-
24
-		// Turn off foreign key checks for mysql so test tables can be easily truncated
25
-		if (getenv('DB') === 'mysql')
26
-		{
27
-			$this->_assign_db();
28
-			$this->CI->db->simple_query('SET foreign_key_checks = 0;');
29
-		}
30 23
 	}
31 24
 
32 25
 	/**
@@ -87,6 +80,9 @@ class Fixture {
87 80
 
88 81
 	private function truncate($table)
89 82
 	{
83
+		// Turn off foreign key checks for mysql so test tables can be easily truncated
84
+		if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 0;');
85
+
90 86
 		$sql = 'TRUNCATE TABLE ' . $table;
91 87
 
92 88
 		if (getenv('DB') !== 'mysql')
@@ -94,7 +90,12 @@ class Fixture {
94 90
 			$sql .= ' CASCADE';
95 91
 		}
96 92
 
97
-		return $this->CI->db->simple_query($sql);
93
+		$res =  $this->CI->db->simple_query($sql);
94
+
95
+		// Reset foreign key checks
96
+		//if (getenv('DB') === 'mysql') $this->CI->db->simple_query('SET foreign_key_checks = 1;');
97
+
98
+		return $res;
98 99
 	}
99 100
 
100 101
 }

+ 1 - 1
application/views/task/ajax_checklist.php View File

@@ -1,5 +1,5 @@
1 1
 
2 2
 <li>
3 3
 	<input type="checkbox" name="checklist[]" value="<?= $id ?>" id="check_<?= $id?>" <?= ($is_checked == 1) ? 'checked="checked"' : '' ?> />
4
-	&nbsp;&nbsp;<label for="check_<?= $id ?>"><?= $desc ?></label>
4
+	&nbsp;&nbsp;<label for="check_<?= $id ?>"><?= $description ?></label>
5 5
 </li>

+ 1 - 1
application/views/task/checklist_view.php View File

@@ -7,7 +7,7 @@
7 7
 <?php foreach($checklist as $c) : ?>
8 8
 	<li>
9 9
 		<input type="checkbox" name="checklist[]" value="<?= $c['id'] ?>" id="check_<?= $c['id']?>" <?= ($c['is_checked']== 1) ? 'checked="checked"' : '' ?> <?= ($user_perms <= PERM_CHECKLIST_ACCESS) ? 'disabled="disabled"' : '' ?> />
10
-		&nbsp;&nbsp;<label for="check_<?= $c['id']?>"><?= $c['desc'] ?></label>
10
+		&nbsp;&nbsp;<label for="check_<?= $c['id']?>"><?= $c['description'] ?></label>
11 11
 	</li>
12 12
 <?php endforeach ?>
13 13
 <?php endif ?>

+ 12 - 1
composer.json View File

@@ -1,5 +1,16 @@
1 1
 {
2
+	"name":"timw4mail/tims-todo",
3
+	"type":"project",
4
+	"license": "BSD-3-Clause",
5
+	"authors": [{
6
+		"name": "Timothy J. Warren",
7
+		"email": "tim@timshomepage.net",
8
+		"homepage": "https://timshomepage.net",
9
+		"role": "Developer"
10
+	}],
2 11
 	"require": {
3
-		"robmorgan/phinx": "*"
12
+		"php": ">=5.4",
13
+		"robmorgan/phinx": "*",
14
+		"ircmaxell/password-compat": "1.0.*"
4 15
 	}
5 16
 }

+ 15 - 0
migrations/20140813145709_rename_desc_column_migration.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+use Phinx\Migration\AbstractMigration;
4
+
5
+class RenameDescColumnMigration extends AbstractMigration
6
+{
7
+	/**
8
+	 * Rename 'desc' field to 'description'. Reserved words suck
9
+	 */
10
+	public function change()
11
+	{
12
+		$this->table('todo_checklist')
13
+			->renameColumn('desc', 'description');
14
+	}
15
+}

+ 3 - 0
tests/bootstrap.php View File

@@ -1,5 +1,8 @@
1 1
 <?php
2 2
 
3
+// Autoloader for password compat
4
+require_once(__DIR__ . '/../vendor/autoload.php');
5
+
3 6
 // Require base bootstrap file
4 7
 require_once(__DIR__ . '/../application/third_party/CIUnit/bootstrap_phpunit.php');
5 8
 

+ 2 - 2
tests/fixtures/todo_checklist_fixt.yml View File

@@ -1,12 +1,12 @@
1 1
 0:
2 2
     id: 18
3 3
     task_id: 97
4
-    desc: 'Share this task'
4
+    description: 'Share this task'
5 5
     is_checked: 1
6 6
 
7 7
 1:
8 8
     id: 136
9 9
     task_id: 97
10
-    desc: 'Allow un-sharing'
10
+    description: 'Allow un-sharing'
11 11
     is_checked: 1
12 12
 

+ 1 - 1
tests/fixtures/todo_item_comments_fixt.yml View File

@@ -3,7 +3,7 @@
3 3
     user_id: 3
4 4
     item_id: 97
5 5
     comment: "This is a test comment"
6
-    time_posted: 1405457296
6
+    time_posted: 1405457299
7 7
     status: 3
8 8
 
9 9
 2:

+ 2 - 2
tests/libs/TodoLibTest.php View File

@@ -418,10 +418,10 @@ class TodoLibTest extends Todo_TestCase {
418 418
 	{
419 419
 		$expected = [
420 420
 			array (
421
-				'user_id' => '7',
421
+				'user_id' => '3',
422 422
 			),
423 423
 			array (
424
-				'user_id' => '3',
424
+				'user_id' => '7',
425 425
 			)
426 426
 		];
427 427
 		$actual = $this->CI->todo->get_friends_in_group(62);

+ 3 - 3
tests/models/TaskModelTest.php View File

@@ -427,7 +427,7 @@ class TaskModelTest extends Todo_TestCase {
427 427
 				'user_id' => '3',
428 428
 				'item_id' => '97',
429 429
 				'comment' => 'This is a test comment',
430
-				'time_posted' => '1405457296',
430
+				'time_posted' => '1405457299',
431 431
 				'email' => 'guest@timshomepage.net',
432 432
 				'status' => 'In Progress',
433 433
 			),
@@ -452,13 +452,13 @@ class TaskModelTest extends Todo_TestCase {
452 452
 			array (
453 453
 				'id' => '18',
454 454
 				'task_id' => '97',
455
-				'desc' => 'Share this task',
455
+				'description' => 'Share this task',
456 456
 				'is_checked' => '1',
457 457
 			),
458 458
 			array (
459 459
 				'id' => '136',
460 460
 				'task_id' => '97',
461
-				'desc' => 'Allow un-sharing',
461
+				'description' => 'Allow un-sharing',
462 462
 				'is_checked' => '1',
463 463
 			),
464 464
 		];

+ 1 - 0
web/index.php View File

@@ -271,6 +271,7 @@ define('VIEWPATH', $view_folder);
271 271
  *
272 272
  * And away we go...
273 273
  */
274
+require_once '../vendor/autoload.php';
274 275
 require_once BASEPATH.'core/CodeIgniter.php';
275 276
 
276 277
 /* End of file index.php */