PluginProbe
PayPlug for WooCommerce (Official) / 1.2.10
PayPlug for WooCommerce (Official) v1.2.10
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / vendor / payplug / payplug-php / tests / unit_tests / Resource / InstallmentPlanTest.php

InstallmentPlanTest.php in PayPlug for WooCommerce (Official) 1.2.10, at vendor/payplug/payplug-php/tests/unit_tests/Resource/InstallmentPlanTest.php

644 lines 27.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Payplug\Resource;
3 use Payplug;
4
5 /**
6 * @group unit
7 * @group ci
8 * @group recommended
9 */
10 class InstallmentPlanTest extends \PHPUnit_Framework_TestCase
11 {
12 private $_requestMock;
13 private $_configuration;
14
15 protected function setUp()
16 {
17 $this->_configuration = new Payplug\Payplug('abc');
18 Payplug\Payplug::setDefaultConfiguration($this->_configuration);
19
20 $this->_requestMock = $this->getMock('\Payplug\Core\IHttpRequest');
21 Payplug\Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock;
22 }
23
24 protected function setUpTwice()
25 {
26 $this->_configuration = new Payplug\Payplug('abc','1970-01-01');
27 Payplug\Payplug::setDefaultConfiguration($this->_configuration);
28
29 $this->_requestMock = $this->getMock('\Payplug\Core\IHttpRequest');
30 Payplug\Core\HttpClient::$REQUEST_HANDLER = $this->_requestMock;
31 }
32
33 public function testCreateRetroInstallmentPlanFromAttributes()
34 {
35 $installment_plan = InstallmentPlan::fromAttributes(array(
36 'id' => 'inst_123456',
37 'object' => 'installment_plan',
38 'is_live' => true,
39 'currency' => 'EUR',
40 'created_at' => 1410437760,
41 'is_active' => true,
42 'is_fully_paid' => false,
43 'schedule' => array(
44 array('date' => '2018-01-01',
45 'amount' => 10000,
46 'payment_ids' => array('pay_123', 'pay_456')),
47 array('date' => '2018-02-01',
48 'amount' => 10000,
49 'payment_ids' => array('pay_789')),
50 array('date' => '2018-03-01',
51 'amount' => 5000,
52 'payment_ids' => array())
53 ),
54 'failure' => null,
55 'customer' => array(
56 'email' => '[email protected]',
57 'first_name' => 'John',
58 'last_name' => 'Doe'
59 ),
60 'hosted_payment' => array(
61 'payment_url' => 'https://www.payplug.com/p/b9868d18546711e490c612314307c934',
62 'return_url' => 'http://yourwebsite.com/payplug_return?someid=11235',
63 'cancel_url' => 'http://yourwebsite.com/payplug_cancel?someid=81321',
64 ),
65 'notification' => array(
66 'url' => 'http://yourwebsite.com/payplug_ipn',
67 'response_code' => 200
68 ),
69 'metadata' => array(
70 'a_custom_field' => 'a custom value',
71 'another_key' => 'another value'
72 )
73 ));
74
75 $this->assertEquals('inst_123456', $installment_plan->id);
76 $this->assertEquals('installment_plan', $installment_plan->object);
77 $this->assertEquals(true, $installment_plan->is_live);
78 $this->assertEquals('EUR', $installment_plan->currency);
79 $this->assertEquals(1410437760, $installment_plan->created_at);
80 $this->assertEquals(true, $installment_plan->is_active);
81 $this->assertEquals(false, $installment_plan->is_fully_paid);
82
83 // Schedule
84 $this->assertEquals('2018-01-01', $installment_plan->schedule[0]->date);
85 $this->assertEquals(10000, $installment_plan->schedule[0]->amount);
86 $this->assertEquals(array('pay_123', 'pay_456'), $installment_plan->schedule[0]->payment_ids);
87 $this->assertEquals('2018-02-01', $installment_plan->schedule[1]->date);
88 $this->assertEquals(10000, $installment_plan->schedule[1]->amount);
89 $this->assertEquals(array('pay_789'), $installment_plan->schedule[1]->payment_ids);
90 $this->assertEquals('2018-03-01', $installment_plan->schedule[2]->date);
91 $this->assertEquals(5000, $installment_plan->schedule[2]->amount);
92 $this->assertEquals(array(), $installment_plan->schedule[2]->payment_ids);
93
94 $this->assertNull($installment_plan->failure);
95
96 // Customer
97 $this->assertEquals('[email protected]', $installment_plan->customer->email);
98 $this->assertEquals('John', $installment_plan->customer->first_name);
99 $this->assertEquals('Doe', $installment_plan->customer->last_name);
100
101 // Hosted payment
102 $this->assertEquals('https://www.payplug.com/p/b9868d18546711e490c612314307c934', $installment_plan->hosted_payment->payment_url);
103 $this->assertEquals('http://yourwebsite.com/payplug_return?someid=11235', $installment_plan->hosted_payment->return_url);
104 $this->assertEquals('http://yourwebsite.com/payplug_cancel?someid=81321', $installment_plan->hosted_payment->cancel_url);
105
106 // Notification
107 $this->assertEquals('http://yourwebsite.com/payplug_ipn', $installment_plan->notification->url);
108 $this->assertEquals(200, $installment_plan->notification->response_code);
109
110
111 $this->assertEquals('a custom value', $installment_plan->metadata['a_custom_field']);
112 $this->assertEquals('another value', $installment_plan->metadata['another_key']);
113 }
114
115 public function testCreateCompleteInstallmentPlanFromAttributes()
116 {
117 $installment_plan = InstallmentPlan::fromAttributes(array(
118 'id' => 'inst_123456',
119 'object' => 'installment_plan',
120 'is_live' => true,
121 'currency' => 'EUR',
122 'created_at' => 1410437760,
123 'is_active' => true,
124 'is_fully_paid' => false,
125 'schedule' => array(
126 array('date' => '2018-01-01',
127 'amount' => 10000,
128 'payment_ids' => array('pay_123', 'pay_456')),
129 array('date' => '2018-02-01',
130 'amount' => 10000,
131 'payment_ids' => array('pay_789')),
132 array('date' => '2018-03-01',
133 'amount' => 5000,
134 'payment_ids' => array())
135 ),
136 'failure' => null,
137 'customer' => array(
138 'email' => '[email protected]',
139 'first_name' => 'John',
140 'last_name' => 'Doe'
141 ),
142 'billing' => array(
143 "title" => "Mr",
144 "first_name" => "John",
145 "last_name" => "Doe",
146 "email" => "[email protected]",
147 "phone_number" => "0123456789",
148 "address1" => "77 rue la Boétie",
149 "address2" => null,
150 "company_name" => "PayPlug",
151 "postcode" => "75008",
152 "city" => "Paris",
153 "state" => null,
154 "country" => "FR",
155 "language" => "fr"
156 ),
157 'shipping' => array(
158 "title" => "Mr",
159 "first_name" => "John",
160 "last_name" => "Doe",
161 "email" => "[email protected]",
162 "phone_number" => "0123456789",
163 "address1" => "77 rue la Boétie",
164 "address2" => null,
165 "company_name" => "PayPlug",
166 "postcode" => "75008",
167 "city" => "Paris",
168 "state" => null,
169 "country" => "FR",
170 "language" => "fr"
171 ),
172 'hosted_payment' => array(
173 'payment_url' => 'https://www.payplug.com/p/b9868d18546711e490c612314307c934',
174 'return_url' => 'http://yourwebsite.com/payplug_return?someid=11235',
175 'cancel_url' => 'http://yourwebsite.com/payplug_cancel?someid=81321',
176 ),
177 'notification' => array(
178 'url' => 'http://yourwebsite.com/payplug_ipn',
179 'response_code' => 200
180 ),
181 'metadata' => array(
182 'a_custom_field' => 'a custom value',
183 'another_key' => 'another value'
184 )
185 ));
186
187 $this->assertEquals('inst_123456', $installment_plan->id);
188 $this->assertEquals('installment_plan', $installment_plan->object);
189 $this->assertEquals(true, $installment_plan->is_live);
190 $this->assertEquals('EUR', $installment_plan->currency);
191 $this->assertEquals(1410437760, $installment_plan->created_at);
192 $this->assertEquals(true, $installment_plan->is_active);
193 $this->assertEquals(false, $installment_plan->is_fully_paid);
194
195 // Schedule
196 $this->assertEquals('2018-01-01', $installment_plan->schedule[0]->date);
197 $this->assertEquals(10000, $installment_plan->schedule[0]->amount);
198 $this->assertEquals(array('pay_123', 'pay_456'), $installment_plan->schedule[0]->payment_ids);
199 $this->assertEquals('2018-02-01', $installment_plan->schedule[1]->date);
200 $this->assertEquals(10000, $installment_plan->schedule[1]->amount);
201 $this->assertEquals(array('pay_789'), $installment_plan->schedule[1]->payment_ids);
202 $this->assertEquals('2018-03-01', $installment_plan->schedule[2]->date);
203 $this->assertEquals(5000, $installment_plan->schedule[2]->amount);
204 $this->assertEquals(array(), $installment_plan->schedule[2]->payment_ids);
205
206 $this->assertNull($installment_plan->failure);
207
208 // Customer
209 $this->assertEquals('[email protected]', $installment_plan->customer->email);
210 $this->assertEquals('John', $installment_plan->customer->first_name);
211 $this->assertEquals('Doe', $installment_plan->customer->last_name);
212
213 // Billing / Shiping
214 $this->assertEquals('Mr', $installment_plan->shipping->title);
215 $this->assertEquals('John', $installment_plan->billing->first_name);
216 $this->assertEquals('Doe', $installment_plan->shipping->last_name);
217 $this->assertEquals('[email protected]', $installment_plan->billing->email);
218 $this->assertEquals('0123456789', $installment_plan->shipping->phone_number);
219 $this->assertEquals('77 rue la Boétie', $installment_plan->billing->address1);
220 $this->assertEquals(null, $installment_plan->shipping->address2);
221 $this->assertEquals('PayPlug', $installment_plan->billing->company_name);
222 $this->assertEquals('75008', $installment_plan->shipping->postcode);
223 $this->assertEquals('Paris', $installment_plan->billing->city);
224 $this->assertEquals(null, $installment_plan->billing->state);
225 $this->assertEquals('FR', $installment_plan->shipping->country);
226 $this->assertEquals('fr', $installment_plan->billing->language);
227
228 // Hosted payment
229 $this->assertEquals('https://www.payplug.com/p/b9868d18546711e490c612314307c934', $installment_plan->hosted_payment->payment_url);
230 $this->assertEquals('http://yourwebsite.com/payplug_return?someid=11235', $installment_plan->hosted_payment->return_url);
231 $this->assertEquals('http://yourwebsite.com/payplug_cancel?someid=81321', $installment_plan->hosted_payment->cancel_url);
232
233 // Notification
234 $this->assertEquals('http://yourwebsite.com/payplug_ipn', $installment_plan->notification->url);
235 $this->assertEquals(200, $installment_plan->notification->response_code);
236
237
238 $this->assertEquals('a custom value', $installment_plan->metadata['a_custom_field']);
239 $this->assertEquals('another value', $installment_plan->metadata['another_key']);
240 }
241
242 public function testCreateInstallmentPlanFromAttributes()
243 {
244 $installment_plan = InstallmentPlan::fromAttributes(array(
245 'id' => 'inst_123456',
246 'object' => 'installment_plan',
247 'is_live' => true,
248 'currency' => 'EUR',
249 'created_at' => 1410437760,
250 'is_active' => true,
251 'is_fully_paid' => false,
252 'schedule' => array(
253 array('date' => '2018-01-01',
254 'amount' => 10000,
255 'payment_ids' => array('pay_123', 'pay_456')),
256 array('date' => '2018-02-01',
257 'amount' => 10000,
258 'payment_ids' => array('pay_789')),
259 array('date' => '2018-03-01',
260 'amount' => 5000,
261 'payment_ids' => array())
262 ),
263 'failure' => null,
264 'billing' => array(
265 "title" => "Mr",
266 "first_name" => "John",
267 "last_name" => "Doe",
268 "email" => "[email protected]",
269 "phone_number" => "0123456789",
270 "address1" => "77 rue la Boétie",
271 "address2" => null,
272 "company_name" => "PayPlug",
273 "postcode" => "75008",
274 "city" => "Paris",
275 "state" => null,
276 "country" => "FR",
277 "language" => "fr"
278 ),
279 'shipping' => array(
280 "title" => "Mr",
281 "first_name" => "John",
282 "last_name" => "Doe",
283 "email" => "[email protected]",
284 "phone_number" => "0123456789",
285 "address1" => "77 rue la Boétie",
286 "address2" => null,
287 "company_name" => "PayPlug",
288 "postcode" => "75008",
289 "city" => "Paris",
290 "state" => null,
291 "country" => "FR",
292 "language" => "fr"
293 ),
294 'hosted_payment' => array(
295 'payment_url' => 'https://www.payplug.com/p/b9868d18546711e490c612314307c934',
296 'return_url' => 'http://yourwebsite.com/payplug_return?someid=11235',
297 'cancel_url' => 'http://yourwebsite.com/payplug_cancel?someid=81321',
298 ),
299 'notification' => array(
300 'url' => 'http://yourwebsite.com/payplug_ipn',
301 'response_code' => 200
302 ),
303 'metadata' => array(
304 'a_custom_field' => 'a custom value',
305 'another_key' => 'another value'
306 )
307 ));
308
309 $this->assertEquals('inst_123456', $installment_plan->id);
310 $this->assertEquals('installment_plan', $installment_plan->object);
311 $this->assertEquals(true, $installment_plan->is_live);
312 $this->assertEquals('EUR', $installment_plan->currency);
313 $this->assertEquals(1410437760, $installment_plan->created_at);
314 $this->assertEquals(true, $installment_plan->is_active);
315 $this->assertEquals(false, $installment_plan->is_fully_paid);
316
317 // Schedule
318 $this->assertEquals('2018-01-01', $installment_plan->schedule[0]->date);
319 $this->assertEquals(10000, $installment_plan->schedule[0]->amount);
320 $this->assertEquals(array('pay_123', 'pay_456'), $installment_plan->schedule[0]->payment_ids);
321 $this->assertEquals('2018-02-01', $installment_plan->schedule[1]->date);
322 $this->assertEquals(10000, $installment_plan->schedule[1]->amount);
323 $this->assertEquals(array('pay_789'), $installment_plan->schedule[1]->payment_ids);
324 $this->assertEquals('2018-03-01', $installment_plan->schedule[2]->date);
325 $this->assertEquals(5000, $installment_plan->schedule[2]->amount);
326 $this->assertEquals(array(), $installment_plan->schedule[2]->payment_ids);
327
328 $this->assertNull($installment_plan->failure);
329
330 // Billing / Shiping
331 $this->assertEquals('Mr', $installment_plan->shipping->title);
332 $this->assertEquals('John', $installment_plan->billing->first_name);
333 $this->assertEquals('Doe', $installment_plan->shipping->last_name);
334 $this->assertEquals('[email protected]', $installment_plan->billing->email);
335 $this->assertEquals('0123456789', $installment_plan->shipping->phone_number);
336 $this->assertEquals('77 rue la Boétie', $installment_plan->billing->address1);
337 $this->assertEquals(null, $installment_plan->shipping->address2);
338 $this->assertEquals('PayPlug', $installment_plan->billing->company_name);
339 $this->assertEquals('75008', $installment_plan->shipping->postcode);
340 $this->assertEquals('Paris', $installment_plan->billing->city);
341 $this->assertEquals(null, $installment_plan->billing->state);
342 $this->assertEquals('FR', $installment_plan->shipping->country);
343 $this->assertEquals('fr', $installment_plan->billing->language);
344
345 // Hosted payment
346 $this->assertEquals('https://www.payplug.com/p/b9868d18546711e490c612314307c934', $installment_plan->hosted_payment->payment_url);
347 $this->assertEquals('http://yourwebsite.com/payplug_return?someid=11235', $installment_plan->hosted_payment->return_url);
348 $this->assertEquals('http://yourwebsite.com/payplug_cancel?someid=81321', $installment_plan->hosted_payment->cancel_url);
349
350 // Notification
351 $this->assertEquals('http://yourwebsite.com/payplug_ipn', $installment_plan->notification->url);
352 $this->assertEquals(200, $installment_plan->notification->response_code);
353
354
355 $this->assertEquals('a custom value', $installment_plan->metadata['a_custom_field']);
356 $this->assertEquals('another value', $installment_plan->metadata['another_key']);
357 }
358
359 public function testInstallmentPlanCreate()
360 {
361 $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = null;
362
363 $this->_requestMock
364 ->expects($this->once())
365 ->method('exec')
366 ->will($this->returnValue('{"status":"ok"}'));
367
368 $this->_requestMock
369 ->expects($this->atLeastOnce())
370 ->method('setopt')
371 ->will($this->returnCallback(function($option, $value = null) {
372 switch($option) {
373 case CURLOPT_POSTFIELDS:
374 $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = json_decode($value, true);
375 return true;
376 }
377 return true;
378 }));
379 $this->_requestMock
380 ->expects($this->any())
381 ->method('getinfo')
382 ->will($this->returnCallback(function($option) {
383 switch($option) {
384 case CURLINFO_HTTP_CODE:
385 return 200;
386 }
387 return null;
388 }));
389
390 $data = array(
391 'currency' => 'EUR',
392 'schedule' => array(
393 array('date' => '2018-01-01',
394 'amount' => 10000),
395 array('date' => '2018-02-01',
396 'amount' => 10000),
397 array('date' => '2018-03-01',
398 'amount' => 5000),
399 ),
400 'customer' => array(
401 'email' => '[email protected]',
402 'first_name' => 'John',
403 'last_name' => 'Doe'
404 ),
405 'billing' => array(
406 'title' => 'Mr',
407 'first_name' => 'John',
408 'last_name' => 'Doe',
409 'email' => '[email protected]',
410 'phone_number' => '0123456789',
411 'address1' => '77 rue la Boétie',
412 'address2' => 'ul',
413 'company_name' => 'PayPlug',
414 'postcode' => '75008',
415 'city' => 'Paris',
416 'state' => 'ul',
417 'country' => 'FR',
418 'language' => 'fr'
419 ),
420 'shipping' => array(
421 'title' => 'Mr',
422 'first_name' => 'John',
423 'last_name' => 'Doe',
424 'email' => '[email protected]',
425 'phone_number' => '0123456789',
426 'address1' => '77 rue la Boétie',
427 'address2' => 'ul',
428 'company_name' => 'PayPlug',
429 'postcode' => '75008',
430 'city' => 'Paris',
431 'state' => 'ul',
432 'country' => 'FR',
433 'language' => 'fr'
434 ),
435 'hosted_payment' => array(
436 'return_url' => 'https://www.example.com/thank_you_for_your_payment.html',
437 'cancel_url' => 'https://www.example.com/so_bad_it_didnt_make_it.html'
438 ),
439 'notification_url' => 'http://www.example.org/callbackURL'
440 );
441
442 $payment = InstallmentPlan::create($data);
443
444 $this->assertEquals($data, $GLOBALS['CURLOPT_POSTFIELDS_DATA']);
445 $this->assertEquals('ok', $payment->status);
446
447 unset($GLOBALS['CURLOPT_POSTFIELDS_DATA']);
448 }
449
450 public function testInstallmentPlanAbort()
451 {
452 $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = null;
453
454 $this->_requestMock
455 ->expects($this->once())
456 ->method('exec')
457 ->will($this->returnValue('{"status":"ok"}'));
458
459 $this->_requestMock
460 ->expects($this->atLeastOnce())
461 ->method('setopt')
462 ->will($this->returnCallback(function($option, $value = null) {
463 switch($option) {
464 case CURLOPT_POSTFIELDS:
465 $GLOBALS['CURLOPT_POSTFIELDS_DATA'] = json_decode($value, true);
466 return true;
467 }
468 return true;
469 }));
470 $this->_requestMock
471 ->expects($this->any())
472 ->method('getinfo')
473 ->will($this->returnCallback(function($option) {
474 switch($option) {
475 case CURLINFO_HTTP_CODE:
476 return 200;
477 }
478 return null;
479 }));
480
481 $payment = Payplug\InstallmentPlan::abort('a_payment_id');
482
483 $this->assertEquals($GLOBALS['CURLOPT_POSTFIELDS_DATA'], array('aborted' => true));
484 $this->assertEquals('ok', $payment->status);
485
486 unset($GLOBALS['CURLOPT_POSTFIELDS_DATA']);
487 }
488
489 public function testInstallmentPlanRetrieve()
490 {
491 $GLOBALS['CURLOPT_URL_DATA'] = null;
492
493 $this->_requestMock
494 ->expects($this->once())
495 ->method('exec')
496 ->will($this->returnValue('{"status":"ok"}'));
497
498 $this->_requestMock
499 ->expects($this->any())
500 ->method('getinfo')
501 ->will($this->returnCallback(function($option) {
502 switch($option) {
503 case CURLINFO_HTTP_CODE:
504 return 200;
505 }
506 return null;
507 }));
508 $this->_requestMock
509 ->expects($this->any())
510 ->method('setopt')
511 ->will($this->returnCallback(function($option, $value = null) {
512 switch($option) {
513 case CURLOPT_URL:
514 $GLOBALS['CURLOPT_URL_DATA'] = $value;
515 return true;
516 }
517 return true;
518 }));
519
520 $installment_plan = InstallmentPlan::retrieve('a_installment_plan');
521
522 $this->assertStringEndsWith('a_installment_plan', $GLOBALS['CURLOPT_URL_DATA']);
523 $this->assertEquals('ok', $installment_plan->status);
524
525 unset($GLOBALS['CURLOPT_URL_DATA']);
526 }
527
528 public function testInstallmentPlanListPaymentsWhenPaymentIsInvalid()
529 {
530 $this->setExpectedException('\PayPlug\Exception\UndefinedAttributeException');
531 $installment_plan = InstallmentPlan::fromAttributes(array('fake' => 'payment'));
532 $installment_plan->listPayments();
533 }
534
535 public function testInstallmentPlanListPayments()
536 {
537 $GLOBALS['CURLOPT_URL_DATA'] = array();
538 $data = json_encode(
539 array('schedule' => array(
540 array('date' => '2018-01-01',
541 'amount' => 10000,
542 'payment_ids' => array('pay_123', 'pay_456')),
543 array('date' => '2018-02-01',
544 'amount' => 10000,
545 'payment_ids' => array('pay_789')),
546 array('date' => '2018-03-01',
547 'amount' => 5000,
548 'payment_ids' => array())
549 )));
550
551 $this->_requestMock
552 ->expects($this->exactly(4))
553 ->method('exec')
554 ->will($this->onConsecutiveCalls(
555 $data,
556 // Retrieve payment
557 '{"id": "pay_123"}',
558 '{"id": "pay_456"}',
559 '{"id": "pay_789"}'
560 ));
561
562
563 $this->_requestMock
564 ->expects($this->any())
565 ->method('getinfo')
566 ->will($this->returnCallback(function($option) {
567 switch($option) {
568 case CURLINFO_HTTP_CODE:
569 return 200;
570 }
571 return null;
572 }));
573 $this->_requestMock
574 ->expects($this->any())
575 ->method('setopt')
576 ->will($this->returnCallback(function($option, $value = null) {
577 switch($option) {
578 case CURLOPT_URL:
579 $GLOBALS['CURLOPT_URL_DATA'][] = $value;
580 return true;
581 }
582 return true;
583 }));
584
585 $installment_plan = InstallmentPlan::fromAttributes(array('id' => 'a_inst_id'));
586 $payments = $installment_plan->listPayments();
587 $this->assertEquals(3, count($payments));
588 $this->assertTrue($payments['pay_123']->id === 'pay_123');
589 $this->assertTrue($payments['pay_456']->id === 'pay_456');
590 $this->assertTrue($payments['pay_789']->id === 'pay_789');
591 $this->assertContains('a_inst_id', $GLOBALS['CURLOPT_URL_DATA'][0]);
592 $this->assertContains('pay_123', $GLOBALS['CURLOPT_URL_DATA'][1]);
593 $this->assertContains('pay_456', $GLOBALS['CURLOPT_URL_DATA'][2]);
594 $this->assertContains('pay_789', $GLOBALS['CURLOPT_URL_DATA'][3]);
595
596 unset($GLOBALS['CURLOPT_URL_DATA']);
597 }
598
599 public function testRetrieveConsistentInstallmentPlanWhenIdIsUndefined()
600 {
601 $this->setExpectedException('\PayPlug\Exception\UndefinedAttributeException');
602
603 $installment_plan = InstallmentPlan::fromAttributes(array('this_installment_plan' => 'has_no_id'));
604 $installment_plan->getConsistentResource();
605 }
606
607 public function testRetrieveConsistentInstallmentPlan()
608 {
609 function testRetrieveConsistentInstallmentPlan_getinfo($option) {
610 switch($option) {
611 case CURLINFO_HTTP_CODE:
612 return 200;
613 }
614 return null;
615 }
616
617 $this->_requestMock
618 ->expects($this->once())
619 ->method('exec')
620 ->will($this->returnValue('{"id": "inst_345"}'));
621
622 $this->_requestMock
623 ->expects($this->any())
624 ->method('setopt')
625 ->will($this->returnValue(true));
626 $this->_requestMock
627 ->expects($this->any())
628 ->method('getinfo')
629 ->will($this->returnCallback(function($option) {
630 switch($option) {
631 case CURLINFO_HTTP_CODE:
632 return 200;
633 }
634 return null;
635 }));
636
637 $installment_plan1 = InstallmentPlan::fromAttributes(array('id' => 'inst_123'));
638 $installment_plan2 = $installment_plan1->getConsistentResource($this->_configuration);
639
640 $this->assertEquals('inst_123', $installment_plan1->id);
641 $this->assertEquals('inst_345', $installment_plan2->id);
642 }
643 }
644