Odyssey
admBankingSettingsTest.php
1 <?php
2 
3 use PHPUnit\Framework\TestCase;
4 
5 class AdminSettingsTest extends TestCase {
6  protected static $env;
7 
8  function setup() {
9  $admLibrary = "/var/www/html/admcom/library";
10  require_once "$admLibrary/aAdminSettings.i";
11 
12  $sharedLibrary = "/var/www/html/shared/library";
13  require_once "$sharedLibrary/hcuEnv.i";
14  require_once "$sharedLibrary/hcuCommon.i";
15 
16  self::$env = LoadSystemEnv("banking");
17  }
18 
19  function test_ValidateACHSettings() {
20  // validate null settings
21  try {
22  $validate = ValidateACHSettings(self::$env, null);
23  } catch (Exception $e) {
24  $this->assertEquals($e->getMessage(), "Settings not found");
25  }
26 
27  // validate non-array
28  try {
29  $validate = ValidateACHSettings(self::$env, "string");
30  } catch (Exception $e) {
31  $this->assertEquals($e->getMessage(), "Settings data is invalid");
32  }
33 
34  // validate non-array, json
35  $validateJSON = HCU_JsonEncode("string");
36  try {
37  $validate = ValidateACHSettings(self::$env, $validateJSON, true);
38  } catch (Exception $e) {
39  $this->assertEquals($e->getMessage(), "Settings data is invalid");
40  }
41 
42  // validate name field empty
43  try {
44  $settings = array();
45  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
46  } catch (Exception $e) {
47  $this->assertEquals($e->getMessage(), "Credit union name is missing");
48  }
49 
50  // validate account field empty
51  try {
52  $settings = array(
53  "name" => "Scrubs Are Alive");
54  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
55  } catch (Exception $e) {
56  $this->assertEquals($e->getMessage(), "ACH GL Account is missing");
57  }
58 
59  // validate offset field empty
60  try {
61  $settings = array(
62  "name" => "Scrubs Are Alive",
63  "account" => "1029384756");
64  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
65  } catch (Exception $e) {
66  $this->assertEquals($e->getMessage(), "Micro deposit offsetting entry choice missing");
67  }
68 
69  // validate routing field empty
70  try {
71  $settings = array(
72  "name" => "Scrubs Are Alive",
73  "account" => "1029384756",
74  "offsetting" => 1);
75  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
76  } catch (Exception $e) {
77  $this->assertEquals($e->getMessage(), "Routing number is missing");
78  }
79 
80  // validate cutoff time field empty
81  try {
82  $settings = array(
83  "name" => "Scrubs Are Alive",
84  "account" => "1029384756",
85  "offsetting" => 1,
86  "routing" => "102938475");
87  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
88  } catch (Exception $e) {
89  $this->assertEquals($e->getMessage(), "Cutoff time is missing");
90  }
91 
92  // validate company id type field empty
93  try {
94  $settings = array(
95  "name" => "Scrubs Are Alive",
96  "account" => "1029384756",
97  "offsetting" => 1,
98  "routing" => "102938475",
99  "cutoff" => "345");
100  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
101  } catch (Exception $e) {
102  $this->assertEquals($e->getMessage(), "Company ID Type is missing");
103  }
104 
105  // validate company id type field incorrect
106  try {
107  $settings = array(
108  "name" => "Scrubs Are Alive",
109  "account" => "1029384756",
110  "offsetting" => 1,
111  "routing" => "102938475",
112  "cutoff" => "345",
113  "type" => 5);
114  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
115  } catch (Exception $e) {
116  $this->assertEquals($e->getMessage(), "Company ID Type is an incorrect value.");
117  }
118 
119  // validate true fields
120  $settings = array(
121  "name" => "Scrubs Are Alive",
122  "account" => "1029384756",
123  "offsetting" => 1,
124  "routing" => "102938475",
125  "cutoff" => "345",
126  "type" => 9);
127  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
128  $this->assertArrayHasKey("validate", $settingsVALIDATE);
129  $this->assertArrayHasKey("settings", $settingsVALIDATE['validate']);
130 
131  $settingsARRAY = HCU_JsonDecode($settingsVALIDATE['validate']['settings']);
132  $this->assertArrayHasKey("name", $settingsARRAY);
133  $this->assertEquals($settings['name'], $settingsARRAY['name']);
134 
135  $this->assertArrayHasKey("account", $settingsARRAY);
136  $this->assertEquals($settings['account'], $settingsARRAY['account']);
137 
138  $this->assertArrayHasKey("offsetting", $settingsARRAY);
139  $this->assertEquals($settings['offsetting'], $settingsARRAY['offsetting']);
140 
141  $this->assertArrayHasKey("cutoff", $settingsARRAY);
142  $this->assertEquals(4, strlen($settingsARRAY['cutoff']));
143  $this->assertEquals("0345", $settingsARRAY['cutoff']);
144 
145  $this->assertArrayHasKey("routing", $settingsVALIDATE['validate']);
146  $this->assertEquals(9, strlen($settingsVALIDATE['validate']['routing']));
147  $this->assertEquals($settings['routing'], $settingsVALIDATE['validate']['routing']);
148 
149  $this->assertArrayHasKey("type", $settingsARRAY);
150  $this->assertEquals($settings['type'], $settingsARRAY['type']);
151 
152  $this->assertArrayNotHasKey("achnotify", $settingsARRAY);
153 
154  // validate wth notify set
155  $settings = array(
156  "name" => "Scrubs Are Alive",
157  "account" => "1029384756",
158  "offsetting" => 1,
159  "routing" => "102938475",
160  "cutoff" => "345",
161  "type" => 9,
162  "notify" => "<html>this has html tags</html>",
163  );
164  $settingsVALIDATE = ValidateACHSettings(self::$env, $settings);
165  $this->assertArrayHasKey("validate", $settingsVALIDATE);
166  $this->assertArrayHasKey("settings", $settingsVALIDATE['validate']);
167  $settingsARRAY = HCU_JsonDecode($settingsVALIDATE['validate']['settings']);
168  $this->assertArrayHasKey("achnotify", $settingsARRAY);
169  $this->assertEquals($settings['notify'], $settingsARRAY['achnotify']);
170  }
171 
172  function test_ValidateAutoSettings() {
173  // validate null settings
174  try {
175  $validate = ValidateAutoSettings(self::$env, null);
176  } catch (Exception $e) {
177  $this->assertEquals($e->getMessage(), "Settings not found");
178  }
179 
180  // validate non-array
181  try {
182  $validate = ValidateAutoSettings(self::$env, "string");
183  } catch (Exception $e) {
184  $this->assertEquals($e->getMessage(), "Settings data is invalid");
185  }
186 
187  // validate non-array, json
188  $validateJSON = HCU_JsonEncode("string");
189  try {
190  $validate = ValidateAutoSettings(self::$env, $validateJSON, true);
191  } catch (Exception $e) {
192  $this->assertEquals($e->getMessage(), "Settings data is invalid");
193  }
194 
195  // validate profile field empty
196  try {
197  $settings = array();
198  $settingsVALIDATE = ValidateAutoSettings(self::$env, $settings);
199  } catch (Exception $e) {
200  $this->assertEquals($e->getMessage(), "Default profile is missing");
201  }
202 
203  // validate profile empty string
204  $settings = array("profile" => "DEFAULT");
205  $settingsVALIDATE = ValidateAutoSettings(self::$env, $settings);
206  $this->assertArrayHasKey("validate", $settingsVALIDATE);
207  $this->assertArrayHasKey("settings", $settingsVALIDATE['validate']);
208 
209  $settingsARRAY = HCU_JsonDecode($settingsVALIDATE['validate']['settings']);
210  $this->assertArrayHasKey("profile", $settingsARRAY);
211  $this->assertEquals($settings['profile'], $settingsARRAY['profile']);
212  }
213 }