PluginProbe
PayPlug for WooCommerce (Official) / 1.0.20
PayPlug for WooCommerce (Official) v1.0.20
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 / CardTest.php

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

112 lines 3.6 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 CardTest 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 public function testCreateCardFromAttributes()
25 {
26 $card = Card::fromAttributes(array(
27 'id' => 'card_167oJVCpvtR9j8N85LraL2GA',
28 'object' => 'card',
29 'created_at' => 1431523049,
30 'is_live' => false,
31 'last4' => '1111',
32 'brand' => 'Visa',
33 'exp_month' => 5,
34 'exp_year' => 2029,
35 'customer_id' => 'cus_6ESfofiMiLBjC6',
36 'country' => 'France',
37 'metadata' => array(
38 'a_custom_field' => 'a custom value',
39 'another_key' => 'another value'
40 )
41 ));
42
43 $this->assertEquals('card_167oJVCpvtR9j8N85LraL2GA', $card->id);
44 $this->assertEquals('card', $card->object);
45 $this->assertEquals(1431523049, $card->created_at);
46 $this->assertEquals(false, $card->is_live);
47 $this->assertEquals('1111', $card->last4);
48 $this->assertEquals('Visa', $card->brand);
49 $this->assertEquals(5, $card->exp_month);
50 $this->assertEquals(2029, $card->exp_year);
51 $this->assertEquals('cus_6ESfofiMiLBjC6', $card->customer_id);
52 $this->assertEquals('France', $card->country);
53
54 $this->assertEquals('a custom value', $card->metadata['a_custom_field']);
55 $this->assertEquals('another value', $card->metadata['another_key']);
56 }
57
58 public function testCardDeleteCardObject()
59 {
60 function testCardDeleteCardObject_getinfo($option) {
61 switch($option) {
62 case CURLINFO_HTTP_CODE:
63 return 200;
64 }
65 return null;
66 }
67 $GLOBALS['CURLOPT_URL_DATA'] = null;
68 function testCardDeleteCardObject_setopt($option, $value = null) {
69 switch($option) {
70 case CURLOPT_URL:
71 $GLOBALS['CURLOPT_URL_DATA'] = $value;
72 return true;
73 }
74 return true;
75 }
76
77 $this->_requestMock
78 ->expects($this->once())
79 ->method('exec')
80 ->will($this->returnValue('{"status":"ok"}'));
81
82 $this->_requestMock
83 ->expects($this->any())
84 ->method('getinfo')
85 ->will($this->returnCallback(function($option) {
86 switch($option) {
87 case CURLINFO_HTTP_CODE:
88 return 200;
89 }
90 return null;
91 }));
92 $this->_requestMock
93 ->expects($this->any())
94 ->method('setopt')
95 ->will($this->returnCallback(function($option, $value = null) {
96 switch($option) {
97 case CURLOPT_URL:
98 $GLOBALS['CURLOPT_URL_DATA'] = $value;
99 return true;
100 }
101 return true;
102 }));
103
104 $card = Card::fromAttributes(array('id' => 'a_card_id'));
105 $card->delete();
106
107 $this->assertStringEndsWith('a_card_id', $GLOBALS['CURLOPT_URL_DATA']);
108
109 unset($GLOBALS['CURLOPT_URL_DATA']);
110 }
111 }
112