1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Unit_tests_providers_model extends CI_Driver {
4 private $ci;
5 private $provider_role_id;
6 private $default_working_plan;
7
8 9 10
11 public function __construct() {
12 $this->ci =& get_instance();
13 $this->ci->load->library('Unit_test');
14 $this->ci->load->model('providers_model');
15
16 $this->provider_role_id = $this->ci->db->get_where('ea_roles',
17 array('slug' => DB_SLUG_PROVIDER))->row()->id;
18
19 $this->default_working_plan = $this->ci->db->get_where('ea_settings',
20 array('name' => 'company_working_plan'))->row()->value;
21 }
22
23 24 25
26 public function run_all() {
27
28
29
30 $class_methods = get_class_methods('Unit_tests_providers_model');
31 foreach ($class_methods as $method_name) {
32 if (substr($method_name, 0, 5) === 'test_') {
33 call_user_func(array($this, $method_name));
34 }
35 }
36 }
37
38
39
40
41
42 private function test_add_insert() {
43 $provider = array(
44 'first_name' => 'John',
45 'last_name' => 'Doe',
46 'email' => 'test@test.com',
47 'mobile_number' => '000000',
48 'phone_number' => '111111',
49 'address' => 'Some Str',
50 'city' => 'Some City',
51 'state' => 'Some State',
52 'zip_code' => '12345',
53 'notes' => 'This is a test provider',
54 'id_roles' => $this->provider_role_id,
55 'services' => array(),
56 'settings' => array(
57 'username' => 'test_prov',
58 'password' => 'test_prov',
59 'working_plan' => $this->default_working_plan,
60 'notifications' => TRUE,
61 'google_sync' => 0,
62 'google_token' => NULL,
63 'google_calendar' => NULL,
64 'sync_past_days' => '5',
65 'sync_future_days' => '5'
66 )
67 );
68
69
70 $provider['id'] = $this->ci->providers_model->add($provider);
71 $this->ci->unit->run($provider['id'], 'is_int', 'Check if add (insert) result is integer.');
72
73
74 $db_provider = $this->ci->db
75 ->get_where('ea_users', array('id' => $provider['id']))
76 ->row_array();
77 $db_provider['services'] = array();
78 $db_provider['settings'] = $this->ci->db
79 ->get_where('ea_user_settings', array('id_users' => $provider['id']))
80 ->row_array();
81 unset($db_provider['settings']['id_users'], $db_provider['settings']['salt'],
82 $provider['settings']['password'], $db_provider['settings']['password']);
83
84 $this->ci->unit->run($provider, $db_provider, 'Check if add(insert) has successfully '
85 . 'inserted a provider record.');
86
87
88
89 if ($this->ci->db->get_where('ea_users', array('id' => $provider['id']))->num_rows() > 0) {
90 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
91 }
92 }
93
94 private function test_add_update() {
95
96 $provider = array(
97 'first_name' => 'John',
98 'last_name' => 'Doe',
99 'email' => 'test@test.com',
100 'mobile_number' => '000000',
101 'phone_number' => '111111',
102 'address' => 'Some Str',
103 'city' => 'Some City',
104 'state' => 'Some State',
105 'zip_code' => '12345',
106 'notes' => 'This is a test provider',
107 'id_roles' => $this->provider_role_id
108 );
109 $this->ci->db->insert('ea_users', $provider);
110 $provider['id'] = $this->ci->db->insert_id();
111
112
113 $settings = array(
114 'id_users' => $provider['id'],
115 'username' => 'test_prov',
116 'password' => 'test_prov',
117 'working_plan' => $this->default_working_plan,
118 'notifications' => TRUE,
119 'google_sync' => 0,
120 'google_token' => NULL,
121 'google_calendar' => NULL,
122 'sync_past_days' => '5',
123 'sync_future_days' => '5'
124 );
125 $this->ci->db->insert('ea_user_settings', $settings);
126
127
128 $provider = array(
129 'id' => $provider['id'],
130 'first_name' => 'CHANGED',
131 'last_name' => 'CHANGED',
132 'email' => 'changed@changed.com',
133 'mobile_number' => 'CHANGED',
134 'phone_number' => 'CHANGED',
135 'address' => 'CHANGED',
136 'city' => 'CHANGED',
137 'state' => 'CHANGED',
138 'zip_code' => 'CHANGED',
139 'notes' => 'CHANGED',
140 'id_roles' => $this->provider_role_id,
141 'services' => array(),
142 'settings' => array(
143 'username' => 'CHANGED',
144 'password' => 'CHANGED',
145 'working_plan' => $this->default_working_plan,
146 'notifications' => TRUE,
147 'google_sync' => 0,
148 'google_token' => NULL,
149 'google_calendar' => NULL,
150 'sync_past_days' => '9',
151 'sync_future_days' => '8'
152 )
153 );
154
155 $update_result = $this->ci->providers_model->add($provider);
156 $this->ci->unit->run($update_result, 'is_int', 'Check if add (update) result is integer.');
157
158
159 $db_provider = $this->ci->db
160 ->get_where('ea_users', array('id' => $provider['id']))
161 ->row_array();
162 $db_provider['services'] = array();
163 $db_provider['settings'] = $this->ci->db
164 ->get_where('ea_user_settings', array('id_users' => $provider['id']))
165 ->row_array();
166 unset($db_provider['settings']['id_users'], $db_provider['settings']['salt'],
167 $provider['settings']['password'], $db_provider['settings']['password']);
168
169 $this->ci->unit->run($provider, $db_provider, 'Check if add(update) has successfully '
170 . 'updated a provider record.');
171
172
173
174 if ($this->ci->db->get_where('ea_users', array('id' => $provider['id']))->num_rows() > 0) {
175 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
176 }
177 }
178
179 private function test_add_with_invalid_data() {
180
181
182 $provider = array(
183 'first_name' => 'some name',
184 'last_name' => 'some name',
185 );
186
187 $has_thrown_exc = FALSE;
188 try {
189 $this->ci->providers_model->add($provider);
190 } catch(Exception $exc) {
191 $has_thrown_exc = TRUE;
192 }
193 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if add() with invalid data has '
194 . 'thrown an exception');
195 }
196
197
198 private function test_exists_with_record_that_exists() {
199
200 $provider = array(
201 'first_name' => 'John',
202 'last_name' => 'Doe',
203 'email' => 'test@test.com',
204 'mobile_number' => '000000',
205 'phone_number' => '111111',
206 'address' => 'Some Str',
207 'city' => 'Some City',
208 'state' => 'Some State',
209 'zip_code' => '12345',
210 'notes' => 'This is a test provider',
211 'id_roles' => $this->provider_role_id
212 );
213 $this->ci->db->insert('ea_users', $provider);
214 $provider['id'] = $this->ci->db->insert_id();
215
216
217 $exists = $this->ci->providers_model->exists($provider);
218 $this->ci->unit->run($exists, TRUE, 'Test exists() with record that exists.');
219
220
221 if ($this->ci->db->get_where('ea_users', array('id' => $provider['id']))->num_rows() > 0) {
222 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
223 }
224 }
225
226 private function test_exists_with_invalid_data() {
227
228 $provider = array(
229 'first_name' => 'John',
230 'last_name' => 'Doe',
231 'email' => 'test@test.com',
232 'mobile_number' => '000000',
233 'phone_number' => '111111',
234 'address' => 'Some Str',
235 'city' => 'Some City',
236 'state' => 'Some State',
237 'zip_code' => '12345',
238 'notes' => 'This is a test provider',
239 'id_roles' => $this->provider_role_id
240 );
241 $this->ci->db->insert('ea_users', $provider);
242 $provider['id'] = $this->ci->db->insert_id();
243
244
245 $has_thrown_exc = FALSE;
246 try {
247 unset($provider['email']);
248 $this->ci->providers_model->exists($provider);
249 } catch(Exception $exc) {
250 $has_thrown_exc = TRUE;
251 }
252 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test exists() with invalid record data.');
253
254
255 if ($this->ci->db->get_where('ea_users', array('id' => $provider['id']))->num_rows() > 0) {
256 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
257 }
258 }
259
260 private function test_exists_with_record_that_does_not_exist() {
261 $provider = array(
262 'first_name' => 'John',
263 'last_name' => 'Doe',
264 'email' => 'test@test.com',
265 'mobile_number' => '000000',
266 'phone_number' => '111111',
267 'address' => 'Some Str',
268 'city' => 'Some City',
269 'state' => 'Some State',
270 'zip_code' => '12345',
271 'notes' => 'This is a test provider',
272 'id_roles' => $this->provider_role_id
273 );
274
275 $exists = $this->ci->providers_model->exists($provider);
276 $this->ci->unit->run($exists, FALSE, 'Test exists() with record that does not exist.');
277 }
278
279
280 private function test_find_record_id() {
281
282 $provider = array(
283 'first_name' => 'John',
284 'last_name' => 'Doe',
285 'email' => 'test@test.com',
286 'mobile_number' => '000000',
287 'phone_number' => '111111',
288 'address' => 'Some Str',
289 'city' => 'Some City',
290 'state' => 'Some State',
291 'zip_code' => '12345',
292 'notes' => 'This is a test provider',
293 'id_roles' => $this->provider_role_id
294 );
295 $this->ci->db->insert('ea_users', $provider);
296 $insert_id = $this->ci->db->insert_id();
297
298
299 $provider['id'] = $this->ci->providers_model->find_record_id($provider);
300 $this->ci->unit->run($provider['id'], $insert_id, 'Test if find_record_id() has '
301 . 'successfully found the inserted record id.');
302
303
304 if ($this->ci->db->get_where('ea_users', array('id' => $insert_id))->num_rows() > 0) {
305 $this->ci->db->delete('ea_users', array('id' => $insert_id));
306 }
307 }
308
309 private function test_find_record_id_with_invalid_data() {
310 $provider = array(
311 'first_name' => 'John',
312 'last_name' => 'Doe',
313
314 'mobile_number' => '000000',
315 'phone_number' => '111111',
316 'address' => 'Some Str',
317 'city' => 'Some City',
318 'state' => 'Some State',
319 'zip_code' => '12345',
320 'notes' => 'This is a test provider',
321 'id_roles' => $this->provider_role_id
322 );
323
324
325 $has_thrown_exc = FALSE;
326 try {
327 $this->ci->providers_model->find_record_id($provider);
328 } catch(Exception $exc) {
329 $has_thrown_exc = TRUE;
330 }
331
332 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if find_record_id() has thrown '
333 . 'exception on invalid data.');
334 }
335
336 private function test_find_record_id_with_record_that_does_not_exist() {
337
338
339 $provider = array(
340 'first_name' => 'John',
341 'last_name' => 'Doe',
342 'email' => 'test@test.com',
343 'mobile_number' => '000000',
344 'phone_number' => '111111',
345 'address' => 'Some Str',
346 'city' => 'Some City',
347 'state' => 'Some State',
348 'zip_code' => '12345',
349 'notes' => 'This is a test provider',
350 'id_roles' => $this->provider_role_id
351 );
352
353 $has_thrown_exc = FALSE;
354 try {
355 $this->ci->providers_model->find_record_id($provider);
356 } catch(Exception $exc) {
357 $has_thrown_exc = TRUE;
358 }
359
360 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if find_record_id() has thrown '
361 . 'exception on record that does not exist.');
362 }
363
364
365 private function test_validate() {
366 $provider = array(
367 'first_name' => 'John',
368 'last_name' => 'Doe',
369 'email' => 'test@test.com',
370 'mobile_number' => '000000',
371 'phone_number' => '111111',
372 'address' => 'Some Str',
373 'city' => 'Some City',
374 'state' => 'Some State',
375 'zip_code' => '12345',
376 'notes' => 'This is a test provider',
377 'id_roles' => $this->provider_role_id,
378 'services' => array(),
379 'settings' => array(
380 'username' => 'test_prov',
381 'password' => 'test_prov',
382 'working_plan' => $this->default_working_plan,
383 'notifications' => TRUE,
384 'google_sync' => FALSE,
385 'google_token' => NULL,
386 'sync_past_days' => '5',
387 'sync_future_days' => '5'
388 )
389 );
390
391 $validation_result = $this->ci->providers_model->validate($provider);
392 $this->ci->unit->run($validation_result, TRUE, 'Test if validate() returned TRUE '
393 . 'with valid data');
394 }
395
396 private function test_validate_with_record_that_does_not_exist() {
397 $provider = array(
398 'id' => '23209348092',
399 'first_name' => 'John',
400 'last_name' => 'Doe',
401 'email' => 'test@test.com',
402 'mobile_number' => '000000',
403 'phone_number' => '111111',
404 'address' => 'Some Str',
405 'city' => 'Some City',
406 'state' => 'Some State',
407 'zip_code' => '12345',
408 'notes' => 'This is a test provider',
409 'id_roles' => $this->provider_role_id,
410 'services' => array(),
411 'settings' => array(
412 'username' => 'test_prov',
413 'password' => 'test_prov',
414 'working_plan' => $this->default_working_plan,
415 'notifications' => TRUE,
416 'google_sync' => FALSE,
417 'google_token' => NULL,
418 'sync_past_days' => '5',
419 'sync_future_days' => '5'
420 )
421 );
422
423 $has_thrown_exc = FALSE;
424 try {
425 $this->ci->providers_model->validate($provider);
426 } catch (Exception $exc) {
427 $has_thrown_exc = TRUE;
428 }
429 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if validate() has thrown an exception '
430 . 'with record that does not exist.');
431 }
432
433 private function test_validate_with_missing_required_fields() {
434 $provider = array(
435 'first_name' => 'John',
436
437
438 'mobile_number' => '000000',
439
440 'address' => 'Some Str',
441 'city' => 'Some City',
442 'state' => 'Some State',
443 'zip_code' => '12345',
444 'notes' => 'This is a test provider',
445 'id_roles' => $this->provider_role_id,
446 'services' => array(),
447 'settings' => array(
448 'username' => 'test_prov',
449 'password' => 'test_prov',
450 'working_plan' => $this->default_working_plan,
451 'notifications' => TRUE,
452 'google_sync' => FALSE,
453 'google_token' => NULL,
454 'sync_past_days' => '5',
455 'sync_future_days' => '5'
456 )
457 );
458
459 $has_thrown_exc = FALSE;
460 try {
461 $this->ci->providers_model->validate($provider);
462 } catch (Exception $exc) {
463 $has_thrown_exc = TRUE;
464 }
465 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if validate() has thrown an exception '
466 . 'with data that is missing required fields.');
467 }
468
469 private function test_validate_with_invalid_email_address() {
470 $provider = array(
471 'first_name' => 'John',
472 'last_name' => 'Doe',
473 'email' => 'THIS IS INVALID',
474 'mobile_number' => '000000',
475 'phone_number' => '111111',
476 'address' => 'Some Str',
477 'city' => 'Some City',
478 'state' => 'Some State',
479 'zip_code' => '12345',
480 'notes' => 'This is a test provider',
481 'id_roles' => $this->provider_role_id,
482 'services' => array(),
483 'settings' => array(
484 'username' => 'test_prov',
485 'password' => 'test_prov',
486 'working_plan' => $this->default_working_plan,
487 'notifications' => TRUE,
488 'google_sync' => FALSE,
489 'google_token' => NULL,
490 'sync_past_days' => '5',
491 'sync_future_days' => '5'
492 )
493 );
494
495 $has_thrown_exc = FALSE;
496 try {
497 $this->ci->providers_model->validate($provider);
498 } catch (Exception $exc) {
499 $has_thrown_exc = TRUE;
500 }
501 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if validate() has thrown an exception '
502 . 'with data that has invalid email.');
503 }
504
505 private function test_validate_with_no_settings() {
506 $provider = array(
507 'first_name' => 'John',
508 'last_name' => 'Doe',
509 'email' => 'THIS IS INVALID',
510 'mobile_number' => '000000',
511 'phone_number' => '111111',
512 'address' => 'Some Str',
513 'city' => 'Some City',
514 'state' => 'Some State',
515 'zip_code' => '12345',
516 'notes' => 'This is a test provider',
517 'id_roles' => $this->provider_role_id
518 );
519
520 $has_thrown_exc = FALSE;
521 try {
522 $this->ci->providers_model->validate($provider);
523 } catch (Exception $exc) {
524 $has_thrown_exc = TRUE;
525 }
526 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if validate() has thrown an exception '
527 . 'with data that do not contain the provider settings.');
528 }
529
530
531 private function test_delete() {
532
533 $provider = array(
534 'first_name' => 'John',
535 'last_name' => 'Doe',
536 'email' => 'THIS IS INVALID',
537 'mobile_number' => '000000',
538 'phone_number' => '111111',
539 'address' => 'Some Str',
540 'city' => 'Some City',
541 'state' => 'Some State',
542 'zip_code' => '12345',
543 'notes' => 'This is a test provider',
544 'id_roles' => $this->provider_role_id
545 );
546 $this->ci->db->insert('ea_users', $provider);
547 $provider['id'] = intval($this->ci->db->insert_id());
548
549 $provider['services'] = array();
550
551 $provider['settings'] = array(
552 'id_users' => $provider['id'],
553 'username' => 'test-prov',
554 'password' => 'test-prov',
555 'notifications' => FALSE,
556 'working_plan' => $this->default_working_plan,
557 'google_sync' => FALSE,
558 'google_token' => NULL,
559 'sync_past_days' => '5',
560 'sync_future_days' => 5
561 );
562 $this->ci->db->insert('ea_user_settings', $provider['settings']);
563
564
565 $result = $this->ci->providers_model->delete($provider['id']);
566 $this->ci->unit->run($result, TRUE, 'Test if delete() returned TRUE as result');
567
568
569 $provider_num_rows = $this->ci->db->get_where('ea_users',
570 array('id' => $provider['id']))->num_rows();
571 $this->ci->unit->run($provider_num_rows, 0, 'Test if delete() has successfully '
572 . 'deleted provider record.');
573
574 $settings_num_rows = $this->ci->db->get_where('ea_user_settings',
575 array('id_users' => $provider['id']))->num_rows();
576 $this->ci->unit->run($settings_num_rows, 0, 'Test if delete() has successfully '
577 . 'deleted provider settings record.');
578
579
580 if ($provider_num_rows > 0) {
581 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
582 }
583
584 if ($settings_num_rows > 0) {
585 $this->ci->db->delete('ea_user_settings', array('id_users' => $provider['id']));
586 }
587 }
588
589 private function test_delete_with_invalid_record_id() {
590 $invalid_id = 'this is invalid';
591
592 $has_thrown_exc = FALSE;
593 try {
594 $this->ci->providers_model->delete($invalid_id);
595 } catch(Exception $exc) {
596 $has_thrown_exc = TRUE;
597 }
598 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if delete() with invalid id argument '
599 . 'has thrown an exception.');
600 }
601
602 private function test_delete_with_record_that_does_not_exist() {
603 $provider_id = '234082390';
604 $result = $this->ci->providers_model->delete($provider_id);
605 $this->ci->unit->run($result, FALSE, 'Test if delete() with record id that does '
606 . 'not exist in database, has returned FALSE as result.');
607 }
608
609
610 private function test_get_row() {
611
612 $provider = array(
613 'last_name' => 'Doe',
614 'first_name' => 'John',
615 'email' => 'alextselegidis@gmail.com',
616 'phone_number' => '0123456789',
617 'address' => 'Abbey Road 18',
618 'city' => 'London',
619 'zip_code' => '12345',
620 'id_roles' => $this->provider_role_id
621 );
622 $this->ci->db->insert('ea_users', $provider);
623 $provider['id'] = $this->ci->db->insert_id();
624
625 $provider['services'] = array();
626
627 $provider['settings'] = array(
628 'id_users' => $provider['id'],
629 'username' => 'testprov',
630 'password' => 'testprov',
631 'notifications' => FALSE,
632 'working_plan' => $this->default_working_plan,
633 'google_sync' => FALSE,
634 'google_token' => NULL,
635 'sync_past_days' => '5',
636 'sync_future_days' => '5'
637 );
638 $this->ci->db->insert('ea_user_settings', $provider['settings']);
639 unset($provider['settings']['id_users']);
640
641
642 $no_model_provider = $this->ci->db
643 ->get_where('ea_users', array('id' => $provider['id']))
644 ->row_array();
645 $no_model_provider['services'] = array();
646 $no_model_provider['settings'] = $this->ci->db
647 ->get_where('ea_user_settings', array('id_users' => $provider['id']))
648 ->row_array();
649 unset($no_model_provider['settings']['id_users']);
650
651 $model_provider = $this->ci->providers_model->get_row($provider['id']);
652
653 $this->ci->unit->run($no_model_provider, $model_provider, 'Test get_row() method successfully '
654 . 'returned provider record.');
655
656
657 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
658 }
659
660 private function test_get_row_that_does_not_exist() {
661 $random_record_id = 486868412;
662
663 $has_thrown_exc = FALSE;
664 try {
665 $this->ci->providers_model->get_row($random_record_id);
666 } catch (Exception $exc) {
667 $has_thrown_exc = TRUE;
668 }
669 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test if get_row() with record id that does '
670 . 'not exist in the database has thrown an exception.');
671 }
672
673 private function test_get_row_with_invalid_argument() {
674 $invalid_id = 'THIS IS NOT AN INTEGER';
675
676 $has_thrown_exc = FALSE;
677 try {
678 $this->ci->providers_model->get_row($invalid_id);
679 } catch (Exception $exc) {
680 $has_thrown_exc = TRUE;
681 }
682
683 $this->ci->unit->run($has_thrown_exc, TRUE, 'Test get_row() with wrong argument.');
684 }
685
686
687 private function test_get_value() {
688
689 $provider = array(
690 'last_name' => 'Doe',
691 'first_name' => 'John',
692 'email' => 'alextselegidis@gmail.com',
693 'phone_number' => '0123456789',
694 'address' => 'Abbey Road 18',
695 'city' => 'London',
696 'zip_code' => '12345',
697 'id_roles' => $this->provider_role_id
698 );
699 $this->ci->db->insert('ea_users', $provider);
700 $provider['id'] = intval($this->ci->db->insert_id());
701
702
703 $model_value = $this->ci->providers_model->get_value('email', $provider['id']);
704
705
706 $this->ci->unit->run($model_value, $provider['email'], 'Test get_value() method.');
707
708
709 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
710 }
711
712 private function test_get_value_record_does_not_exist() {
713 $random_record_id = 843521368768;
714
715 $has_thrown_exception = FALSE;
716
717 try {
718 $this->ci->providers_model->get_value('email', $random_record_id);
719 } catch (Exception $exc) {
720 $has_thrown_exception = TRUE;
721 }
722
723 $this->ci->unit->run($has_thrown_exception, TRUE, 'Test get_value() with record id that '
724 . 'does not exist.');
725 }
726
727 private function test_get_value_field_does_not_exist() {
728
729 $provider = array(
730 'last_name' => 'Doe',
731 'first_name' => 'John',
732 'email' => 'alextselegidis@gmail.com',
733 'phone_number' => '0123456789',
734 'address' => 'Abbey Road 18',
735 'city' => 'London',
736 'zip_code' => '12345',
737 'id_roles' => $this->provider_role_id
738 );
739 $this->ci->db->insert('ea_users', $provider);
740 $provider['id'] = intval($this->ci->db->insert_id());
741
742
743 $wrong_field_name = 'THIS IS WRONG';
744 $has_thrown_exception = FALSE;
745
746 try {
747 $this->ci->providers_model->get_value($wrong_field_name, $provider['id']);
748 } catch (Exception $exc) {
749 $has_thrown_exception = TRUE;
750 }
751
752 $this->ci->unit->run($has_thrown_exception, TRUE, 'Test get_value() with record id that '
753 . 'does not exist.');
754
755
756 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
757 }
758
759
760 private function test_get_batch() {
761
762 $db_data = $this->ci->db
763 ->get_where('ea_users', array('id_roles' => $this->provider_role_id))
764 ->result_array();
765
766 foreach($db_data as &$db_provider) {
767 $services = $this->ci->db
768 ->get_where('ea_services_providers', array('id_users' => $db_provider['id']))
769 ->result_array();
770 $db_provider['services'] = array();
771 foreach($services as $service) {
772 $db_provider['services'][] = $service['id_services'];
773 }
774
775
776 $db_provider['settings'] = $this->ci->db
777 ->get_where('ea_user_settings', array('id_users' => $db_provider['id']))
778 ->row_array();
779 unset($db_provider['settings']['id_users']);
780 }
781
782
783 $model_data = $this->ci->providers_model->get_batch();
784
785
786 $this->ci->unit->run($db_data, $model_data, 'Test get_batch() method.');
787 }
788
789 private function test_get_batch_with_where_clause() {
790
791 $provider = array(
792 'last_name' => 'Doe',
793 'first_name' => 'John',
794 'email' => 'alextselegidis@gmail.com',
795 'phone_number' => '0123456789',
796 'address' => 'Abbey Road 18',
797 'city' => 'London',
798 'zip_code' => '12345',
799 'id_roles' => $this->provider_role_id
800 );
801 $this->ci->db->insert('ea_users', $provider);
802 $provider['id'] = intval($this->ci->db->insert_id());
803
804 $settings = array(
805 'id_users' => $provider['id'],
806 'username' => 'testprov',
807 'password' => 'testprov',
808 'notifications' => FALSE,
809 'working_plan' => $this->default_working_plan,
810 'google_sync' => FALSE,
811 'google_token' => NULL,
812 'sync_past_days' => '5',
813 'sync_future_days' => '5'
814 );
815 $this->ci->db->insert('ea_user_settings', $settings);
816
817
818 $no_model_batch = $this->ci->db
819 ->get_where('ea_users', array('id' => $provider['id']))
820 ->result_array();
821
822 foreach($no_model_batch as &$no_model_provider) {
823 $services = $this->ci->db
824 ->get_where('ea_services_providers', array('id_users' => $provider['id']))
825 ->result_array();
826 $no_model_provider['services'] = array();
827 foreach($services as $service) {
828 $no_model_provider['services'][] = $service['id_services'];
829 }
830
831
832 $no_model_provider['settings'] = $this->ci->db
833 ->get_where('ea_user_settings', array('id_users' => $no_model_provider['id']))
834 ->row_array();
835 unset($no_model_provider['settings']['id_users']);
836 }
837
838
839 $model_batch = $this->ci->providers_model->get_batch(array('id' => $provider['id']));
840
841
842 $this->ci->unit->run($no_model_batch, $model_batch, 'Test get_batch() with where clause.');
843
844
845 $this->ci->db->delete('ea_users', array('id' => $provider['id']));
846 }
847
848 private function unabled_test_get_batch_with_invalid_where_clause() {
849
850 }
851 }
852
853
854
855