Updated Identity Support from SDK Core

- Moved PPModels required for Identity Support
This commit is contained in:
japatel
2014-10-14 14:15:41 -05:00
parent 0cb302326a
commit dc2ac0fd63
36 changed files with 2652 additions and 587 deletions

View File

@@ -0,0 +1,78 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\CreateProfileResponse;
/**
* Class CreateProfileResponse
*
* @package PayPal\Test\Api
*/
class CreateProfileResponseTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object CreateProfileResponse
* @return string
*/
public static function getJson()
{
return json_encode(json_decode('{"id":"TestSample"}'));
}
/**
* Gets Object Instance with Json data filled in
* @return CreateProfileResponse
*/
public static function getObject()
{
return new CreateProfileResponse(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return CreateProfileResponse
*/
public function testSerializationDeserialization()
{
$obj = new CreateProfileResponse(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getId());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param CreateProfileResponse $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getId(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param CreateProfileResponse $obj
*/
public function testDeprecatedGetters($obj)
{
}
/**
* @depends testSerializationDeserialization
* @param CreateProfileResponse $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\FlowConfig;
/**
* Class FlowConfig
*
* @package PayPal\Test\Api
*/
class FlowConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object FlowConfig
* @return string
*/
public static function getJson()
{
return json_encode(json_decode('{"landing_page_type":"TestSample","bank_txn_pending_url":"http://www.google.com"}'));
}
/**
* Gets Object Instance with Json data filled in
* @return FlowConfig
*/
public static function getObject()
{
return new FlowConfig(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return FlowConfig
*/
public function testSerializationDeserialization()
{
$obj = new FlowConfig(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getLandingPageType());
$this->assertNotNull($obj->getBankTxnPendingUrl());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param FlowConfig $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getLandingPageType(), "TestSample");
$this->assertEquals($obj->getBankTxnPendingUrl(), "http://www.google.com");
}
/**
* @depends testSerializationDeserialization
* @param FlowConfig $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getLanding_page_type(), "TestSample");
$this->assertEquals($obj->getBank_txn_pending_url(), "http://www.google.com");
}
/**
* @depends testSerializationDeserialization
* @param FlowConfig $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Landing_page_type
$obj->setLandingPageType(null);
$this->assertNull($obj->getLanding_page_type());
$this->assertNull($obj->getLandingPageType());
$this->assertSame($obj->getLandingPageType(), $obj->getLanding_page_type());
$obj->setLanding_page_type("TestSample");
$this->assertEquals($obj->getLanding_page_type(), "TestSample");
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage BankTxnPendingUrl is not a fully qualified URL
*/
public function testUrlValidationForBankTxnPendingUrl()
{
$obj = new FlowConfig();
$obj->setBankTxnPendingUrl(null);
}
public function testUrlValidationForBankTxnPendingUrlDeprecated()
{
$obj = new FlowConfig();
$obj->setBank_txn_pending_url(null);
$this->assertNull($obj->getBank_txn_pending_url());
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\InputFields;
/**
* Class InputFields
*
* @package PayPal\Test\Api
*/
class InputFieldsTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object InputFields
* @return string
*/
public static function getJson()
{
return json_encode(json_decode('{"allow_note":true,"no_shipping":123,"address_override":123}'));
}
/**
* Gets Object Instance with Json data filled in
* @return InputFields
*/
public static function getObject()
{
return new InputFields(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return InputFields
*/
public function testSerializationDeserialization()
{
$obj = new InputFields(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getAllowNote());
$this->assertNotNull($obj->getNoShipping());
$this->assertNotNull($obj->getAddressOverride());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param InputFields $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getAllowNote(), true);
$this->assertEquals($obj->getNoShipping(), 123);
$this->assertEquals($obj->getAddressOverride(), 123);
}
/**
* @depends testSerializationDeserialization
* @param InputFields $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getAllow_note(), true);
$this->assertEquals($obj->getNo_shipping(), 123);
$this->assertEquals($obj->getAddress_override(), 123);
}
/**
* @depends testSerializationDeserialization
* @param InputFields $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Allow_note
$obj->setAllowNote(null);
$this->assertNull($obj->getAllow_note());
$this->assertNull($obj->getAllowNote());
$this->assertSame($obj->getAllowNote(), $obj->getAllow_note());
$obj->setAllow_note(true);
$this->assertEquals($obj->getAllow_note(), true);
// Check for No_shipping
$obj->setNoShipping(null);
$this->assertNull($obj->getNo_shipping());
$this->assertNull($obj->getNoShipping());
$this->assertSame($obj->getNoShipping(), $obj->getNo_shipping());
$obj->setNo_shipping(123);
$this->assertEquals($obj->getNo_shipping(), 123);
// Check for Address_override
$obj->setAddressOverride(null);
$this->assertNull($obj->getAddress_override());
$this->assertNull($obj->getAddressOverride());
$this->assertSame($obj->getAddressOverride(), $obj->getAddress_override());
$obj->setAddress_override(123);
$this->assertEquals($obj->getAddress_override(), 123);
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\Patch;
/**
* Class Patch
*
* @package PayPal\Test\Api
*/
class PatchTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object Patch
* @return string
*/
public static function getJson()
{
return json_encode(json_decode('{"op":"TestSample","path":"TestSample","value":"TestSampleObject","from":"TestSample"}'));
}
/**
* Gets Object Instance with Json data filled in
* @return Patch
*/
public static function getObject()
{
return new Patch(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return Patch
*/
public function testSerializationDeserialization()
{
$obj = new Patch(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getOp());
$this->assertNotNull($obj->getPath());
$this->assertNotNull($obj->getValue());
$this->assertNotNull($obj->getFrom());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param Patch $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getOp(), "TestSample");
$this->assertEquals($obj->getPath(), "TestSample");
$this->assertEquals($obj->getValue(), "TestSampleObject");
$this->assertEquals($obj->getFrom(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param Patch $obj
*/
public function testDeprecatedGetters($obj)
{
}
/**
* @depends testSerializationDeserialization
* @param Patch $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Common\PPModel;
use PayPal\Api\Presentation;
/**
* Class Presentation
*
* @package PayPal\Test\Api
*/
class PresentationTest extends \PHPUnit_Framework_TestCase
{
/**
* Gets Json String of Object Presentation
* @return string
*/
public static function getJson()
{
return json_encode(json_decode('{"brand_name":"TestSample","logo_image":"TestSample","locale_code":"TestSample"}'));
}
/**
* Gets Object Instance with Json data filled in
* @return Presentation
*/
public static function getObject()
{
return new Presentation(self::getJson());
}
/**
* Tests for Serialization and Deserialization Issues
* @return Presentation
*/
public function testSerializationDeserialization()
{
$obj = new Presentation(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getBrandName());
$this->assertNotNull($obj->getLogoImage());
$this->assertNotNull($obj->getLocaleCode());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param Presentation $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getBrandName(), "TestSample");
$this->assertEquals($obj->getLogoImage(), "TestSample");
$this->assertEquals($obj->getLocaleCode(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param Presentation $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getBrand_name(), "TestSample");
$this->assertEquals($obj->getLogo_image(), "TestSample");
$this->assertEquals($obj->getLocale_code(), "TestSample");
}
/**
* @depends testSerializationDeserialization
* @param Presentation $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Brand_name
$obj->setBrandName(null);
$this->assertNull($obj->getBrand_name());
$this->assertNull($obj->getBrandName());
$this->assertSame($obj->getBrandName(), $obj->getBrand_name());
$obj->setBrand_name("TestSample");
$this->assertEquals($obj->getBrand_name(), "TestSample");
// Check for Logo_image
$obj->setLogoImage(null);
$this->assertNull($obj->getLogo_image());
$this->assertNull($obj->getLogoImage());
$this->assertSame($obj->getLogoImage(), $obj->getLogo_image());
$obj->setLogo_image("TestSample");
$this->assertEquals($obj->getLogo_image(), "TestSample");
// Check for Locale_code
$obj->setLocaleCode(null);
$this->assertNull($obj->getLocale_code());
$this->assertNull($obj->getLocaleCode());
$this->assertSame($obj->getLocaleCode(), $obj->getLocale_code());
$obj->setLocale_code("TestSample");
$this->assertEquals($obj->getLocale_code(), "TestSample");
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
}

View File

@@ -2,6 +2,11 @@
namespace PayPal\Test\Api;
use PayPal\Common\ResourceModel;
use PayPal\Validation\ArgumentValidator;
use PayPal\Api\CreateProfileResponse;
use PayPal\Rest\ApiContext;
use PayPal\Transport\PPRestCall;
use PayPal\Api\WebProfile;
/**
@@ -11,73 +16,219 @@ use PayPal\Api\WebProfile;
*/
class WebProfileTest extends \PHPUnit_Framework_TestCase
{
public function testCreateprofileSerialization()
/**
* Gets Json String of Object WebProfile
* @return string
*/
public static function getJson()
{
$requestBody = '{"name":"someName2' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":1,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"http://www.ebay.com"}}';
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
$object = new WebProfile($requestBodyEncoded);
return json_encode(json_decode('{"id":"TestSample","name":"TestSample","flow_config":' .FlowConfigTest::getJson() . ',"input_fields":' .InputFieldsTest::getJson() . ',"presentation":' .PresentationTest::getJson() . '}'));
}
$json = $object->toJson();
$this->assertEquals($requestBodyEncoded, $json);
/**
* Gets Object Instance with Json data filled in
* @return WebProfile
*/
public static function getObject()
{
return new WebProfile(self::getJson());
}
/**
* @group integration
* Tests for Serialization and Deserialization Issues
* @return WebProfile
*/
public function testCreateprofileOperation()
public function testSerializationDeserialization()
{
$requestBody = '{"name":"someName2' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":1,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"http://www.ebay.com"}}';
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
$object = new WebProfile($requestBodyEncoded);
$response = $object->create(null);
$this->assertNotNull($response);
return $response->getId();
$obj = new WebProfile(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getId());
$this->assertNotNull($obj->getName());
$this->assertNotNull($obj->getFlowConfig());
$this->assertNotNull($obj->getInputFields());
$this->assertNotNull($obj->getPresentation());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
/**
* @depends testSerializationDeserialization
* @param WebProfile $obj
*/
public function testGetters($obj)
{
$this->assertEquals($obj->getId(), "TestSample");
$this->assertEquals($obj->getName(), "TestSample");
$this->assertEquals($obj->getFlowConfig(), FlowConfigTest::getObject());
$this->assertEquals($obj->getInputFields(), InputFieldsTest::getObject());
$this->assertEquals($obj->getPresentation(), PresentationTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebProfile $obj
*/
public function testDeprecatedGetters($obj)
{
$this->assertEquals($obj->getFlow_config(), FlowConfigTest::getObject());
$this->assertEquals($obj->getInput_fields(), InputFieldsTest::getObject());
}
/**
* @depends testSerializationDeserialization
* @param WebProfile $obj
*/
public function testDeprecatedSetterNormalGetter($obj)
{
// Check for Flow_config
$obj->setFlowConfig(null);
$this->assertNull($obj->getFlow_config());
$this->assertNull($obj->getFlowConfig());
$this->assertSame($obj->getFlowConfig(), $obj->getFlow_config());
$obj->setFlow_config(FlowConfigTest::getObject());
$this->assertEquals($obj->getFlow_config(), FlowConfigTest::getObject());
// Check for Input_fields
$obj->setInputFields(null);
$this->assertNull($obj->getInput_fields());
$this->assertNull($obj->getInputFields());
$this->assertSame($obj->getInputFields(), $obj->getInput_fields());
$obj->setInput_fields(InputFieldsTest::getObject());
$this->assertEquals($obj->getInput_fields(), InputFieldsTest::getObject());
//Test All Deprecated Getters and Normal Getters
$this->testDeprecatedGetters($obj);
$this->testGetters($obj);
}
/**
* @depends testCreateprofileOperation
* @group integration
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testGetprofileOperation($profileId)
public function testCreate($obj, $mockApiContext)
{
$response = WebProfile::get($profileId, null);
$this->assertNotNull($response);
$this->assertEquals($response->getId(), $profileId);
$this->assertEquals("http://www.ebay.com", $response->getPresentation()->getLogoImage());
$this->assertEquals(1, $response->getInputFields()->getNoShipping());
$this->assertEquals(1, $response->getInputFields()->getAddressOverride());
$this->assertEquals("billing", $response->getFlowConfig()->getLandingPageType());
$this->assertEquals("http://www.ebay.com", $response->getFlowConfig()->getBankTxnPendingUrl());
return $response->getId();
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
CreateProfileResponseTest::getJson()
));
$result = $obj->create($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function testValidationerrorSerialization()
{
$requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}';
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
$object = new WebProfile($requestBodyEncoded);
$json = $object->toJson();
$this->assertEquals($requestBodyEncoded, $json);
}
/**
* @group integration
* @expectedException PayPal\Exception\PPConnectionException
* @expectedExceptionCode 400
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testValidationerrorOperation()
public function testUpdate($obj, $mockApiContext)
{
$requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}';
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
$object = new WebProfile($requestBodyEncoded);
$response = $object->create(null);
return $response->getId();
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$result = $obj->update($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testPartialUpdate($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$patch = array(PatchTest::getObject());
$result = $obj->partial_update($patch, $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testGet($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
WebProfileTest::getJson()
));
$result = $obj->get("profileId", $mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testGetList($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
json_encode(array(json_decode(WebProfileTest::getJson())))
));
$result = $obj->get_list($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
/**
* @dataProvider mockProvider
* @param WebProfile $obj
*/
public function testDelete($obj, $mockApiContext)
{
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
true
));
$result = $obj->delete($mockApiContext, $mockPPRestCall);
$this->assertNotNull($result);
}
public function mockProvider()
{
$obj = self::getObject();
$mockApiContext = $this->getMockBuilder('ApiContext')
->disableOriginalConstructor()
->getMock();
return array(
array($obj, $mockApiContext),
array($obj, null)
);
}
}

View File

@@ -0,0 +1,50 @@
<?php
use PayPal\Auth\Openid\PPOpenIdAddress;
/**
* Test class for PPOpenIdAddress.
*
*/
class PPOpenIdAddressTest extends \PHPUnit_Framework_TestCase
{
/** @var PPOpenIdAddress */
private $addr;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->addr = self::getTestData();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
public static function getTestData()
{
$addr = new PPOpenIdAddress();
$addr->setCountry("US")->setLocality("San Jose")
->setPostalCode("95112")->setRegion("CA")
->setStreetAddress("1, North 1'st street");
return $addr;
}
/**
* @test
*/
public function testSerializationDeserialization()
{
$addrCopy = new PPOpenIdAddress();
$addrCopy->fromJson($this->addr->toJson());
$this->assertEquals($this->addr, $addrCopy);
}
}

View File

@@ -0,0 +1,45 @@
<?php
use PayPal\Auth\Openid\PPOpenIdError;
/**
* Test class for PPOpenIdError.
*
*/
class PPOpenIdErrorTest extends PHPUnit_Framework_TestCase
{
/** @var PPOpenIdError */
private $error;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->error = new PPOpenIdError();
$this->error->setErrorDescription('error description')
->setErrorUri('http://developer.paypal.com/api/error')
->setError('VALIDATION_ERROR');
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testSerializationDeserialization()
{
$errorCopy = new PPOpenIdError();
$errorCopy->fromJson($this->error->toJson());
$this->assertEquals($this->error, $errorCopy);
}
}

View File

@@ -0,0 +1,93 @@
<?php
use PayPal\Common\PPApiContext;
use PayPal\Auth\Openid\PPOpenIdSession;
/**
* Test class for PPOpenIdSession.
*
*/
class PPOpenIdSessionTest extends \PHPUnit_Framework_TestCase
{
private $context;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->context = new \PayPal\Rest\ApiContext();
$this->context->setConfig(
array(
'acct1.ClientId' => 'DummyId',
'acct1.ClientSecret' => 'A8VERY8SECRET8VALUE0',
'mode' => 'live'
)
);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testLoginUrlForMultipleScopes()
{
$clientId = "AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd";
$redirectUri = 'https://devtools-paypal.com/';
$scope = array('this', 'that', 'and more');
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - custom scope");
$scope = array();
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=openid+profile+address+email+phone+" . urlencode("https://uri.paypal.com/services/paypalattributes") . "+" . urlencode('https://uri.paypal.com/services/expresscheckout') . "&redirect_uri=" . urlencode($redirectUri),
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - default scope");
$scope = array('openid');
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=openid&redirect_uri=" . urlencode($redirectUri),
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - openid scope");
}
/**
* @test
*/
public function testLoginWithCustomConfig()
{
$redirectUri = 'http://mywebsite.com';
$scope = array('this', 'that', 'and more');
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
$this->assertEquals($expectedBaseUrl . "?client_id=DummyId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, "DummyId", null, null, $this->context), "Failed case - custom config");
}
/**
* @test
*/
public function testLogoutWithCustomConfig()
{
$redirectUri = 'http://mywebsite.com';
$idToken = 'abc';
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession";
$this->assertEquals($expectedBaseUrl . "?id_token=$idToken&redirect_uri=" . urlencode($redirectUri) . "&logout=true",
PPOpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config");
}
}

View File

@@ -0,0 +1,76 @@
<?php
use PayPal\Auth\Openid\PPOpenIdTokeninfo;
/**
* Test class for PPOpenIdTokeninfo.
*
*/
class PPOpenIdTokeninfoTest extends \PHPUnit_Framework_TestCase
{
/** @var PPOpenIdTokeninfo */
public $token;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->token = new PPOpenIdTokeninfo();
$this->token->setAccessToken("Access token")
->setExpiresIn(900)
->setRefreshToken("Refresh token")
->setIdToken("id token")
->setScope("openid address")
->setTokenType("Bearer");
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testSerializationDeserialization()
{
$tokenCopy = new PPOpenIdTokeninfo();
$tokenCopy->fromJson($this->token->toJson());
$this->assertEquals($this->token, $tokenCopy);
}
/**
* @t1est
* TODO: Fix Test. This test is disabled
*/
public function t1estOperations()
{
$clientId = 'AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd';
$clientSecret = 'ELtVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX';
$params = array(
'code' => '<FILLME>',
'redirect_uri' => 'https://devtools-paypal.com/',
'client_id' => $clientId,
'client_secret' => $clientSecret
);
$accessToken = PPOpenIdTokeninfo::createFromAuthorizationCode($params);
$this->assertNotNull($accessToken);
$params = array(
'refresh_token' => $accessToken->getRefreshToken(),
'client_id' => $clientId,
'client_secret' => $clientSecret
);
$accessToken = $accessToken->createFromRefreshToken($params);
$this->assertNotNull($accessToken);
}
}

View File

@@ -0,0 +1,60 @@
<?php
use PayPal\Auth\Openid\PPOpenIdUserinfo;
/**
* Test class for PPOpenIdUserinfo.
*
*/
class PPOpenIdUserinfoTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testSerializationDeserialization()
{
$user = new PPOpenIdUserinfo();
$user->setAccountType("PERSONAL")->setAgeRange("20-30")->setBirthday("1970-01-01")
->setEmail("me@email.com")->setEmailVerified(true)
->setFamilyName("Doe")->setMiddleName("A")->setGivenName("John")
->setLocale("en-US")->setGender("male")->setName("John A Doe")
->setPayerId("A-XZASASA")->setPhoneNumber("1-408-111-1111")
->setPicture("http://gravatar.com/me.jpg")
->setSub("me@email.com")->setUserId("userId")
->setVerified(true)->setVerifiedAccount(true)
->setZoneinfo("America/PST")->setLanguage('en_US')
->setAddress(PPOpenIdAddressTest::getTestData());
$userCopy = new PPOpenIdUserinfo();
$userCopy->fromJson($user->toJSON());
$this->assertEquals($user, $userCopy);
}
/**
* @test
*/
public function testInvalidParamUserInfoCall()
{
$this->setExpectedException('PayPal\Exception\PPConnectionException');
PPOpenIdUserinfo::getUserinfo(array('access_token' => 'accessToken'));
}
}

View File

@@ -80,7 +80,7 @@ class ModelTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("test", $obj->getName());
$this->assertEquals("description", $obj->getDescription());
} catch (\PHPUnit_Framework_Error_Notice $ex) {
echo $ex->getMessage();
// No need to do anything
}
}

View File

@@ -1,45 +0,0 @@
<?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);
}
}