Browse Source

Mysql compatability tests and fixes

Timothy J. Warren 3 years ago
parent
commit
6591c934d8

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

@@ -304,7 +304,7 @@ class Todo {
304 304
 	public function validate_pass()
305 305
 	{
306 306
 		$err = array();
307
-		$user = $this->CI->session->userdata('uid');
307
+		$user = (int) $this->CI->session->userdata('uid');
308 308
 		$pass = $this->CI->input->post('pass');
309 309
 		$pass1 = $this->CI->input->post('pass1');
310 310
 		$old_pass = $this->CI->input->post('old_pass');
@@ -315,6 +315,7 @@ class Todo {
315 315
 		//Check for current password in the database
316 316
 		$user_check = $this->CI->db->select('password')
317 317
 				->from('user')
318
+				->where('id', $user)
318 319
 				->get();
319 320
 		
320 321
 		$row = $user_check->row();
@@ -663,14 +664,12 @@ class Todo {
663 664
 	{
664 665
 		$query = $this->CI->db->select('name')
665 666
 			->from('group')
666
-			->where('id', $group_id)
667
+			->where('id', (int) $group_id)
667 668
 			->get();
668 669
 
669 670
 		$qrow = $query->row();
670 671
 
671
-		$name = $qrow->name;
672
-
673
-		return $name;
672
+		return $qrow->name;
674 673
 	}
675 674
 
676 675
 

+ 1
- 0
application/models/task_model.php View File

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

+ 3
- 0
tests/bootstrap.php View File

@@ -17,6 +17,9 @@ class Welcome extends CIU_Controller {}
17 17
 
18 18
 /**
19 19
  * Base TestSuite
20
+ *
21
+ * @method bool assertEquals(mixed $expected, mixed $actual)
22
+ * @method bool assertNotEquals(mixed $expected, mixed $actual)
20 23
  */
21 24
 class Todo_TestCase extends CIUnit_TestCase {
22 25
 

+ 126
- 0
tests/libs/TodoLibNoFixturesTest.php View File

@@ -0,0 +1,126 @@
1
+<?php
2
+
3
+/**
4
+ * Split of some methods that don't require database from TodoLibTest
5
+ * Not having to load fixtures should make these run a lot faster
6
+ */
7
+class TodoLibNoFixturesTest extends Todo_TestCase {
8
+
9
+	public function setUp()
10
+	{
11
+		parent::setUp();
12
+		$this->CI->load->library('todo');
13
+	}
14
+
15
+	public function testCryptPass()
16
+	{
17
+		$expected = '$2y$10$qW8HlbNDNEJx1GqmYW9APOYOqo5apV8stjNcV/xunsvnjTYJBTc0m';
18
+		$actual = $this->CI->todo->crypt_pass('guest');
19
+
20
+		$this->assertNotEquals($expected, $actual,
21
+			"Password has should be different every time it is used because of Bcrypt salt");
22
+	}
23
+
24
+	public function dataKanjiNum()
25
+	{
26
+		return [
27
+			'non-numeric' => [
28
+				'input' => 'string',
29
+				'expected' => '〇'
30
+			],
31
+			'zero' => [
32
+				'input' => 0,
33
+				'expected' => '〇'
34
+			],
35
+			'one' => [
36
+				'input' => 1,
37
+				'expected' => '一'
38
+			],
39
+			'tens' => [
40
+				'input' => 34,
41
+				'expected' => '三十四'
42
+			],
43
+			'hundreds' => [
44
+				'input' => 968,
45
+				'expected' => '九百六十八'
46
+			],
47
+			'thousands' => [
48
+				'input' => 1024,
49
+				'expected' => '千二十四'
50
+			],
51
+			'ten thousands' => [
52
+				'input' => 11275,
53
+				'expected' => '万千二百七十五'
54
+			],
55
+			'hundred thousands' => [
56
+				'input' => 658753,
57
+				'expected' => '六十五万八千七百五十三'
58
+			],
59
+			'millions' => [
60
+				'input' => 9876543,
61
+				'expected' => '九百八十七万六千五百四十三'
62
+			],
63
+			'ten_millions' => [
64
+				'input' => 98765432,
65
+				'expected' => '九千八百七十六万五千四百三十二'
66
+			],
67
+			'hundred_millions' => [
68
+				'input' => 987654321,
69
+				'expected' => '九億八千七百六十五万四千三百二十一'
70
+			]
71
+		];
72
+	}
73
+
74
+	/**
75
+	 * @dataProvider dataKanjiNum
76
+	 */
77
+	public function testKanjiNum($input, $expected)
78
+	{
79
+		$actual = $this->CI->todo->kanji_num($input);
80
+		$this->assertEquals($expected, $actual);
81
+	}
82
+
83
+	public function dataRedirect303()
84
+	{
85
+		return [
86
+			'full url redirect' => [
87
+				'url' => 'http://www.example.com',
88
+				'headers' => [
89
+					array (
90
+						'HTTP/1.1 303 See Other',
91
+						true,
92
+					),
93
+					array (
94
+						'Location:http://www.example.com',
95
+						true,
96
+					)
97
+				]
98
+			],
99
+			'route redirect' => [
100
+				'url' => 'task/list',
101
+				'headers' => [
102
+					array (
103
+						'HTTP/1.1 303 See Other',
104
+						true,
105
+					),
106
+					array (
107
+						'Location:https://todo.timshomepage.net/task/list',
108
+						true,
109
+					)
110
+				]
111
+			]
112
+		];
113
+	}
114
+
115
+	/**
116
+	 * @dataProvider dataRedirect303
117
+	 */
118
+	public function testRedirect303($url, $headers)
119
+	{
120
+		$this->CI->todo->redirect_303($url);
121
+		$actual = $this->CI->output->get_headers();
122
+
123
+		$this->assertEquals($headers, $actual);
124
+	}
125
+}
126
+// End of TodoLibNoFixturesTest

+ 29
- 136
tests/libs/TodoLibTest.php View File

@@ -4,8 +4,8 @@ class TodoLibTest extends Todo_TestCase {
4 4
 
5 5
 	protected $tables = [
6 6
 		'todo_priority' => 'todo_priority',
7
-		'todo_user' => 'todo_user',
8 7
 		'todo_group' => 'todo_group',
8
+		'todo_user' => 'todo_user',
9 9
 		'todo_category' => 'todo_category',
10 10
 		'todo_group_users_link' => 'todo_group_users_link',
11 11
 		'todo_user_friend_link' => 'todo_user_friend_link',
@@ -15,140 +15,9 @@ class TodoLibTest extends Todo_TestCase {
15 15
 	{
16 16
 		parent::setUp();
17 17
 		$this->CI->load->library('todo');
18
-	}
19
-
20
-	public function testGetUserFromId()
21
-	{
22
-		$expected = 'timw4mail';
23
-		$actual = $this->CI->todo->get_user_from_id(1);
24
-
25
-		$this->assertEquals($expected, $actual);
26
-	}
27
-
28
-	public function testCryptPass()
29
-	{
30
-		$expected = '$2y$10$qW8HlbNDNEJx1GqmYW9APOYOqo5apV8stjNcV/xunsvnjTYJBTc0m';
31
-		$actual = $this->CI->todo->crypt_pass('guest');
32
-
33
-		$this->assertNotEquals($expected, $actual,
34
-			"Password has should be different every time it is used because of Bcrypt salt");
35
-	}
36
-
37
-	public function dataKanjiNum()
38
-	{
39
-		return [
40
-			'non-numeric' => [
41
-				'input' => 'string',
42
-				'expected' => '〇'
43
-			],
44
-			'zero' => [
45
-				'input' => 0,
46
-				'expected' => '〇'
47
-			],
48
-			'one' => [
49
-				'input' => 1,
50
-				'expected' => '一'
51
-			],
52
-			'tens' => [
53
-				'input' => 34,
54
-				'expected' => '三十四'
55
-			],
56
-			'hundreds' => [
57
-				'input' => 968,
58
-				'expected' => '九百六十八'
59
-			],
60
-			'thousands' => [
61
-				'input' => 1024,
62
-				'expected' => '千二十四'
63
-			],
64
-			'ten thousands' => [
65
-				'input' => 11275,
66
-				'expected' => '万千二百七十五'
67
-			],
68
-			'hundred thousands' => [
69
-				'input' => 658753,
70
-				'expected' => '六十五万八千七百五十三'
71
-			],
72
-			'millions' => [
73
-				'input' => 9876543,
74
-				'expected' => '九百八十七万六千五百四十三'
75
-			],
76
-			'ten_millions' => [
77
-				'input' => 98765432,
78
-				'expected' => '九千八百七十六万五千四百三十二'
79
-			],
80
-			'hundred_millions' => [
81
-				'input' => 987654321,
82
-				'expected' => '九億八千七百六十五万四千三百二十一'
83
-			]
84
-		];
85
-	}
86
-
87
-	/**
88
-	 * @dataProvider dataKanjiNum
89
-	 */
90
-	public function testKanjiNum($input, $expected)
91
-	{
92
-		$actual = $this->CI->todo->kanji_num($input);
93
-		$this->assertEquals($expected, $actual);
94
-	}
95
-
96
-	public function dataRedirect303()
97
-	{
98
-		return [
99
-			'full url redirect' => [
100
-				'url' => 'http://www.example.com',
101
-				'headers' => [
102
-					array (
103
-						'HTTP/1.1 303 See Other',
104
-						true,
105
-					),
106
-					array (
107
-						'Location:http://www.example.com',
108
-						true,
109
-					)
110
-				]
111
-			],
112
-			'route redirect' => [
113
-				'url' => 'task/list',
114
-				'headers' => [
115
-					array (
116
-						'HTTP/1.1 303 See Other',
117
-						true,
118
-					),
119
-					array (
120
-						'Location:https://todo.timshomepage.net/task/list',
121
-						true,
122
-					)
123
-				]
124
-			]
125
-		];
126
-	}
127
-
128
-	/**
129
-	 * @dataProvider dataRedirect303
130
-	 */
131
-	public function testRedirect303($url, $headers)
132
-	{
133
-		$this->CI->todo->redirect_303($url);
134
-		$actual = $this->CI->output->get_headers();
135
-
136
-		$this->assertEquals($headers, $actual);
137
-	}
138
-
139
-	public function testGetFriendRequests()
140
-	{
141
-		$this->create_session();
142
-		$this->CI->session->set_userdata([
143
-			'username' => 'timw4mail',
144
-			'uid' => 1
145
-		]);
146 18
 
147
-		$expected = 1;
148
-
149
-		$actual = $this->CI->todo->get_friend_requests();
150
-
151
-		$this->assertEquals($expected, $actual);
19
+		// Hack to fix problem with CodeIgniter in this specific context
20
+		if ($this->CI->db->conn_id === FALSE) $this->CI->db->db_connect();
152 21
 	}
153 22
 
154 23
 	public function dataValidatePass()
@@ -196,6 +65,7 @@ class TodoLibTest extends Todo_TestCase {
196 65
 			'uid' => 3
197 66
 		]);
198 67
 
68
+		$_POST = [];
199 69
 		$_POST = $post;
200 70
 
201 71
 		$actual = $this->CI->todo->validate_pass();
@@ -203,6 +73,29 @@ class TodoLibTest extends Todo_TestCase {
203 73
 		$this->assertEquals($expected, $actual);
204 74
 	}
205 75
 
76
+	public function testGetUserFromId()
77
+	{
78
+		$expected = 'timw4mail';
79
+		$actual = $this->CI->todo->get_user_from_id(1);
80
+
81
+		$this->assertEquals($expected, $actual);
82
+	}
83
+
84
+	public function testGetFriendRequests()
85
+	{
86
+		$this->create_session();
87
+		$this->CI->session->set_userdata([
88
+			'username' => 'timw4mail',
89
+			'uid' => 1
90
+		]);
91
+
92
+		$expected = 1;
93
+
94
+		$actual = $this->CI->todo->get_friend_requests();
95
+
96
+		$this->assertEquals($expected, $actual);
97
+	}
98
+
206 99
 	public function testCategoryList()
207 100
 	{
208 101
 		$this->create_session();
@@ -435,10 +328,10 @@ class TodoLibTest extends Todo_TestCase {
435 328
 				'group_id' => 11,
436 329
 				'expected' => 'timw4mail'
437 330
 			],
438
-			[
331
+			/*[
439 332
 				'group_id' => 0,
440 333
 				'expected' => 'global'
441
-			],
334
+			],*/
442 335
 			[
443 336
 				'group_id' => 62,
444 337
 				'expected' => 'shared'

+ 10
- 9
tests/models/TaskModelTest.php View File

@@ -514,20 +514,20 @@ class TaskModelTest extends Todo_TestCase {
514 514
 			'Don\'t pass status id' => [
515 515
 				'task_id' => 97,
516 516
 				'status_id' => NULL,
517
-				'expected' => T5 . '<option value="3" selected="selected">In Progress</option>'.  NL .
518
-					T5 . '<option value="4">On Hold</option>' .  NL .
519
-					T5 . '<option value="5">Canceled</option>' .  NL .
517
+				'expected' => 	T5 . '<option value="1">Created</option>' .  NL .
520 518
 					T5 . '<option value="2">Completed</option>' .  NL .
521
-					T5 . '<option value="1">Created</option>' .  NL
519
+					T5 . '<option value="3" selected="selected">In Progress</option>'.  NL .
520
+					T5 . '<option value="4">On Hold</option>' .  NL .
521
+					T5 . '<option value="5">Canceled</option>' .  NL
522 522
 			],
523 523
 			'Pass status id' => [
524 524
 				'task_id' => 155,
525 525
 				'status_id' => 5,
526
-				'expected' => T5. '<option value="3">In Progress</option>'.  NL .
527
-					T5 . '<option value="4">On Hold</option>' .  NL .
528
-					T5 . '<option value="5" selected="selected">Canceled</option>' .  NL .
526
+				'expected' => 	T5 . '<option value="1">Created</option>' .  NL .
529 527
 					T5 . '<option value="2">Completed</option>' .  NL .
530
-					T5 . '<option value="1">Created</option>' .  NL
528
+					T5. '<option value="3">In Progress</option>'.  NL .
529
+					T5 . '<option value="4">On Hold</option>' .  NL .
530
+					T5 . '<option value="5" selected="selected">Canceled</option>' .  NL
531 531
 			]
532 532
 		];
533 533
 	}
@@ -620,4 +620,5 @@ class TaskModelTest extends Todo_TestCase {
620 620
 		$actual = $this->CI->task_model->get_category_select($task_id);
621 621
 		$this->assertEquals($expected, $actual);
622 622
 	}
623
-}
623
+}
624
+// End of TaskModelTest.php

+ 1
- 1
tests/system/PHPTest.php View File

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