Odyssey
TestCompassSingleNodeSelection.php
1 <?php
2 
3 use PHPUnit\Framework\TestCase;
4 
5 require_once('hcuTranslate.i');
6 require_once('menu-creators/CreateMenu.php');
7 require_once('menu-creators/CompassMenu.php');
8 
9 /**
10  * Unit test for the Compass Menu functionality, a WIP. Test that the single node selection
11  * works, whether top level or nested selections. AssertSame() used over assertEquals()
12  * because it is more strict(ish,) unit compares both type and value.
13  */
14 class TestCompassSingleNodeSelection extends TestCase
15 {
16  /** @var object CompassMenu class */
17  protected $CompassObj = null;
18 
19  /** @var array just the items we need to instantiate the class and run our tests. */
20  protected $HB_ENV = [
21  'MC' => null,
22  'Cu' => 'SCRUBCU',
23  'Cn' => 'BongoBob',
24  'Uid' => 19,
25  'loginpath' => 'http://localhost:8000/banking',
26  'cuquery' => 'cu=SCRUBCU',
27  ];
28  /** @var string Mock of JSON returned by hcuFunctions.i->CompassMenuJson(). */
29  protected $json = '';
30  /**
31  * @var string The compass menu config for unit testing. Would rather have a copy of
32  * this so unit tests don't break if it changes, but in one scenario that is what
33  * we want. Uses PHP path info.
34  */
35  protected $json_path = 'banking/library/menu-creators/compass-menu-config.json';
36 
37  /**
38  * Set the properties used by all tests. HB_ENV is an injected dependency for CompassMenu.
39  */
40  public function setUp()
41  {
42  $this->json = $this->mockJson();
43  $this->HB_ENV['MC'] = new hcu_talk_base('en_US');
44  $this->CompassObj = new CompassMenu($this->HB_ENV);
45  }
46 
47  /**
48  * Test the user activity top level node without the node wrapper <li>.
49  * @return void
50  */
52  {
53  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'user-activity');
54  $expected = $this->topLevelUserActivityNode();
55  //echo "\n\n EXPECTED\n\n->$expected<-\n\nACTUAL ->$result<-\n\n";
56  $this->assertSame($expected, $result);
57  }
58 
59  /**
60  * Test the user activity top level node with the full wrapper <li>.
61  * @return void
62  */
64  {
65  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'user-activity', true);
66  $expected = $this->topLevelUserActivityNodeWithWrapper();
67 
68  $this->assertSame($expected, $result);
69  }
70 
71  /**
72  * Test the secure email top level node without the node wrapper <li>.
73  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'secure-email-item');
74  * @return void
75  */
77  {
78  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'secure-email-item');
79  $expected = $this->topLevelSecureEmailNode();
80 
81  $this->assertSame($expected, $result);
82  }
83 
84  /**
85  * Test thesecure email top level node with the full wrapper <li>.
86  * @return void
87  */
89  {
90  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'secure-email-item', true);
91  $expected = $this->topLevelSecureEmailNodeWithWrapper();
92 
93  $this->assertSame($expected, $result);
94  }
95 
96  /**
97  * Test that the single node works and returns just the content of the user info node with a nested element.
98  * This eliminates the <li> wrapper and just returns its content.
99  * @return void
100  */
102  {
103  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'dropdown-user-menu-ul-li');
104  $expected = $this->singleNestedNodeUserInfo();
105 
106  $this->assertSame($expected, $result);
107  }
108 
109  /**
110  * Test that the single node works and returns the full wrapper of the user info node with a nested element.
111  * @return void
112  */
114  {
115  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'dropdown-user-menu-ul-li', true);
116  $expected = $this->fullSingleNestedNodeUserInfo();
117 
118  $this->assertSame($expected, $result);
119  }
120 
121  /**
122  * Test that the single node works and returns just the content of the failed login node with a nested element.
123  * Note it has three other nested elements, testing covers an inner one below.
124  * @return void
125  */
127  {
128  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'failed-login');
129  $expected = $this->singleNestedNodeFailedLogin();
130 
131  $this->assertSame($expected, $result);
132  }
133 
134  /**
135  * Test that the single node works and returns the full wrapper of the failed login node with a nested element.
136  * Note it has three other nested elements, testing covers an inner one below.
137  * @return void
138  */
140  {
141  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'failed-login', true);
142  $expected = $this->singleNestedNodeWithWrapperFailedLogin();
143 
144  $this->assertSame($expected, $result);
145  }
146 
147 
148 
149  /**
150  * Test that the last-login node, which is nested inside the nested failed-login node, returns just the
151  * content without the wrapper.
152  * @return void
153  */
155  {
156  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'last-login');
157  $expected = $this->singleNestedNodeLastLogin();
158 
159  $this->assertSame($expected, $result);
160  }
161 
162  /**
163  * Test that the last-login node, which is nested inside the nested failed-login node, returns the
164  * content with the full outer wrapper.
165  * @return void
166  */
168  {
169  $result = $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'last-login', true);
170  $expected = $this->singleNestedNodeWithWrapperLastLogin();
171 
172  $this->assertSame($expected, $result);
173  }
174 
175 
176  /************************************************************************************************
177  * Helpers - do not reformat, it will break the unit tests. Sloppy looking and ugly, yes,
178  * this is how the data returns from the class on request.
179  * **********************************************************************************************/
180 
181  /**
182  * Mock the JSON returned from hcuFunctions.i->CompassMenuJson().
183  * @return string
184  */
185  protected function mockJson()
186  {
187  return ' {"logout":{"display":"Sign Out","icon":"power-off","action":"exit","script":"hcuLogout.prg"},'
188  . '"activity":{"display":"User Activity","icon":"bell","count":0,"menuid":"33","script":'
189  . '"hcuUserActivity.prg","action":"menu"},"messages":{"display":"Secure Message","icon":'
190  . '"comments","count":"0","menuid":"47","script":"hcuSecureMail.prg","action":"menu"},'
191  . '"status":{"display":"Login Status","icon":"tasks","count":0,"endpoint":"http:\/\/localhost:'
192  . '8000\/banking\/hcuAccountStatus.prg?cu=SCRUBCU","action":"popup","prior":{"title":'
193  . '"Last Successful Login","date":"Tue Nov 12, 2019 09:17am","level":"info"},"fail":'
194  . '{"title":"Last Failed Login","date":"Tue Nov 12, 2019 09:00am","level":"info"},'
195  . '"system":{"title":"Account Status as of ","date":"Fri May 23, 2008 04:32pm","level":'
196  . '"info"}},"user":{"display":"User Info","icon":"user","count":0,"action":"popup",'
197  . '"email":{"title":"Current email is","message":"mike@homecu.net","icon":"envelope",'
198  . '"level":"info","link":"Update Now","url":"http:\/\/localhost:8000\/banking\/'
199  . 'hcuProfileEmail.prg?cu=SCRUBCU","script":"hcuProfileEmail.prg","menuid":"52","action":"menu"}}}';
200 
201  }
202 
203  /**
204  * Expected response when we request the top level user activity node without the full_node param.
205  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'user-activity');
206  * @return string
207  */
208  protected function topLevelUserActivityNode()
209  {
210  return '<a id="user-activity-link" href="http://localhost:8000/banking/hcuUserActivity.prg?cu=SCRUBCU" aria-label="User Activity" title="User Activity">
211 <i class="fa fa-bell fa-fw"></i><span id="activity-link-text" class="compass-link-text">User Activity</span></a>';
212  }
213 
214  /**
215  * Expected response when we request the top level user activity node with the full_node param set to true.
216  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'user-activity', true);
217  * @return string
218  */
220  {
221  return ' <li id="user-activity" class="hcu-quick-nav-activity">
222 <a id="user-activity-link" href="http://localhost:8000/banking/hcuUserActivity.prg?cu=SCRUBCU" aria-label="User Activity" title="User Activity">
223 <i class="fa fa-bell fa-fw"></i><span id="activity-link-text" class="compass-link-text">User Activity</span></a></li>
224 ';
225  }
226 
227  /**
228  * Expected response when we request the top level secure email node without the full_node param.
229  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'secure-email-item');
230  * @return string
231  */
232  protected function topLevelSecureEmailNode()
233  {
234  return '<a id="secure-email-link" href="http://localhost:8000/banking/hcuSecureMail.prg?cu=SCRUBCU" aria-label="Secure Messages" title="Secure Messages">
235 <i class="fa fa-comments fa-fw"></i><span id="secure-email-link-text" class="compass-link-text">Secure Message</span></a>';
236  }
237 
238  /**
239  * Expected response when we request the top level secure email node with the full_node param set to true.
240  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'secure-email-item', true);
241  * @return string
242  */
244  {
245  return ' <li id="secure-email-item" class="hcu-quick-nav-secure-mail">
246 <a id="secure-email-link" href="http://localhost:8000/banking/hcuSecureMail.prg?cu=SCRUBCU" aria-label="Secure Messages" title="Secure Messages">
247 <i class="fa fa-comments fa-fw"></i><span id="secure-email-link-text" class="compass-link-text">Secure Message</span></a></li>
248 ';
249  }
250 
251  /**
252  * Expected response when we request a single nested node with the full_node param absent or false.
253  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'dropdown-user-menu-ul-li');
254  * @return string
255  */
256  protected function singleNestedNodeUserInfo()
257  {
258  return ' <div class="col-xs-12">
259  <div id="update-email" class="k-block hcu-alert-block">
260  <div id="email-alert-icon-block" class="hcu-alert-block-icon">
261 <i id="email-alert-icon" class="fa fa-2x fa-envelope"></i></div>
262 &nbsp;
263  <div id="email-message-block-text" class="hcu-alert-block-text">
264 <span id="email-message-title">Current email is</span><br>
265 <label id="email-message-label"> <p id="email-message-p">
266 mike@homecu.net</p>
267 </label></div>
268 <hr>
269 <a id="update-email-link" href="http://localhost:8000/banking/hcuProfileEmail.prg?cu=SCRUBCU">
270 Update Now</a></div>
271 </div>
272 ';
273  }
274 
275  /**
276  * Expected response when we request a single nested node with the full_node param true.
277  * $this->CompassObj->singleCompassMenuNode($this->json_path, $this->json, 'dropdown-user-menu-ul-li', true);
278  * @return string
279  */
280  protected function fullSingleNestedNodeUserInfo()
281  {
282  return ' <li id="dropdown-user-menu-ul-li">
283  <div class="col-xs-12">
284  <div id="update-email" class="k-block hcu-alert-block">
285  <div id="email-alert-icon-block" class="hcu-alert-block-icon">
286 <i id="email-alert-icon" class="fa fa-2x fa-envelope"></i></div>
287 &nbsp;
288  <div id="email-message-block-text" class="hcu-alert-block-text">
289 <span id="email-message-title">Current email is</span><br>
290 <label id="email-message-label"> <p id="email-message-p">
291 mike@homecu.net</p>
292 </label></div>
293 <hr>
294 <a id="update-email-link" href="http://localhost:8000/banking/hcuProfileEmail.prg?cu=SCRUBCU">
295 Update Now</a></div>
296 </div>
297 </li>
298 ';
299  }
300 
301  /**
302  * This is the response for failed-login without a wrapper. Note it has sub-members tested in another test.
303  * @return string
304  */
305  protected function singleNestedNodeFailedLogin()
306  {
307  return ' <div id="failed-login-col-xs" class="col-xs-12">
308  <div id="failed-login-form-group" class="form-group">
309  <div id="failed-login-k-b" class="k-block">
310  <div id="failed-login-summary-block" class="hcu-summary-block">
311  <div id="failed-login-summary-row" class="summary-row">
312  <div id="failed-login-summary-desc" class="summary-desc">
313 <label id="failed-login-summary-desc-label" class="control-label">Last Failed Login</label></div>
314  <div id="failed-login-summary-value" class="summary-value">
315  <p id="failed-login-summary-desc-p" class="form-control-static">
316 Tue Nov 12, 2019 09:00am</p>
317 </div>
318 </div>
319 </div>
320 </div>
321 </div>
322  <div id="last-login" class="form-group">
323  <div id="last-login-k-block" class="k-block">
324  <div id="last-login-summary-block" class="hcu-summary-block">
325  <div id="last-login-summary-row" class="summary-row">
326  <div id="last-login-summary-desc" class="summary-desc">
327 <label id="last-login-summary-desc-label" class="control-label">Last Successful Login</label></div>
328  <div id="last-login-summary-value" class="summary-value">
329  <p id="last-login-summary-value-label" class="form-control-static">
330 Tue Nov 12, 2019 09:17am</p>
331 </div>
332 </div>
333 </div>
334 </div>
335 </div>
336  <div id="acct-status" class="form-group">
337  <div id="acct-status-k-block" class="k-block">
338  <div id="acct-status-summary-block" class="hcu-summary-block">
339  <div id="acct-status-summary-row" class="summary-row">
340  <div id="acct-status-summary-desc" class="summary-desc">
341 <label id="acct-status-summary-desc-label" class="control-label">Account Status as of </label></div>
342  <div id="acct-status-summary-value" class="summary-value">
343  <p id="acct-status-summary-p" class="form-control-static">
344 Fri May 23, 2008 04:32pm</p>
345 </div>
346 </div>
347 </div>
348 </div>
349 </div>
350 </div>
351 ';
352  }
353 
354  /**
355  * This is the response for failed-login with the <li> wrapper. Note it has sub-members tested in another test.
356  * @return string
357  */
359  {
360  return ' <li id="failed-login">
361  <div id="failed-login-col-xs" class="col-xs-12">
362  <div id="failed-login-form-group" class="form-group">
363  <div id="failed-login-k-b" class="k-block">
364  <div id="failed-login-summary-block" class="hcu-summary-block">
365  <div id="failed-login-summary-row" class="summary-row">
366  <div id="failed-login-summary-desc" class="summary-desc">
367 <label id="failed-login-summary-desc-label" class="control-label">Last Failed Login</label></div>
368  <div id="failed-login-summary-value" class="summary-value">
369  <p id="failed-login-summary-desc-p" class="form-control-static">
370 Tue Nov 12, 2019 09:00am</p>
371 </div>
372 </div>
373 </div>
374 </div>
375 </div>
376  <div id="last-login" class="form-group">
377  <div id="last-login-k-block" class="k-block">
378  <div id="last-login-summary-block" class="hcu-summary-block">
379  <div id="last-login-summary-row" class="summary-row">
380  <div id="last-login-summary-desc" class="summary-desc">
381 <label id="last-login-summary-desc-label" class="control-label">Last Successful Login</label></div>
382  <div id="last-login-summary-value" class="summary-value">
383  <p id="last-login-summary-value-label" class="form-control-static">
384 Tue Nov 12, 2019 09:17am</p>
385 </div>
386 </div>
387 </div>
388 </div>
389 </div>
390  <div id="acct-status" class="form-group">
391  <div id="acct-status-k-block" class="k-block">
392  <div id="acct-status-summary-block" class="hcu-summary-block">
393  <div id="acct-status-summary-row" class="summary-row">
394  <div id="acct-status-summary-desc" class="summary-desc">
395 <label id="acct-status-summary-desc-label" class="control-label">Account Status as of </label></div>
396  <div id="acct-status-summary-value" class="summary-value">
397  <p id="acct-status-summary-p" class="form-control-static">
398 Fri May 23, 2008 04:32pm</p>
399 </div>
400 </div>
401 </div>
402 </div>
403 </div>
404 </div>
405 </li>
406 ';
407  }
408 
409  /**
410  * This is the response for last login without a wrapper. This is a sub-member of the previous
411  * failed-login test; this is a single sub-member of failed-login.
412  * @return string
413  */
414  protected function singleNestedNodeLastLogin()
415  {
416  return ' <div id="last-login-k-block" class="k-block">
417  <div id="last-login-summary-block" class="hcu-summary-block">
418  <div id="last-login-summary-row" class="summary-row">
419  <div id="last-login-summary-desc" class="summary-desc">
420 <label id="last-login-summary-desc-label" class="control-label">Last Successful Login</label></div>
421  <div id="last-login-summary-value" class="summary-value">
422  <p id="last-login-summary-value-label" class="form-control-static">
423 Tue Nov 12, 2019 09:17am</p>
424 </div>
425 </div>
426 </div>
427 </div>
428 ';
429  }
430 
431  /**
432  * As above, response for last login with the outer wrapper.
433  * @return string
434  */
436  {
437  return ' <div id="last-login" class="form-group">
438  <div id="last-login-k-block" class="k-block">
439  <div id="last-login-summary-block" class="hcu-summary-block">
440  <div id="last-login-summary-row" class="summary-row">
441  <div id="last-login-summary-desc" class="summary-desc">
442 <label id="last-login-summary-desc-label" class="control-label">Last Successful Login</label></div>
443  <div id="last-login-summary-value" class="summary-value">
444  <p id="last-login-summary-value-label" class="form-control-static">
445 Tue Nov 12, 2019 09:17am</p>
446 </div>
447 </div>
448 </div>
449 </div>
450 </div>
451 ';
452  }
453 }