|
| 1 | +<?php |
| 2 | + |
| 3 | +class AmazonFinancialGroupListTest extends PHPUnit_Framework_TestCase { |
| 4 | + |
| 5 | + /** |
| 6 | + * @var AmazonFinancialGroupList |
| 7 | + */ |
| 8 | + protected $object; |
| 9 | + |
| 10 | + /** |
| 11 | + * Sets up the fixture, for example, opens a network connection. |
| 12 | + * This method is called before a test is executed. |
| 13 | + */ |
| 14 | + protected function setUp() { |
| 15 | + resetLog(); |
| 16 | + $this->object = new AmazonFinancialGroupList('testStore', true, null, __DIR__.'/../../test-config.php'); |
| 17 | + } |
| 18 | + |
| 19 | + public function testSetUseToken(){ |
| 20 | + $this->assertNull($this->object->setUseToken()); |
| 21 | + $this->assertNull($this->object->setUseToken(true)); |
| 22 | + $this->assertNull($this->object->setUseToken(false)); |
| 23 | + $this->assertFalse($this->object->setUseToken('wrong')); |
| 24 | + } |
| 25 | + |
| 26 | + public function testSetMaxResultsPerPage(){ |
| 27 | + $this->assertFalse($this->object->setMaxResultsPerPage(null)); //can't be nothing |
| 28 | + $this->assertFalse($this->object->setMaxResultsPerPage(-5)); //too low |
| 29 | + $this->assertFalse($this->object->setMaxResultsPerPage(150)); //too high |
| 30 | + $this->assertFalse($this->object->setMaxResultsPerPage(array(5, 7))); //not a valid value |
| 31 | + $this->assertFalse($this->object->setMaxResultsPerPage('banana')); //what are you even doing |
| 32 | + $this->assertNull($this->object->setMaxResultsPerPage(77)); |
| 33 | + $this->assertNull($this->object->setMaxResultsPerPage('75')); |
| 34 | + $o = $this->object->getOptions(); |
| 35 | + $this->assertArrayHasKey('MaxResultsPerPage', $o); |
| 36 | + $this->assertEquals('75', $o['MaxResultsPerPage']); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @return array |
| 41 | + */ |
| 42 | + public function timeProvider() { |
| 43 | + return array( |
| 44 | + array(null, null, false, false), //nothing given, so no change |
| 45 | + array(time(), time(), true, true), //timestamps |
| 46 | + array('', '', false, false), //strings, but empty |
| 47 | + array('-1 min', null, true, false), //one set |
| 48 | + array(null, '-1 min', false, false), //other set |
| 49 | + array('-1 min', '-1 min', true, true), //both set |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @dataProvider timeProvider |
| 55 | + */ |
| 56 | + public function testSetTimeLimits($a, $b, $c, $d){ |
| 57 | + $try = $this->object->setTimeLimits($a, $b); |
| 58 | + $o = $this->object->getOptions(); |
| 59 | + if ($c) { |
| 60 | + $this->assertNull($try); |
| 61 | + $this->assertArrayHasKey('FinancialEventGroupStartedAfter', $o); |
| 62 | + $this->assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i', $o['FinancialEventGroupStartedAfter']); |
| 63 | + } else { |
| 64 | + $this->assertFalse($try); |
| 65 | + $this->assertArrayNotHasKey('FinancialEventGroupStartedAfter', $o); |
| 66 | + } |
| 67 | + |
| 68 | + if ($c && $d) { |
| 69 | + $this->assertArrayHasKey('FinancialEventGroupStartedBefore', $o); |
| 70 | + $this->assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i', $o['FinancialEventGroupStartedBefore']); |
| 71 | + //setting only first date resets second one |
| 72 | + $this->assertNull($this->object->setTimeLimits($a)); |
| 73 | + $o2 = $this->object->getOptions(); |
| 74 | + $this->assertArrayNotHasKey('FinancialEventGroupStartedBefore', $o2); |
| 75 | + } else { |
| 76 | + $this->assertArrayNotHasKey('FinancialEventGroupStartedBefore', $o); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + public function testFetchGroupList() { |
| 81 | + resetLog(); |
| 82 | + $this->object->setMock(true, 'fetchFinancialGroups.xml'); //no token |
| 83 | + $this->assertFalse($this->object->fetchGroupList()); //no date yet |
| 84 | + $this->object->setTimeLimits('-1 day'); |
| 85 | + $this->assertNull($this->object->fetchGroupList()); |
| 86 | + |
| 87 | + $check = parseLog(); |
| 88 | + $this->assertEquals('Single Mock File set: fetchFinancialGroups.xml', $check[1]); |
| 89 | + $this->assertEquals('Start date must be set in order to fetch financial event groups', $check[2]); |
| 90 | + $this->assertEquals('Fetched Mock File: mock/fetchFinancialGroups.xml', $check[3]); |
| 91 | + |
| 92 | + $o = $this->object->getOptions(); |
| 93 | + $this->assertEquals('ListFinancialEventGroups', $o['Action']); |
| 94 | + |
| 95 | + $this->assertFalse($this->object->hasToken()); |
| 96 | + |
| 97 | + return $this->object; |
| 98 | + } |
| 99 | + |
| 100 | + public function testFetchGroupListToken1() { |
| 101 | + resetLog(); |
| 102 | + $this->object->setMock(true, 'fetchFinancialGroupsToken.xml'); |
| 103 | + //without using token |
| 104 | + $this->object->setTimeLimits('-1 day'); |
| 105 | + $this->assertNull($this->object->fetchGroupList()); |
| 106 | + $check = parseLog(); |
| 107 | + $this->assertEquals('Single Mock File set: fetchFinancialGroupsToken.xml', $check[1]); |
| 108 | + $this->assertEquals('Fetched Mock File: mock/fetchFinancialGroupsToken.xml', $check[2]); |
| 109 | + |
| 110 | + $this->assertTrue($this->object->hasToken()); |
| 111 | + $o = $this->object->getOptions(); |
| 112 | + $this->assertEquals('ListFinancialEventGroups', $o['Action']); |
| 113 | + $r = $this->object->getGroups(); |
| 114 | + $this->assertInternalType('array', $r); |
| 115 | + $this->assertCount(1, $r); |
| 116 | + } |
| 117 | + |
| 118 | + public function testFetchGroupListToken2() { |
| 119 | + resetLog(); |
| 120 | + $this->object->setMock(true, array('fetchFinancialGroupsToken.xml', 'fetchFinancialGroupsToken2.xml')); |
| 121 | + |
| 122 | + //with using token |
| 123 | + $this->object->setUseToken(); |
| 124 | + $this->object->setTimeLimits('-1 day'); |
| 125 | + $this->assertNull($this->object->fetchGroupList()); |
| 126 | + $check = parseLog(); |
| 127 | + $this->assertEquals('Mock files array set.', $check[1]); |
| 128 | + $this->assertEquals('Fetched Mock File: mock/fetchFinancialGroupsToken.xml', $check[2]); |
| 129 | + $this->assertEquals('Recursively fetching more Financial Event Groups', $check[3]); |
| 130 | + $this->assertEquals('Fetched Mock File: mock/fetchFinancialGroupsToken2.xml', $check[4]); |
| 131 | + $this->assertFalse($this->object->hasToken()); |
| 132 | + $o = $this->object->getOptions(); |
| 133 | + $this->assertEquals('ListFinancialEventGroupsByNextToken', $o['Action']); |
| 134 | + $this->assertArrayNotHasKey('FinancialEventGroupStartedAfter', $o); |
| 135 | + $r = $this->object->getGroups(); |
| 136 | + $this->assertInternalType('array', $r); |
| 137 | + $this->assertCount(2, $r); |
| 138 | + $this->assertNotEquals($r[0], $r[1]); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @param AmazonFinancialGroupList $o |
| 143 | + * @depends testFetchGroupList |
| 144 | + */ |
| 145 | + public function testGetGroups($o) { |
| 146 | + $list = $o->getGroups(); |
| 147 | + $this->assertInternalType('array', $list); |
| 148 | + $this->assertCount(2, $list); |
| 149 | + $this->assertArrayHasKey(0, $list); |
| 150 | + $this->assertArrayHasKey(1, $list); |
| 151 | + $this->assertArrayHasKey('FinancialEventGroupId', $list[0]); |
| 152 | + $this->assertEquals($o->getGroupId(0), $list[0]['FinancialEventGroupId']); |
| 153 | + $this->assertArrayHasKey('ProcessingStatus', $list[0]); |
| 154 | + $this->assertEquals($o->getProcessingStatus(0), $list[0]['ProcessingStatus']); |
| 155 | + $this->assertArrayHasKey('FundTransferStatus', $list[0]); |
| 156 | + $this->assertEquals($o->getTransferStatus(0), $list[0]['FundTransferStatus']); |
| 157 | + $this->assertArrayHasKey('OriginalTotal', $list[0]); |
| 158 | + $this->assertEquals($o->getOriginalTotal(0), $list[0]['OriginalTotal']); |
| 159 | + $this->assertArrayHasKey('ConvertedTotal', $list[0]); |
| 160 | + $this->assertEquals($o->getConvertedTotal(0), $list[0]['ConvertedTotal']); |
| 161 | + $this->assertArrayHasKey('FundTransferDate', $list[0]); |
| 162 | + $this->assertEquals($o->getTransferDate(0), $list[0]['FundTransferDate']); |
| 163 | + $this->assertArrayHasKey('TraceId', $list[0]); |
| 164 | + $this->assertEquals($o->getTraceId(0), $list[0]['TraceId']); |
| 165 | + $this->assertArrayHasKey('AccountTail', $list[0]); |
| 166 | + $this->assertEquals($o->getAccountTail(0), $list[0]['AccountTail']); |
| 167 | + $this->assertArrayHasKey('BeginningBalance', $list[0]); |
| 168 | + $this->assertEquals($o->getBeginningBalance(0), $list[0]['BeginningBalance']); |
| 169 | + $this->assertArrayHasKey('FinancialEventGroupStart', $list[0]); |
| 170 | + $this->assertEquals($o->getStartDate(0), $list[0]['FinancialEventGroupStart']); |
| 171 | + $this->assertArrayHasKey('FinancialEventGroupEnd', $list[0]); |
| 172 | + $this->assertEquals($o->getEndDate(0), $list[0]['FinancialEventGroupEnd']); |
| 173 | + //not fetched yet for this object |
| 174 | + $this->assertFalse($this->object->getGroups()); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * @param AmazonFinancialGroupList $o |
| 179 | + * @depends testFetchGroupList |
| 180 | + */ |
| 181 | + public function testGetGroupId($o) { |
| 182 | + $this->assertEquals('22YgYW55IGNhcm5hbCBwbGVhEXAMPLE', $o->getGroupId(0)); |
| 183 | + $this->assertEquals('22Y99995IGNhcm5hbANOTHEREXAMPLE', $o->getGroupId(1)); |
| 184 | + $this->assertEquals($o->getGroupId(0), $o->getGroupId()); |
| 185 | + //not fetched yet for this object |
| 186 | + $this->assertFalse($this->object->getGroupId()); |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * @param AmazonFinancialGroupList $o |
| 191 | + * @depends testFetchGroupList |
| 192 | + */ |
| 193 | + public function testGetProcessingStatus($o) { |
| 194 | + $this->assertEquals('Closed', $o->getProcessingStatus(0)); |
| 195 | + $this->assertEquals('Closed2', $o->getProcessingStatus(1)); |
| 196 | + $this->assertEquals($o->getProcessingStatus(0), $o->getProcessingStatus()); |
| 197 | + //not fetched yet for this object |
| 198 | + $this->assertFalse($this->object->getProcessingStatus()); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * @param AmazonFinancialGroupList $o |
| 203 | + * @depends testFetchGroupList |
| 204 | + */ |
| 205 | + public function testGetTransferStatus($o) { |
| 206 | + $this->assertEquals('Successful', $o->getTransferStatus(0)); |
| 207 | + $this->assertEquals('Successful2', $o->getTransferStatus(1)); |
| 208 | + $this->assertEquals($o->getTransferStatus(0), $o->getTransferStatus()); |
| 209 | + //not fetched yet for this object |
| 210 | + $this->assertFalse($this->object->getTransferStatus()); |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * @param AmazonFinancialGroupList $o |
| 215 | + * @depends testFetchGroupList |
| 216 | + */ |
| 217 | + public function testGetOriginalTotal($o) { |
| 218 | + $x0 = array(); |
| 219 | + $x0['Amount'] = '19.00'; |
| 220 | + $x0['CurrencyCode'] = 'USD'; |
| 221 | + $x1 = array(); |
| 222 | + $x1['Amount'] = '42.00'; |
| 223 | + $x1['CurrencyCode'] = 'USD'; |
| 224 | + $this->assertEquals($x0, $o->getOriginalTotal(0)); |
| 225 | + $this->assertEquals($x0['Amount'], $o->getOriginalTotal(0, true)); |
| 226 | + $this->assertEquals($x1, $o->getOriginalTotal(1)); |
| 227 | + $this->assertEquals($x1['Amount'], $o->getOriginalTotal(1, true)); |
| 228 | + $this->assertEquals($o->getOriginalTotal(0), $o->getOriginalTotal()); |
| 229 | + //not fetched yet for this object |
| 230 | + $this->assertFalse($this->object->getOriginalTotal()); |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * @param AmazonFinancialGroupList $o |
| 235 | + * @depends testFetchGroupList |
| 236 | + */ |
| 237 | + public function testGetConvertedTotal($o) { |
| 238 | + $x0 = array(); |
| 239 | + $x0['Amount'] = '19.50'; |
| 240 | + $x0['CurrencyCode'] = 'USD'; |
| 241 | + $x1 = array(); |
| 242 | + $x1['Amount'] = '42.50'; |
| 243 | + $x1['CurrencyCode'] = 'USD'; |
| 244 | + $this->assertEquals($x0, $o->getConvertedTotal(0)); |
| 245 | + $this->assertEquals($x0['Amount'], $o->getConvertedTotal(0, true)); |
| 246 | + $this->assertEquals($x1, $o->getConvertedTotal(1)); |
| 247 | + $this->assertEquals($x1['Amount'], $o->getConvertedTotal(1, true)); |
| 248 | + $this->assertEquals($o->getConvertedTotal(0), $o->getConvertedTotal()); |
| 249 | + //not fetched yet for this object |
| 250 | + $this->assertFalse($this->object->getConvertedTotal()); |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * @param AmazonFinancialGroupList $o |
| 255 | + * @depends testFetchGroupList |
| 256 | + */ |
| 257 | + public function testGetTransferDate($o) { |
| 258 | + $this->assertEquals('2014-09-09T01:30:00.000-06:00', $o->getTransferDate(0)); |
| 259 | + $this->assertEquals('2014-10-09T01:30:00.000-06:00', $o->getTransferDate(1)); |
| 260 | + $this->assertEquals($o->getTransferDate(0), $o->getTransferDate()); |
| 261 | + //not fetched yet for this object |
| 262 | + $this->assertFalse($this->object->getTransferDate()); |
| 263 | + } |
| 264 | + |
| 265 | + /** |
| 266 | + * @param AmazonFinancialGroupList $o |
| 267 | + * @depends testFetchGroupList |
| 268 | + */ |
| 269 | + public function testGetTraceId($o) { |
| 270 | + $this->assertEquals('128311029381HSADJEXAMPLE', $o->getTraceId(0)); |
| 271 | + $this->assertEquals('128999929381HADJEXAMPLE2', $o->getTraceId(1)); |
| 272 | + $this->assertEquals($o->getTraceId(0), $o->getTraceId()); |
| 273 | + //not fetched yet for this object |
| 274 | + $this->assertFalse($this->object->getTraceId()); |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * @param AmazonFinancialGroupList $o |
| 279 | + * @depends testFetchGroupList |
| 280 | + */ |
| 281 | + public function testGetAccountTail($o) { |
| 282 | + $this->assertEquals('1212', $o->getAccountTail(0)); |
| 283 | + $this->assertEquals('1313', $o->getAccountTail(1)); |
| 284 | + $this->assertEquals($o->getAccountTail(0), $o->getAccountTail()); |
| 285 | + //not fetched yet for this object |
| 286 | + $this->assertFalse($this->object->getAccountTail()); |
| 287 | + } |
| 288 | + |
| 289 | + /** |
| 290 | + * @param AmazonFinancialGroupList $o |
| 291 | + * @depends testFetchGroupList |
| 292 | + */ |
| 293 | + public function testGetBeginningBalance($o) { |
| 294 | + $x0 = array(); |
| 295 | + $x0['Amount'] = '0.00'; |
| 296 | + $x0['CurrencyCode'] = 'USD'; |
| 297 | + $x1 = array(); |
| 298 | + $x1['Amount'] = '20.00'; |
| 299 | + $x1['CurrencyCode'] = 'USD'; |
| 300 | + $this->assertEquals($x0, $o->getBeginningBalance(0)); |
| 301 | + $this->assertEquals($x0['Amount'], $o->getBeginningBalance(0, true)); |
| 302 | + $this->assertEquals($x1, $o->getBeginningBalance(1)); |
| 303 | + $this->assertEquals($x1['Amount'], $o->getBeginningBalance(1, true)); |
| 304 | + $this->assertEquals($o->getBeginningBalance(0), $o->getBeginningBalance()); |
| 305 | + //not fetched yet for this object |
| 306 | + $this->assertFalse($this->object->getBeginningBalance()); |
| 307 | + } |
| 308 | + |
| 309 | + /** |
| 310 | + * @param AmazonFinancialGroupList $o |
| 311 | + * @depends testFetchGroupList |
| 312 | + */ |
| 313 | + public function testGetStartDate($o) { |
| 314 | + $this->assertEquals('2014-09-01T01:30:00.000-06:00', $o->getStartDate(0)); |
| 315 | + $this->assertEquals('2014-10-01T01:30:00.000-06:00', $o->getStartDate(1)); |
| 316 | + $this->assertEquals($o->getStartDate(0), $o->getStartDate()); |
| 317 | + //not fetched yet for this object |
| 318 | + $this->assertFalse($this->object->getStartDate()); |
| 319 | + } |
| 320 | + |
| 321 | + /** |
| 322 | + * @param AmazonFinancialGroupList $o |
| 323 | + * @depends testFetchGroupList |
| 324 | + */ |
| 325 | + public function testGetEndDate($o) { |
| 326 | + $this->assertEquals('2014-09-09T01:30:00.000-06:00', $o->getEndDate(0)); |
| 327 | + $this->assertEquals('2014-10-09T01:30:00.000-06:00', $o->getEndDate(1)); |
| 328 | + $this->assertEquals($o->getEndDate(0), $o->getEndDate()); |
| 329 | + //not fetched yet for this object |
| 330 | + $this->assertFalse($this->object->getEndDate()); |
| 331 | + } |
| 332 | + |
| 333 | +} |
| 334 | + |
| 335 | +require_once('helperFunctions.php'); |
0 commit comments