Initial commit

This commit is contained in:
aydiv
2013-03-06 18:42:06 +05:30
commit 69cb3c4dcb
101 changed files with 6222 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Address;
use PayPal\Test\Constants;
class AddressTest extends \PHPUnit_Framework_TestCase {
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $type = "Billing";
public static function createAddress() {
$addr = new Address();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostal_code(self::$postalCode);
$addr->setCountry_code(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setType(self::$type);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostal_code());
$this->assertEquals(self::$countryCode, $this->address->getCountry_code());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$type, $this->address->getType());
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new Address();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\AmountDetails;
use PayPal\Test\Constants;
class AmountDetailsTest extends \PHPUnit_Framework_TestCase {
private $amountDetails;
public static $subtotal = "2.00";
public static $tax = "1.12";
public static $shipping = "3.15";
public static $fee = "4.99";
public static function createAmountDetails() {
$amountDetails = new AmountDetails();
$amountDetails->setSubtotal(self::$subtotal);
$amountDetails->setTax(self::$tax);
$amountDetails->setShipping(self::$shipping);
$amountDetails->setFee(self::$fee);
return $amountDetails;
}
public function setup() {
$this->amountDetails = self::createAmountDetails();
}
public function testGetterSetters() {
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amountDetails;
$a2 = new AmountDetails();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Test\Constants;
class AmountTest extends \PHPUnit_Framework_TestCase {
private $amounts;
public static $currency = "USD";
public static $total = "1.12";
public static function createAmount() {
$amount = new Amount();
$amount->setCurrency(self::$currency);
$amount->setTotal(self::$total);
return $amount;
}
public function setup() {
$this->amounts['partial'] = self::createAmount();
$amount = self::createAmount();
$amount->setDetails(AmountDetailsTest::createAmountDetails());
$this->amounts['full'] = $amount;
}
public function testGetterSetter() {
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
$this->assertEquals(AmountDetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amounts['partial'];
$a2 = new Amount();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
use PayPal\Api\Link;
use PayPal\Test\Constants;
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
private $authorizations = array();
public static $create_time = "2013-02-28T00:00:00Z";
public static $id = "AUTH-123";
public static $state = "Created";
public static $parent_payment = "PAY-12345";
public static $currency = "USD";
public static $total = "1.12";
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createAuthorization() {
$authorization = new Authorization();
$authorization->setCreate_time(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setAmount(AmountTest::createAmount());
$authorization->setLinks(array(LinkTest::createLink()));
return $authorization;
}
public function setup() {
$authorization = new Authorization();
$authorization->setCreate_time(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setParent_payment(self::$parent_payment);
$this->authorizations['partial'] = $authorization;
$this->authorizations['full'] = self::createAuthorization();
}
public function testGetterSetter() {
$authorization = $this->authorizations['partial'];
$this->assertEquals(self::$create_time, $authorization->getCreate_time());
$this->assertEquals(self::$id, $authorization->getId());
$this->assertEquals(self::$state, $authorization->getState());
$this->assertEquals(self::$parent_payment, $authorization->getParent_payment());
$authorization = $this->authorizations['full'];
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
$this->assertEquals(1, count($authorization->getLinks()));
}
public function testSerializeDeserialize() {
$a1 = $this->authorizations['partial'];
$a2 = new Authorization();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Capture;
use PayPal\Test\Constants;
class CaptureTest extends \PHPUnit_Framework_TestCase {
private $captures;
public static $authorization_id = "AUTH-123";
public static $create_time = "2013-02-28T00:00:00Z";
public static $description = "Test capture";
public static $id = "C-5678";
public static $parent_payment = "PAY-123";
public static $state = "Created";
public static function createCapture() {
$capture = new Capture();
$capture->setAuthorization_id(self::$authorization_id);
$capture->setCreate_time(self::$create_time);
$capture->setDescription(self::$description);
$capture->setId(self::$id);
$capture->setParent_payment(self::$parent_payment);
$capture->setState(self::$state);
return $capture;
}
public function setup() {
$this->captures['partial'] = self::createCapture();
$capture = self::createCapture();
$capture->setAmount(AmountTest::createAmount());
$capture->setLinks(array(LinkTest::createLink()));
$this->captures['full'] = $capture;
}
public function testGetterSetter() {
$this->assertEquals(self::$authorization_id, $this->captures['partial']->getAuthorization_id());
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreate_time());
$this->assertEquals(self::$description, $this->captures['partial']->getDescription());
$this->assertEquals(self::$id, $this->captures['partial']->getId());
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParent_payment());
$this->assertEquals(self::$state, $this->captures['partial']->getState());
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
$links = $this->captures['full']->getLinks();
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$c1 = $this->captures['partial'];
$c2 = new Capture();
$c2->fromJson($c1->toJson());
$this->assertEquals($c1, $c2);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Test\Constants;
class CreditCardTest extends \PHPUnit_Framework_TestCase {
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard() {
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpire_month(self::$expireMonth);
$card->setExpire_year(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirst_name(self::$firstName);
$card->setLast_name(self::$lastName);
$card->setId(self::$id);
$card->setValid_until(self::$validUntil);
$card->setState(self::$state);
$card->setPayer_id(self::$payerId);
return $card;
}
public function setup() {
$card = self::createCreditCard();
$card->setBilling_address(AddressTest::createAddress());
$card->setLinks(array(LinkTest::createLink()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters() {
$c = $this->cards['partial'];
$this->assertEquals(self::$cardType, $c->getType());
$this->assertEquals(self::$cardNumber, $c->getNumber());
$this->assertEquals(self::$expireMonth, $c->getExpire_month());
$this->assertEquals(self::$expireYear, $c->getExpire_year());
$this->assertEquals(self::$cvv, $c->getCvv2());
$this->assertEquals(self::$firstName, $c->getFirst_name());
$this->assertEquals(self::$lastName, $c->getLast_name());
$this->assertEquals(self::$id, $c->getId());
$this->assertEquals(self::$validUntil, $c->getValid_until());
$this->assertEquals(self::$state, $c->getState());
$this->assertEquals(self::$payerId, $c->getPayer_id());
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBilling_address()->getLine1());
$link = $c->getLinks();
$this->assertEquals(LinkTest::$href, $link[0]->getHref());
}
public function testSerializeDeserialize() {
$c1 = $this->cards['full'];
$json = $c1->toJson();
$c2 = new CreditCard();
$c2->fromJson($json);
$this->assertEquals($c1, $c2);
}
public function testOperations() {
$c1 = $this->cards['full'];
// $this->assertNull($c1->getId());
$c1->create();
$this->assertNotNull($c1->getId());
$c2 = CreditCard::get($c1->getId());
$this->assertEquals($c1->getBilling_address(), $c2->getBilling_address());
$this->assertGreaterThan(0, count($c2->getLinks()));
$this->assertEquals(self::$cardType, $c2->getType());
$this->assertNotNull($c2->getState());
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\CreditCardToken;
use PayPal\Test\Constants;
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase {
private $ccToken;
public static $payerId = "PAYER-123";
public static $creditCardId = "CC-123";
public static function createCreditCardToken() {
$ccToken = new CreditCardToken();
$ccToken->setPayer_id(self::$payerId);
$ccToken->setCredit_card_id(self::$creditCardId);
return $ccToken;
}
public function setup() {
$this->ccToken = self::createCreditCardToken();
}
public function testGetterSetter() {
$this->assertEquals(self::$payerId, $this->ccToken->getPayer_id());
$this->assertEquals(self::$creditCardId, $this->ccToken->getCredit_card_id());
}
public function testSerializeDeserialize() {
$t1 = $this->ccToken;
$t2 = new CreditCardToken();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\FundingInstrument;
use PayPal\Test\Constants;
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase {
private $fi;
public static function createFundingInstrument() {
$fi = new FundingInstrument();
$fi->setCredit_card(CreditCardTest::createCreditCard());
$fi->setCredit_card_token(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public function setup() {
$this->fi = self::createFundingInstrument();
}
public function testGetterSetter() {
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCredit_card()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCredit_card_token()->getCredit_card_id());
}
public function testSerializeDeserialize() {
$fi1 = $this->fi;
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Test\Constants;
class ItemListTest extends \PHPUnit_Framework_TestCase {
private $items = array();
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList() {
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShipping_address(ShippingAddressTest::createAddress());
return $itemList;
}
public function setup() {
$this->items = self::createItemList();
}
public function testGetterSetters() {
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShipping_address());
}
public function testSerializeDeserialize() {
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Test\Constants;
class ItemTest extends \PHPUnit_Framework_TestCase {
private $item;
public static $name = "item name";
public static $price = "1.12";
public static $quantity = "10";
public static $sku = "AXVTY123";
public static $currency = "USD";
public static function createItem() {
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
public function setup() {
$this->item = ItemTest::createItem();
}
public function testGetterSetters() {
$this->assertEquals(self::$name, $this->item->getName());
$this->assertEquals(self::$price, $this->item->getPrice());
$this->assertEquals(self::$sku, $this->item->getSku());
$this->assertEquals(self::$quantity, $this->item->getQuantity());
$this->assertEquals(self::$currency, $this->item->getCurrency());
}
public function testSerializeDeserialize() {
$item = new Item();
$item->fromJson($this->item->toJSON());
$this->assertEquals($item, $this->item);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Link;
use PayPal\Test\Constants;
class LinkTest extends \PHPUnit_Framework_TestCase {
private $link;
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createLink() {
$link = new Link();
$link->setHref(self::$href);
$link->setRel(self::$rel);
$link->setMethod(self::$method);
return $link;
}
public function setup() {
$this->link = self::createLink();
}
public function testGetterSetters() {
$this->assertEquals(self::$href, $this->link->getHref());
$this->assertEquals(self::$rel, $this->link->getRel());
$this->assertEquals(self::$method, $this->link->getMethod());
}
public function testSerializeDeserialize() {
$link2 = new Link();
$link2->fromJson($this->link->toJSON());
$this->assertEquals($this->link, $link2);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Payee;
use PayPal\Test\Constants;
class PayeeTest extends \PHPUnit_Framework_TestCase {
private $payee;
public static $email = "test@paypal.com";
public static $merchant_id = "1XY12121";
public static $phone = "+14081234566";
public static function createPayee() {
$payee = new Payee();
$payee->setEmail(self::$email);
$payee->setMerchant_id(self::$merchant_id);
$payee->setPhone(self::$phone);
return $payee;
}
public function setup() {
$this->payee = self::createPayee();
}
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payee->getEmail());
$this->assertEquals(self::$merchant_id, $this->payee->getMerchant_id());
$this->assertEquals(self::$phone, $this->payee->getPhone());
}
public function testSerializeDeserialize() {
$p1 = $this->payee;
$p2 = new Payee();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\PayerInfo;
use PayPal\Test\Constants;
class PayerInfoTest extends \PHPUnit_Framework_TestCase {
private $payerInfo;
public static $email = "test@paypal.com";
public static $firstName = "first";
public static $lastName = "last";
public static $phone = "408-1234-5687";
public static $payerId = "PAYER-1234";
public static function createPayerInfo() {
$payerInfo = new PayerInfo();
$payerInfo->setEmail(self::$email);
$payerInfo->setFirst_name(self::$firstName);
$payerInfo->setLast_name(self::$lastName);
$payerInfo->setPhone(self::$phone);
$payerInfo->setPayer_id(self::$payerId);
$payerInfo->setShipping_address(AddressTest::createAddress());
return $payerInfo;
}
public function setup() {
$this->payerInfo = self::createPayerInfo();
}
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
$this->assertEquals(self::$firstName, $this->payerInfo->getFirst_name());
$this->assertEquals(self::$lastName, $this->payerInfo->getLast_name());
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
$this->assertEquals(self::$payerId, $this->payerInfo->getPayer_id());
$this->assertEquals(AddressTest::$line1, $this->payerInfo->getShipping_address()->getLine1());
}
public function testSerializeDeserialize() {
$p1 = $this->payerInfo;
$p2 = new PayerInfo();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Test\Constants;
class PayerTest extends \PHPUnit_Framework_TestCase {
private $payer;
private static $paymentMethod = "credit_card";
public static function createPayer() {
$payer = new Payer();
$payer->setPayment_method(self::$paymentMethod);
$payer->setPayer_info(PayerInfoTest::createPayerInfo());
$payer->setFunding_instruments(array(FundingInstrumentTest::createFundingInstrument()));
return $payer;
}
public function setup() {
$this->payer = self::createPayer();
}
public function testGetterSetter() {
$this->assertEquals(self::$paymentMethod, $this->payer->getPayment_method());
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayer_info()->getEmail());
$fi = $this->payer->getFunding_instruments();
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCredit_card_token()->getCredit_card_id());
}
public function testSerializeDeserialize() {
$p1 = $this->payer;
$p2 = new Payer();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\PaymentHistory;
use PayPal\Test\Constants;
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase {
private $history;
public static $count = "10";
public static $nextId = "11";
public static function createPaymentHistory() {
$history = new PaymentHistory();
$history->setCount(self::$count);
$history->setNext_id(self::$nextId);
$history->setPayments(array(PaymentTest::createPayment()));
return $history;
}
public function setup() {
$this->history = PaymentHistoryTest::createPaymentHistory();
}
public function testGetterSetters() {
$this->assertEquals(self::$count, $this->history->getCount());
$this->assertEquals(self::$nextId, $this->history->getNext_id());
}
public function testSerializeDeserialize() {
$history = new PaymentHistory();
$history->fromJson($this->history->toJSON());
$this->assertEquals($history, $this->history);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class PaymentTest extends \PHPUnit_Framework_TestCase {
private $payments;
public static function createPayment() {
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturn_url("http://localhost/return");
$redirectUrls->setCancel_url("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirect_urls($redirectUrls);
$payment->setPayer(PayerTest::createPayer());
$payment->setTransactions(array(TransactionTest::createTransaction()));
return $payment;
}
public static function createNewPayment() {
$payer = new Payer();
$payer->setPayment_method("credit_card");
$payer->setFunding_instruments(array(FundingInstrumentTest::createFundingInstrument()));
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturn_url("http://localhost/return");
$redirectUrls->setCancel_url("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirect_urls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
}
public function setup() {
$this->payments['full'] = self::createPayment();
$this->payments['new'] = self::createNewPayment();
}
public function testSerializeDeserialize() {
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
public function testOperations() {
$p1 = $this->payments['new'];
$p1->create();
$this->assertNotNull($p1->getId());
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Refund;
use PayPal\Test\Constants;
class RefundTest extends \PHPUnit_Framework_TestCase {
private $refund;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $description = "Test refund";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static function createRefund() {
$refund = new Refund();
$refund->setAmount(AmountTest::createAmount());
$refund->setCapture_id(self::$captureId);
$refund->setCreate_time(self::$createTime);
$refund->setDescription(self::$description);
$refund->setId(self::$id);
$refund->setLinks(array(LinkTest::createLink()));
$refund->setParent_payment(self::$parentPayment);
return $refund;
}
public function setup() {
$this->refund = self::createRefund();
}
public function testGetterSetter() {
$this->assertEquals(self::$captureId, $this->refund->getCapture_id());
$this->assertEquals(self::$createTime, $this->refund->getCreate_time());
$this->assertEquals(self::$description, $this->refund->getDescription());
$this->assertEquals(self::$id, $this->refund->getId());
$this->assertEquals(self::$parentPayment, $this->refund->getParent_payment());
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
$links = $this->refund->getLinks();
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$r1 = $this->refund;
$r2 = new Refund();
$r2->fromJson($r1->toJson());
$this->assertEquals($r1, $r2);
}
public function testOperations() {
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Refund;
use PayPal\Api\Sale;
use PayPal\Test\Constants;
use PayPal\Test\Api\AmountTest;
use PayPal\Test\Api\PaymentTest;
use PayPal\Test\Api\LinkTest;
class SaleTest extends \PHPUnit_Framework_TestCase {
private $sale;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $description = "Test refund";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $state = "Created";
public static function createSale() {
$sale = new Sale();
$sale->setAmount(AmountTest::createAmount());
$sale->setCreate_time(self::$createTime);
$sale->setId(self::$id);
$sale->setLinks(array(LinkTest::createLink()));
$sale->setParent_payment(self::$parentPayment);
$sale->setState(self::$state);
return $sale;
}
public function setup() {
$this->sale = self::createSale();
}
public function testGetterSetter() {
$this->assertEquals(self::$createTime, $this->sale->getCreate_time());
$this->assertEquals(self::$id, $this->sale->getId());
$this->assertEquals(self::$parentPayment, $this->sale->getParent_payment());
$this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
$links = $this->sale->getLinks();
$this->assertEquals(LinkTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$s1 = $this->sale;
$s2 = new Sale();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
public function testOperations() {
$payment = PaymentTest::createNewPayment();
$payment->create();
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelated_resources();
$saleId = $resources[0]->getSale()->getId();
$sale = Sale::get($saleId);
$this->assertNotNull($sale);
$refund = new Refund();
$refund->setAmount(AmountTest::createAmount());
$sale->refund($refund);
$this->setExpectedException('\InvalidArgumentException');
$sale->refund(NULL);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\ShippingAddress;
use PayPal\Test\Constants;
class ShippingAddressTest extends \PHPUnit_Framework_TestCase {
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $recipientName = "TestUser";
public static $type = "Billing";
public static function createAddress() {
$addr = new ShippingAddress();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostal_code(self::$postalCode);
$addr->setCountry_code(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setRecipient_name(self::$recipientName);
$addr->setType(self::$type);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostal_code());
$this->assertEquals(self::$countryCode, $this->address->getCountry_code());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$recipientName, $this->address->getRecipient_name());
$this->assertEquals(self::$type, $this->address->getType());
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new ShippingAddress();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\SubTransaction;
use PayPal\Test\Constants;
class SubTransactionTest extends \PHPUnit_Framework_TestCase {
private $subTransaction;
public static function createSubTransaction() {
$subTransaction = new SubTransaction();
$subTransaction->setAuthorization(AuthorizationTest::createAuthorization());
$subTransaction->setCapture(CaptureTest::createCapture());
return $subTransaction;
}
public function setup() {
$this->subTransaction = self::createSubTransaction();
}
public function testGetterSetter() {
$this->assertEquals(AuthorizationTest::$create_time, $this->subTransaction->getAuthorization()->getCreate_Time());
$this->assertEquals(CaptureTest::$create_time, $this->subTransaction->getCapture()->getCreate_Time());
}
public function testSerializeDeserialize() {
$s1 = $this->subTransaction;
$s2 = new SubTransaction();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\SubTransaction;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class TransactionTest extends \PHPUnit_Framework_TestCase {
private $transaction;
public static $description = "desc . . . ";
public static $total = "1.12";
public static function createTransaction() {
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setItem_list(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelated_resources( array(SubTransactionTest::createSubTransaction()) );
return $transaction;
}
public function setup() {
$this->transaction = self::createTransaction();
}
public function testGetterSetter() {
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
$this->assertEquals(self::$description, $this->transaction->getDescription());
$items = $this->transaction->getItem_list()->getItems();
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
$resources = $this->transaction->getRelated_resources();
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreate_Time());
}
public function testSerializeDeserialize() {
$t1 = $this->transaction;
$t2 = new Transaction();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}

View File

@@ -0,0 +1,33 @@
<?php
// namespace PayPal\Test\Common;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Test\Constants;
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
public function testGetAccessToken() {
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$token = $cred->getAccessToken();
$this->assertNotNull($token);
// Check that we get the same token when issuing a new call before token expiry
$newToken = $cred->getAccessToken();
$this->assertNotNull($newToken);
$this->assertEquals($token, $newToken);
// sleep(60*8);
// $newToken = $cred->getAccessToken();
// $this->assertNotNull($newToken);
// $this->assertNotEqual($token, $newToken);
}
public function testInvalidCredentials() {
$this->setExpectedException('\PPConnectionException');
$cred = new OAuthTokenCredential('dummy', 'secret');
$this->assertNull($cred->getAccessToken());
}
}

View File

@@ -0,0 +1,22 @@
<?php
// namespace PayPal\Test\Common;
use PayPal\Common\ArrayUtil;
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
public function testIsAssocArray() {
$arr = array(1, 2, 3);
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
$arr = array(
'name' => 'John Doe',
'City' => 'San Jose'
);
$this->assertEquals(true, ArrayUtil::isAssocArray($arr));
$arr[] = 'CA';
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
}
}

View File

@@ -0,0 +1,135 @@
<?php
// namespace PayPal\Test\Common;
use PayPal\Common\Model;
class SimpleClass extends Model {
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setDescription($desc) {
$this->desc = $desc;
}
public function getDescription() {
return $this->desc;
}
}
class ArrayClass extends Model {
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setDescription($desc) {
$this->desc = $desc;
}
public function getDescription() {
return $this->desc;
}
public function setTags($tags) {
if(!is_array($tags)) {
$tags = array($tags);
}
$this->tags = $tags;
}
public function getTags() {
return $this->tags;
}
}
class NestedClass extends Model {
public function setId($id) {
$this->id = $id;
}
public function getId() {
return $this->id;
}
/**
*
* @param ArrayClass $info
*/
public function setInfo($info) {
$this->info = $info;
}
public function getInfo() {
return $this->info;
}
}
class ChildClass extends SimpleClass {
}
class ModelTest extends PHPUnit_Framework_TestCase {
public function testSimpleClassConversion() {
$o = new SimpleClass();
$o->setName("test");
$o->setDescription("description");
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","desc":"description"}', $json);
$newO = new SimpleClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testArrayClassConversion() {
$o = new ArrayClass();
$o->setName("test");
$o->setDescription("description");
$o->setTags(array('payment', 'info', 'test'));
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
$newO = new ArrayClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testNestedClassConversion() {
$n = new ArrayClass();
$n->setName("test");
$n->setDescription("description");
// $n->setTags(array('payment', 'info', 'test'));
$o = new NestedClass();
$o->setId('123');
$o->setInfo($n);
$this->assertEquals("123", $o->getId());
$this->assertEquals("test", $o->getInfo()->getName());
// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
$json = $o->toJSON();
// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
$this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
$newO = new NestedClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
}

View File

@@ -0,0 +1,23 @@
<?php
use PayPal\Common\UserAgent;
class UserAgentTest extends PHPUnit_Framework_TestCase {
public function testGetValue() {
$ua = UserAgent::getValue();
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
// Check that we pass the useragent in the expected format
$this->assertNotNull($id);
$this->assertNotNull($version);
$this->assertNotNull($features);
// Check that we pass in these mininal features
$this->assertThat($features, $this->stringContains("OS="));
$this->assertThat($features, $this->stringContains("Bit="));
$this->assertThat($features, $this->stringContains("Lang="));
$this->assertThat($features, $this->stringContains("V="));
$this->assertGreaterThan(5, count(explode(';', $features)));
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace PayPal\Test;
class Constants {
const CLIENT_ID = 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM';
const CLIENT_SECRET = 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM';
}

View File

@@ -0,0 +1,41 @@
<?php
// namespace PayPal\Test\Rest;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\Call;
use PayPal\Test\Constants;
class CallTest {
public function testExecuteWithExplicitCredentials() {
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$data = '"request":"test message"';
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
$this->assertEquals($data, $ret);
}
public function testExecuteWithInvalidCredentials() {
$cred = new OAuthTokenCredential('test', 'dummy');
$data = '"request":"test message"';
$call = new Call();
$this->setExpectedException('\PPConnectionException');
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
}
public function testExecuteWithDefaultCredentials() {
$data = '"request":"test message"';
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data);
$this->assertEquals($data, $ret);
}
}