Odyssey
TestCuTdApi.php
1 <?php
2 
3 use PHPUnit\Framework\TestCase;
4 
5 /**
6  * Unit test for the cutd_list() api. cutd_list() allows usage of a single trusted ID
7  * or an array of trusted id's, other functions accessing it nuke/ don't use the
8  * input of $_POST['trustedids'].
9  *
10  * ************************* NOTE TO TEST LIVE CONNECTION **************************
11  * This will require one modification: your HCUticket cookie for www4. The HCUticket
12  * value can be obtained by viewing your logged in cookies in the browser or doing
13  * a D & D of $_COOKIE somewhere (after logging into www4.) Place the resulting
14  * value in the "your_cookie" property below.
15  * **********************************************************************************
16  */
17 class TestCuTdApi extends TestCase
18 {
19  /**
20  * @var string to test the actual curl connection, log in to www4 and get your
21  * HCUticket cookie value from your browser. All tests fail without it.
22  */
23  protected $your_cookie = '';
24 
25  /**
26  * @var string Only use to test live curl connection. Can be changed to your local
27  * docker IP if you like.
28  */
29  protected $url = 'http://www4.homecu.net/hcuadm/CuVendorListApi.prg';
30 
31  /**
32  * Test API, single trust ID, empty Cu.
33  * @return void
34  */
36  {
37  $post = [
38  'Cu' => '',
39  'trustedid' => 'IPAY_V3'
40  ];
41  // Use this to actually post.
42  //$this->runAssertions($post);
43 
44  $result = $this->singleTrustIdEmptyCuResult();
45  $this->assertArrayHasKey('status', $result);
46  $this->assertArrayHasKey('data', $result);
47  }
48 
49  /**
50  * Test API, single trust ID and SCRUBCU.
51  * @return void
52  */
54  {
55  $post = [
56  'Cu' => 'SCRUBCU',
57  'trustedid' => 'IPAY_V3'
58  ];
59  // Use this to actually post.
60  //$this->runAssertions($post);
61 
62  $result = $this->singleTrustIdScrubCuResult();
63  $this->assertArrayHasKey('status', $result);
64  $this->assertArrayHasKey('data', $result);
65  }
66 
67  /**
68  * Test API, array of ID's, empty Cu.
69  * @return void
70  */
72  {
73  $post = [
74  'Cu' => '',
75  'trustedids' => json_encode([
76  'abeAI', 'ACCSOFT', 'ALLIEDPAY_SSO', 'MWI_LOANPAY', 'BDI', 'RDCBluepoint', 'RDCTranzCap', 'CERTEGY',
77  'RDCCheckAlt', 'CHKFREE', 'CUDIRECT_SSO', 'DELUXE_OP', 'Bit', 'Digital', 'DMI', 'HcuDMI', 'MemberPay',
78  'RDCENSENTA', 'ENSENTA_BRDC', 'FICS', 'HcuEZCARD', 'FIS_EZCARD', 'FISERV_CPS', 'RDCTest', 'FWDTranzCap',
79  'MBLPAY_TEST', 'hcuLoanApp', 'HcuMIR', 'HOMECUSERVICE', 'HcuCheckImages', 'IDS_ES', 'IPAY', 'IPAYMBL',
80  'IPAY_V3', 'IPAYBPS', 'IPAYAPP', 'IPAYTEST', 'LASERPRINT_ES', 'LASERTEC_ES', 'MDesk3', 'MDesk',
81  'PAYVERIS', 'PAYZUR_SSO', 'PSCUPAY_SSO', 'PSCUPAY_API', 'PSCUINFO', 'PSCU_ACCPT', 'SavvyMo_SSO',
82  'ThinkDigital', 'RDCDigiliti', 'GOTOMYCARD', 'RDCVsoft', 'VSOFT', 'WebShare', 'MeridianLink'
83  ])
84  ];
85 
86  // Use this to actually post.
87  //$this->runAssertions($post);
88 
89  $result = $this->trustIdArrayNoCu();
90  $this->assertArrayHasKey('status', $result);
91  $this->assertArrayHasKey('data', $result);
92  }
93 
94  /**
95  * Test API, array of ID's, SCRUBCU.
96  * @return void
97  */
99  {
100  $post = [
101  'Cu' => 'SCRUBCU',
102  'trustedids' => json_encode([
103  'abeAI', 'ACCSOFT', 'ALLIEDPAY_SSO', 'MWI_LOANPAY', 'BDI', 'RDCBluepoint', 'RDCTranzCap', 'CERTEGY',
104  'RDCCheckAlt', 'CHKFREE', 'CUDIRECT_SSO', 'DELUXE_OP', 'Bit', 'Digital', 'DMI', 'HcuDMI', 'MemberPay',
105  'RDCENSENTA', 'ENSENTA_BRDC', 'FICS', 'HcuEZCARD', 'FIS_EZCARD', 'FISERV_CPS', 'RDCTest', 'FWDTranzCap',
106  'MBLPAY_TEST', 'hcuLoanApp', 'HcuMIR', 'HOMECUSERVICE', 'HcuCheckImages', 'IDS_ES', 'IPAY', 'IPAYMBL',
107  'IPAY_V3', 'IPAYBPS', 'IPAYAPP', 'IPAYTEST', 'LASERPRINT_ES', 'LASERTEC_ES', 'MDesk3', 'MDesk',
108  'PAYVERIS', 'PAYZUR_SSO', 'PSCUPAY_SSO', 'PSCUPAY_API', 'PSCUINFO', 'PSCU_ACCPT', 'SavvyMo_SSO',
109  'ThinkDigital', 'RDCDigiliti', 'GOTOMYCARD', 'RDCVsoft', 'VSOFT', 'WebShare', 'MeridianLink'
110  ])
111  ];
112 
113  // Use this to actually post.
114  //$this->runAssertions($post);
115 
116  $result = $this->trustIdArrayNoCu();
117  $this->assertArrayHasKey('status', $result);
118  $this->assertArrayHasKey('data', $result);
119  }
120 
121  /**
122  * Common to all live tests, run assertions that check if we have an array with status and data members.
123  * @param array $post
124  * @return void
125  */
126  protected function runAssertions($post)
127  {
128  $result = $this->postToUrl($post);
129  $this->assertArrayHasKey('status', $result);
130  $this->assertArrayHasKey('data', $result);
131  }
132 
133  /**
134  * Mock the response received from a live curl call, single trust ID, no CU.
135  * @return array
136  */
137  protected function singleTrustIdEmptyCuResult()
138  {
139  return [
140  'status' => [
141  'Response' => true,
142  'Message' => 'OK',
143  'Errors' => []
144  ],
145  'data' => [
146  'SCRUBCU|IPAY_V3]' => [
147  'cu' => 'SCRUBCU',
148  'trustedid' => 'IPAY_V3',
149  'fields' => []
150  ],
151  'CRUISECU|IPAY_V3]' => [
152  'cu' => 'CRUISECU',
153  'trustedid' => 'IPAY_V3',
154  'fields' => []
155  ]
156  ]
157  ];
158  }
159 
160  /**
161  * Mock the response received from a live curl call, single trust ID, SCRUBCU.
162  * @return array
163  */
164  protected function singleTrustIdScrubCuResult()
165  {
166  return [
167  'status' => [
168  'Response' => true,
169  'Message' => 'OK',
170  'Errors' => []
171  ],
172  'data' => [
173  'SCRUBCU|IPAY_V3]' => [
174  'cu' => 'SCRUBCU',
175  'trustedid' => 'IPAY_V3',
176  'fields' => []
177  ]
178  ]
179  ];
180  }
181 
182  /**
183  * Mock the response with array of trusted ID's and no CU specified.
184  * This is a shortened version of the actual return array you'll get.
185  * @return array
186  */
187  protected function trustIdArrayNoCu()
188  {
189  return [
190  'status' => [
191  'Response' => true,
192  'Message' => 'OK',
193  'Errors' => []
194  ],
195  'data' => [
196  'SCRUBCU|ACCSOFT' => [
197  'cu' => 'SCRUBCU',
198  'trustedid' => 'CCSOFT',
199  'fields' => [
200  'privateKey' => '',
201  'sharedKey' => '',
202  ]
203  ],
204  'SCRUBCU|CERTEGY' => [
205  'cu' => 'SCRUBCU',
206  'trustedid' => 'CERTEGY',
207  'fields' => [
208  'FIID' => '0006',
209  'ACCOUNT' => '',
210  'pilotURL' => 'https://bp01.premierbillpay.com/servlet/tpservlet',
211  'certegyKey' => '8Pqb@NZ&!JH%g89Fql0m12P$',
212  'pilotKey' => 'pO_cI0m&asoagia4lec#uHI8',
213  'certegyURL' => 'https://sso-redirector.ezbills.com/mvsso/servlet/tpservlet',
214  'pilot' => 0,
215  'hcuLogging' => 0
216  ]
217  ],
218  'CRUISECU|IPAY_V3]' => [
219  'cu' => 'CRUISECU',
220  'trustedid' => 'IPAY_V3',
221  'fields' => []
222  ]
223  ]
224  ];
225  }
226 
227  /**
228  * Mock the response with an array of trusted ID's and SCRUBCU specified.
229  * This is a shortened version of the actual return array you'll get.
230  * @return array
231  */
232  protected function trustIdArrayScrubCu()
233  {
234  return [
235  'status' => [
236  'Response' => true,
237  'Message' => 'OK',
238  'Errors' => []
239  ],
240  'data' => [
241  'SCRUBCU|ACCSOFT' => [
242  'cu' => 'SCRUBCU',
243  'trustedid' => 'CCSOFT',
244  'fields' => [
245  'privateKey' => '',
246  'sharedKey' => '',
247  ]
248  ],
249  'SCRUBCU|CERTEGY' => [
250  'cu' => 'SCRUBCU',
251  'trustedid' => 'CERTEGY',
252  'fields' => [
253  'FIID' => '0006',
254  'ACCOUNT' => '',
255  'pilotURL' => 'https://bp01.premierbillpay.com/servlet/tpservlet',
256  'certegyKey' => '8Pqb@NZ&!JH%g89Fql0m12P$',
257  'pilotKey' => 'pO_cI0m&asoagia4lec#uHI8',
258  'certegyURL' => 'https://sso-redirector.ezbills.com/mvsso/servlet/tpservlet',
259  'pilot' => 0,
260  'hcuLogging' => 0
261  ]
262  ]
263  ]
264  ];
265  }
266 
267  /**
268  * Basic native curl call for tests. Use only yo test live, do not leave calls in unit test.
269  * @param array [Cu => string optional, trustid => string optional, trustids => string (JSON encoded array), optional]
270  * @return array
271  */
272  protected function postToUrl($post)
273  {
274  $params = http_build_query($post);
275 
276  $curlcookies = "HCUTicket={$this->your_cookie};";
277 
278  $ch = curl_init($this->url);
279  curl_setopt($ch,CURLOPT_COOKIE, $curlcookies);
280  curl_setopt($ch,CURLOPT_USERPWD,"nobody:no1home");
281  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
282  curl_setopt($ch,CURLOPT_POST, true);
283  curl_setopt($ch,CURLOPT_POSTFIELDS, $params);
284  //curl_setopt($ch, CURLOPT_VERBOSE, true);
285 
286  $rawresp = curl_exec($ch);
287 
288  return json_decode($rawresp, true);
289  }
290 
291 }
singleTrustIdScrubCuResult()
runAssertions($post)
singleTrustIdEmptyCuResult()
test_has_results_with_array_of_trust_ids_and_empty_cu()
Definition: TestCuTdApi.php:71
test_has_results_with_single_trust_id_and_has_cu()
Definition: TestCuTdApi.php:53
test_test_has_results_with_single_trust_id_and_has_cu()
Definition: TestCuTdApi.php:98
test_has_results_with_single_trust_id_and_empty_cu()
Definition: TestCuTdApi.php:35
postToUrl($post)