Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 172
0.00% covered (danger)
0.00%
0 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
Reason_test
0.00% covered (danger)
0.00%
0 / 172
0.00% covered (danger)
0.00%
0 / 14
342
0.00% covered (danger)
0.00%
0 / 1
 __construct
n/a
0 / 0
n/a
0 / 0
1
 test_index
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSvRSNListPage
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSvRSNAddPage
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNAddEvent_C1
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNAddEvent_C2
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNAddEvent_C3
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
6
 test_FSvRSNEditPage_C1
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
 test_FSvRSNEditPage_C2
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNEditEvent_C1
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
6
 test_FSaRSNDeleteEvent_C1
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSvRSNDataList_C1
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSvRSNDataList_C2
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNEditEvent_C4
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
 test_FSaRSNEditEvent_C5
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Part of ci-phpunit-test
4 *
5 * @author     Kenji Suzuki <https://github.com/kenjis>
6 * @license    MIT License
7 * @copyright  2015 Kenji Suzuki
8 * @link       https://github.com/kenjis/ci-phpunit-test
9 */
10
11class Reason_test extends TestCase
12{
13    // public function setUp(): void {
14    //    echo $this->getName();
15    // }
16    /** 
17    *@codeCoverageIgnore
18    */
19    public function __construct() {
20        parent::__construct();
21        $ci = &get_instance();
22        $ci->load->database();
23        $ci->load->helper('validator_helper');
24        $this->code = substr(md5(uniqid(mt_rand(), true)), 0, 5);
25        $_SESSION =array (
26            '__ci_last_regenerate' => 1674475513,
27            'lang' => 'th',
28            'tLangID' => 1,
29            'tSesUserLogin' => '009',
30            'tSesUsrRoleCodeMulti' => '\'00002\'',
31            'nSesUsrRoleLevel' => 99,
32            'tSesUsrAgnCode' => NULL,
33            'tSesUsrAgnName' => NULL,
34            'tSesUsrMerCode' => NULL,
35            'tSesUsrMerName' => NULL,
36            'tSesUsrBchCodeDefault' => '00001',
37            'tSesUsrBchNameDefault' => 'AdaSoft00001',
38            'tSesUsrBchCodeMulti' => '\'00001\'',
39            'tSesUsrBchNameMulti' => '\'AdaSoft00001\'',
40            'nSesUsrBchCount' => 0,
41            'tSesUsrShpCodeDefault' => '00014',
42            'tSesUsrShpNameDefault' => 'รันไทม์ช็อป',
43            'tSesUsrShpCodeMulti' => '\'00014\'',
44            'tSesUsrShpNameMulti' => '\'รันไทม์ช็อป\'',
45            'nSesUsrShpCount' => 0,
46            'tSesUsrWahCode' => '00001',
47            'tSesUsrWahName' => 'คลังขาย',
48            'tSesUsrLoginLevel' => 'HQ',
49            'tSesUsrLoginAgency' => 0,
50            'bSesLogIn' => 1,
51            'tSesUserCode' => '00002',
52            'tSesUsername' => '00002',
53            'tSesUsrDptName' => NULL,
54            'tSesUsrDptCode' => NULL,
55            'tSesUsrUsername' => 'Adasoft',
56            'tSesUsrImagePerson' => NULL,
57            'tSesUsrInfo' => 
58            array (
59              'FTUsrStaActive' => 1,
60              'FTUsrLogType' => 1,
61              'FTStaError' => 0,
62              'FTUsrCode' => '00002',
63              'FTUsrName' => 'Adasoft',
64              'FTDptCode' => NULL,
65              'FTDptName' => NULL,
66              'FTImgObj' => NULL,
67            ),
68            'tSesUsrGroup' => 
69            array (
70              0 => 
71              array (
72                'FTUsrCode' => '00002',
73                'FTAgnCode' => NULL,
74                'FTAgnName' => NULL,
75                'FTBchCode' => NULL,
76                'FTBchName' => NULL,
77                'FTShpCode' => NULL,
78                'FTShpName' => NULL,
79                'FTMerCode' => NULL,
80                'FTMerName' => NULL,
81                'FTWahCode' => NULL,
82                'FTWahName' => NULL,
83                'FTLoginLevel' => 'HQ',
84                'FTStaLoginAgn' => 0,
85              ),
86            ),
87            'tSesSessionID' => '0000220230123185822',
88            'tSesSessionDate' => '2023-01-23 18:58:22',
89            'tLangEdit' => 1,
90            'bIsHaveAgn' => NULL,
91            'tSesUsrLevel' => 'HQ',
92            'tSesUsrRoleSpcCodeMulti' => '\'00002\',\'00003\',\'00004\',\'00005\',\'00006\',\'00007\',\'00008\',\'00009\',\'00010\',\'00011\',\'00012\',\'00013\',\'00014\',\'00016\',\'00017\',\'00018\',\'00019\',\'00020\',\'00021\',\'00022\',\'00023\',\'00024\',\'00025\',\'00026\',\'00027\',\'00028\',\'00029\',\'00030\',\'00031\',\'00032\',\'00033\',\'00034\',\'00035\',\'00036\',\'00037\',\'00038\'',
93            'bShpEnabled' => 1,
94            'bAgnEnabled' => 1,
95            'bLockerEnabled' => NULL,
96            'bPdtFasionEnabled' => NULL,
97            'tSesHQBchCode' => '00001',
98            'bSesRegStaLicense' => 1,
99            'tSesCstKey' => '52a8a4705e6c',
100            'bSesRegStaBuyPackage' => 1,
101        );
102
103
104    }
105
106    //1.เข้าหน้า index สำเร็จ
107    //ทดสอบเข้าหน้ามาสเตอร์
108    public function test_index(){
109        print ' 1.เข้าหน้า index สำเร็จ\n';
110        $oOutput = $this->request(
111            'POST',
112            'other/reason/cReason/index/0/0'
113        );
114        $this->assertStringContainsString('oetRsnStaBrowse', $oOutput);
115        $this->assertResponseCode(200);
116    }
117
118    //2.เข้าหน้า list สำเร็จ
119    //ทดสอบเข้าหน้า List
120    public function test_FSvRSNListPage(){
121        print ' 2.เข้าหน้า list สำเร็จ';
122        $oOutput = $this->request(
123            'POST',
124            'other/reason/cReason/FSvRSNListPage'
125        );
126        $this->assertStringContainsString('ostDataReasion', $oOutput);
127        $this->assertResponseCode(200);
128    }
129
130    //3.เข้าหน้า Add สำเร็จ
131    //ทดสอบเข้าหน้าเพิ่มข้อมูล
132    public function test_FSvRSNAddPage(){
133        print ' 3.เข้าหน้า Add สำเร็จ';
134        $oOutput = $this->request(
135            'POST',
136            'other/reason/cReason/FSvRSNAddPage'
137        );
138        $this->assertStringContainsString('obtSubmitReason', $oOutput);
139        $this->assertResponseCode(200);
140    }
141
142    //4.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างอัตโนมัติ ต้องได้ผลลัพท์คือเพิ่มได้สำเร็จ
143    //สร้างแบบปกติ ระบุเพียงชื่อเหตุผลอย่างเดียว และ สร้างรหัสอัตโนมัติ
144    public function test_FSaRSNAddEvent_C1(){
145        print ' 4.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างอัตโนมัติ ต้องได้ผลลัพท์คือเพิ่มได้สำเร็จ';
146        $aParam = array(
147            'ocbReasonAutoGenCode'   => '1',
148            'oetRsnCode'=> '',
149            'ocmRcnGroup' => '001',
150            'oetRsnName'  => 'ทดสอบ',
151            'oetRsnRemark'  => '',
152            'oetRSNAgnCode'  => ''
153        );
154        $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSaRSNAddEvent',$aParam);
155        $this->assertStringContainsString(
156            'Success Add Event', $oOutput
157        );
158        $this->assertResponseCode(200);
159        
160    }
161
162    //5.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างเองแบบคีย์ ต้องได้ผลลัพท์คือเพิ่มได้สำเร็จ
163    //สร้างแบบ รหัสแบบกรอกเองแบบไม่ซ้ำ และ ระบุชื่อเพียงอย่างเดียว
164    public function test_FSaRSNAddEvent_C2(){
165        print ' 5.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างเองแบบคีย์ ต้องได้ผลลัพท์คือเพิ่มได้สำเร็จ';
166        $aParam = array(
167            'ocbReasonAutoGenCode'   => '0',
168            'oetRsnCode'=> $this->code,
169            'ocmRcnGroup' => '001',
170            'oetRsnName'  => 'ทดสอบ '.$this->code,
171            'oetRsnRemark'  => '',
172            'oetRSNAgnCode'  => ''
173        );
174        $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSaRSNAddEvent',$aParam);
175        $this->assertStringContainsString(
176            'Success Add Event', $oOutput
177        );
178        $this->assertResponseCode(200);
179        
180    }
181
182        //6.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างเองแบบคีย์ และ รหัสเคยมีอยู่แล้ว ต้องได้ผลลัพท์คือการอัพเดทแทนที่
183        //สร้างแบบ รหัสแบบกรอกเองแบบซ้ำ และ ระบุชื่อเพียงอย่างเดียว
184        public function test_FSaRSNAddEvent_C3(){
185            print ' 6.เพิ่มข้อมูล โดยระบุเหตุผล และ รหัสสร้างเองแบบคีย์ และ รหัสเคยมีอยู่แล้ว ต้องได้ผลลัพท์คือการอัพเดทแทนที่';
186            $ci = &get_instance();
187            $ci->load->database();
188            $aResult = $ci->db->select(['FTRsnCode','FTRsnName'])->where('FNLngID',1)->where('FTRsnCode!=','')->limit(1)->get('TCNMRsn_L')->row_array();
189            if(!empty($aResult)){
190                $aParam = array(
191                    'ocbReasonAutoGenCode'   => '0',
192                    'oetRsnCode'=> $aResult['FTRsnCode'],
193                    'ocmRcnGroup' => '001',
194                    'oetRsnName'  => $aResult['FTRsnName'],
195                    'oetRsnRemark'  => '',
196                    'oetRSNAgnCode'  => ''
197                );
198            }
199            $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSaRSNAddEvent',$aParam);
200            $this->assertStringContainsString(
201                'Data Code Duplicate', $oOutput
202            );
203            $this->assertResponseCode(200);
204            
205        }
206
207
208    //7.เข้าหน้าจอแก้ไขแบบมีข้อมูลจริง  ต้องได้ผลลัพท์สำเร็จ
209    //ทดสอบเข้าหน้าแก้ไข แบบปกติ
210    public function test_FSvRSNEditPage_C1(){
211        print ' 7.เข้าหน้าจอแก้ไขแบบมีข้อมูลจริง  ต้องได้ผลลัพท์สำเร็จ';
212        $ci = &get_instance();
213        $ci->load->database();
214        $aResult = $ci->db->select(['FTRsnCode','FTRsnName'])->where('FNLngID',1)->where('FTRsnCode!=','')->limit(1)->get('TCNMRsn_L')->row_array();
215        if(!empty($aResult)){
216            $oOutput = $this->request(
217                'POST',
218                'other/reason/cReason/FSvRSNEditPage',
219                ['tRsnCode'=>$aResult['FTRsnCode']]
220            );
221
222        }
223
224        $this->assertStringContainsString('obtSubmitReason', $oOutput);
225        $this->assertResponseCode(200);
226    }
227    //8.เข้าหน้าจอแก้ไขแบบไม่มีข้อมูลจริง  ต้องได้ผลลัพท์สำเร็จแต่ไม่มีข้อมูลเป็นหน้า Add ปกติ
228    //ทดสอบเข้าหน้าแก้ไข แบบไม่มีข้อมูลจริงๆ
229    public function test_FSvRSNEditPage_C2(){
230        print ' 8.เข้าหน้าจอแก้ไขแบบไม่มีข้อมูลจริง  ต้องได้ผลลัพท์สำเร็จแต่ไม่มีข้อมูลเป็นหน้า Add ปกติ';
231        $oOutput = $this->request(
232            'POST',
233            'other/reason/cReason/FSvRSNEditPage',
234            ['tRsnCode'=>'0018984515']
235        );
236        $this->assertStringContainsString('obtSubmitReason', $oOutput);
237        $this->assertResponseCode(200);
238    }
239
240    //9.อัพเดทข้อมูล ระบุชื่อเหตุผลใหม่ไปด้วยความยาวที่ไม่เกิน ผลลัพท์ต้องสำเร็จ
241    //แก้ไขข้อมูล แก้ชื่อใหม่
242    public function test_FSaRSNEditEvent_C1(){
243        print ' 9.อัพเดทข้อมูล ระบุชื่อเหตุผลใหม่ไปด้วยความยาวที่ไม่เกิน ผลลัพท์ต้องสำเร็จ';
244        $ci = &get_instance();
245        $ci->load->database();
246        $aResult = $ci->db->select(['FTRsnCode','FTRsnName'])->where('FNLngID',1)->where('FTRsnCode!=','')->limit(1)->get('TCNMRsn_L')->row_array();
247        if(!empty($aResult)){
248            $aParam = array(
249                'ocbReasonAutoGenCode'   => '0',
250                'oetRsnCode'=> $aResult['FTRsnCode'],
251                'ocmRcnGroup' => '001',
252                'oetRsnName'  => $aResult['FTRsnName'],
253                'oetRsnRemark'  => '',
254                'oetRSNAgnCode'  => ''
255            );
256        }
257        $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSaRSNEditEvent',$aParam);
258        $this->assertStringContainsString(
259            'Success Add Event', $oOutput
260        );
261        $this->assertResponseCode(200);
262        
263    }
264
265        //10. ทดสอบลบข้อมูลแบบเดี่ยว ส่งข้อมูลไปแบบมีอยู่จริง ผลลัพท์ต้องได้สำเร็จ
266        //ลบข้อมูลแบบปกติ Sigle
267        public function test_FSaRSNDeleteEvent_C1(){
268            print ' 10.ทดสอบลบข้อมูลแบบเดี่ยว ส่งข้อมูลไปแบบมีอยู่จริง ผลลัพท์ต้องได้สำเร็จ';
269            $aParam = array(
270                'tIDCode'   => $this->code,
271            );
272            $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSaRSNDeleteEvent',$aParam);
273            $this->assertStringContainsString(
274                'Delete Success', $oOutput
275            );
276            $this->assertResponseCode(200);
277        
278        }
279
280        //11.ทดสอบค้นหาข้อมูลจากหน้าจอ
281        public function test_FSvRSNDataList_C1(){
282            print ' 11.ทดสอบค้นหาข้อมูลจากหน้าจอ ต้องสำเร็จ';
283            $aParam = array(
284                'nPageCurrent'   => 1,
285                'tSearchAll'   => 'ทดสอบ'
286            );
287            $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSvRSNDataList',$aParam);
288            $this->assertStringContainsString(
289                'nCurrentPageTB', $oOutput
290            );
291            $this->assertResponseCode(200);
292        
293        }
294
295
296
297        //12.ทดสอบกดหน้าถัดไป
298        public function test_FSvRSNDataList_C2(){
299            print ' 12.ทดสอบกดหน้าถัดไป';
300            $aParam = array(
301                'nPageCurrent'   => 2,
302                'tSearchAll'   => ''
303            );
304            $oOutput = $this->ajaxRequest('POST', 'other/reason/cReason/FSvRSNDataList',$aParam);
305            $this->assertStringContainsString(
306                'nCurrentPageTB', $oOutput
307            );
308            $this->assertResponseCode(200);
309        
310        }
311        
312
313
314
315    //13.อัพเดทข้อมูล ระบุชื่อเหตุผลใหม่ไปด้วยความยาวที่ไม่เกิน ผลลัพท์ต้องสำเร็จ
316    //แก้ไขข้อมูล แก้ชื่อใหม่
317    public function test_FSaRSNEditEvent_C4(){
318        print ' 13.เพิ่มข้อมูลแบบรหัสอัตโนมัติและมีชื่อที่นาวเกินขนาดฟิว';
319        $aParam = array(
320            'ocbReasonAutoGenCode'   => '1',
321            'oetRsnCode'=> '',
322            'ocmRcnGroup' => '001',
323            'oetRsnName'  => 'ทดสอบใหม่ ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่ทดสอบใหม่',
324            'oetRsnRemark'  => '',
325            'oetRSNAgnCode'  => ''
326        );
327        //validator
328        $afield = [
329            'ocbReasonAutoGenCode' => 'max:1',
330            'oetRsnCode' => 'required,max:5',
331            'ocmRcnGroup' => 'required,max:5',
332            'oetRsnName' => 'max:200',
333            'oetRsnRemark' => 'max:100',
334            'oetRSNAgnCode' => 'max:10',
335        ];
336       $aResult = json_encode(validate($aParam,$afield));
337        $this->assertStringContainsString('The oetRsnName must have at most 200 characters', $aResult);
338    
339    }
340
341    //13.อัพเดทข้อมูล ระบุชื่อเหตุผลใหม่ไปด้วยความยาวที่ไม่เกิน ผลลัพท์ต้องสำเร็จ
342    //แก้ไขข้อมูล แก้ชื่อใหม่
343    public function test_FSaRSNEditEvent_C5(){
344        print ' 14.เพิ่มข้อมูลแบบผิดประเภทของฟิวด์';
345        $aParam = array(
346            'ocbReasonAutoGenCode'   => '1',
347            'oetRsnCode'=> '',
348            'ocmRcnGroup' => '001',
349            'oetRsnName'  => array('testfailr'),
350            'oetRsnRemark'  => '',
351            'oetRSNAgnCode'  => ''
352        );
353        $afield = array(
354            'ocbReasonAutoGenCode'   => 'string',
355            'oetRsnCode'=> 'string',
356            'ocmRcnGroup' => 'string',
357            'oetRsnName'  => 'string',
358            'oetRsnRemark'  => 'string',
359            'oetRSNAgnCode'  => 'string'
360        );
361        // print gettype($aParam['oetRsnName']);
362        
363        $aResult = json_encode(validate_type($aParam,$afield));
364        $this->assertStringContainsString('Error type varible ', $aResult);
365        
366    }
367
368
369
370
371}