This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/tests/PayPal/Test/Core/PPHttpConfigTest.php
japatel 49b80f76af Removing Dependency from SDK Core Project
- Copied files required for Rest API SDK
- Removed PPApiContext and directly connected APIContext with PPConfigManager
- Removed duplicate data storage of configuration and credentials.
- Code Style Fixes
- Remove build.xml file as it is not required anymore
- Updated the samples
- Updated the documentations
2014-10-06 11:16:47 -05:00

122 lines
2.9 KiB
PHP

<?php
use PayPal\Core\PPHttpConfig;
/**
* Test class for PPAPIService.
*
*/
class PPHttpConfigTest extends PHPUnit_Framework_TestCase
{
protected $object;
private $config = array(
'http.ConnectionTimeOut' => '30',
'http.Retry' => '5' ,
);
/**
* 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 testHeaderFunctions()
{
$o = new PPHttpConfig();
$o->addHeader('key1', 'value1');
$o->addHeader('key2', 'value');
$o->addHeader('key2', 'overwritten');
$this->assertEquals(2, count($o->getHeaders()));
$this->assertEquals('overwritten', $o->getHeader('key2'));
$this->assertNull($o->getHeader('key3'));
$o = new PPHttpConfig();
$o->addHeader('key1', 'value1');
$o->addHeader('key2', 'value');
$o->addHeader('key2', 'and more', false);
$this->assertEquals(2, count($o->getHeaders()));
$this->assertEquals('value;and more', $o->getHeader('key2'));
$o->removeHeader('key2');
$this->assertEquals(1, count($o->getHeaders()));
$this->assertNull($o->getHeader('key2'));
}
/**
* @test
*/
public function testCurlOpts()
{
$o = new PPHttpConfig();
$o->setCurlOptions(array('k' => 'v'));
$curlOpts = $o->getCurlOptions();
$this->assertEquals(1, count($curlOpts));
$this->assertEquals('v', $curlOpts['k']);
}
/**
* @test
*/
public function testUserAgent()
{
$ua = 'UAString';
$o = new PPHttpConfig();
$o->setUserAgent($ua);
$curlOpts= $o->getCurlOptions();
$this->assertEquals($ua, $curlOpts[CURLOPT_USERAGENT]);
}
/**
* @test
*/
public function testSSLOpts()
{
$sslCert = '../cacert.pem';
$sslPass = 'passPhrase';
$o = new PPHttpConfig();
$o->setSSLCert($sslCert, $sslPass);
$curlOpts= $o->getCurlOptions();
$this->assertArrayHasKey(CURLOPT_SSLCERT, $curlOpts);
$this->assertEquals($sslPass, $curlOpts[CURLOPT_SSLCERTPASSWD]);
}
/**
* @test
*/
public function testProxyOpts()
{
$proxy = 'http://me:secret@hostname:8081';
$o = new PPHttpConfig();
$o->setHttpProxy($proxy);
$curlOpts= $o->getCurlOptions();
$this->assertEquals('hostname:8081', $curlOpts[CURLOPT_PROXY]);
$this->assertEquals('me:secret', $curlOpts[CURLOPT_PROXYUSERPWD]);
$this->setExpectedException('PayPal\Exception\PPConfigurationException');
$o->setHttpProxy('invalid string');
}
}
?>