27896fef5f4e8f2c7a1f5b41aafc5de33e188101
[WP-Plugins/glm-member-db.git] /
1 <?php
2 namespace PayPal\Test\Api;
3
4 use PayPal\Api\Address;
5 use PayPal\Api\CreditCard;
6 use PayPal\Test\Constants;
7 class CreditCardTest extends \PHPUnit_Framework_TestCase {
8         
9         private $cards;
10         
11         public static $id = "id";
12         public static $validUntil = "2013-02-28T00:00:00Z";
13         public static $state = "created";
14         public static $payerId = "payer-id";
15         public static $cardType = "visa";
16         public static $cardNumber = "4417119669820331";
17         public static $expireMonth = 11;
18         public static $expireYear = "2019";
19         public static $cvv = "012";
20         public static $firstName = "V";
21         public static $lastName = "C";
22         
23         public static function createCreditCard() {
24                 $card = new CreditCard();
25                 $card->setType(self::$cardType);
26                 $card->setNumber(self::$cardNumber);
27                 $card->setExpireMonth(self::$expireMonth);
28                 $card->setExpireYear(self::$expireYear);
29                 $card->setCvv2(self::$cvv);
30                 $card->setFirstName(self::$firstName);
31                 $card->setLastName(self::$lastName);
32                 $card->setId(self::$id);
33                 $card->setValidUntil(self::$validUntil);
34                 $card->setState(self::$state);
35                 $card->setPayerId(self::$payerId);
36                 return $card;
37         }
38         
39         public function setup() {
40                 
41                 $card = self::createCreditCard();
42                 $card->setBillingAddress(AddressTest::createAddress()); 
43                 $card->setLinks(array(LinksTest::createLinks()));
44                 $this->cards['full'] = $card;
45                 
46                 $card = self::createCreditCard();       
47                 $this->cards['partial'] = $card;
48         }
49         
50         public function testGetterSetters() {
51                 $c = $this->cards['partial'];
52                 $this->assertEquals(self::$cardType, $c->getType());
53                 $this->assertEquals(self::$cardNumber, $c->getNumber());
54                 $this->assertEquals(self::$expireMonth, $c->getExpireMonth());
55                 $this->assertEquals(self::$expireYear, $c->getExpireYear());
56                 $this->assertEquals(self::$cvv, $c->getCvv2());
57                 $this->assertEquals(self::$firstName, $c->getFirstName());
58                 $this->assertEquals(self::$lastName, $c->getLastName());
59                 $this->assertEquals(self::$id, $c->getId());
60                 $this->assertEquals(self::$validUntil, $c->getValidUntil());
61                 $this->assertEquals(self::$state, $c->getState());
62                 $this->assertEquals(self::$payerId, $c->getPayerId());
63                 
64                 $c = $this->cards['full'];
65                 $this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
66                 $link = $c->getLinks();
67                 $this->assertEquals(LinksTest::$href, $link[0]->getHref());
68         }
69         
70         public function testSerializeDeserialize() {
71                 $c1 = $this->cards['full'];
72                 $json = $c1->toJson();
73                 
74                 $c2 = new CreditCard();
75                 $c2->fromJson($json);           
76                 
77                 $this->assertEquals($c1, $c2);
78         }
79         
80         public function testOperations() {
81                 $c1 = $this->cards['full'];
82                 
83 //              $this->assertNull($c1->getId());
84                 $c1->create();          
85                 $this->assertNotNull($c1->getId());
86                 
87                 $c2 = CreditCard::get($c1->getId());
88                 $this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress());
89                 $this->assertGreaterThan(0, count($c2->getLinks()));
90                 $this->assertEquals(self::$cardType, $c2->getType());
91                 $this->assertNotNull($c2->getState());
92                 $this->assertEquals(true, $c2->delete());
93         }
94 }