Skip to content

Commit

Permalink
Update Configuration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
regdos committed Apr 5, 2016
1 parent 289c08f commit fde022e
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 33 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"license": "LGPL-3.0",
"description": "OpenPayU PHP Library",
"version": "2.2.0-DEV",
"version": "2.2.X-DEV",
"extra": [
{
"engine": "PHP SDK"
Expand All @@ -17,12 +17,12 @@
}
],
"require": {
"php": ">=5.2.1",
"php": ">=5.3.0",
"ext-curl": "*",
"ext-hash": "*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "5.3.*"
},
"support": {
"issues": "https://github.com/PayU/openpayu_php/issues"
Expand Down
5 changes: 1 addition & 4 deletions lib/OpenPayU/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* http://www.payu.com
* http://developers.payu.com
*/

class OpenPayU_Configuration
{
private static $_availableEnvironment = array('custom', 'secure');
Expand Down Expand Up @@ -47,14 +46,13 @@ class OpenPayU_Configuration
private static $oauthTokenCache = null;

private static $serviceUrl = '';
private static $serviceDomain = '';
private static $hashAlgorithm = 'SHA-256';

private static $sender = 'Generic';

const API_VERSION = '2.1';
const COMPOSER_JSON = "/composer.json";
const DEFAULT_SDK_VERSION = 'PHP SDK 2.2.X-DEV / OAUTH';
const DEFAULT_SDK_VERSION = 'PHP SDK 2.2.X-DEV';
const OAUTH_CONTEXT = 'pl/standard/user/oauth/authorize';

/**
Expand Down Expand Up @@ -104,7 +102,6 @@ public static function setEnvironment($environment = 'secure', $domain = 'payu.c

if ($environment == 'secure') {
self::$env = $environment;
self::$serviceDomain = $domain;
self::$serviceUrl = 'https://' . $environment . '.' . $domain . $api . $version;
self::$oauthEndpoint = 'https://' . $environment . '.' . $domain . self::OAUTH_CONTEXT;
} else if ($environment == 'custom') {
Expand Down
151 changes: 125 additions & 26 deletions tests/unit/OpenPayU_ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,32 @@
*/

require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
require realpath(dirname(__FILE__)).'\..\..\vendor/autoload.php';
require realpath(dirname(__FILE__)) . '\..\..\vendor/autoload.php';


class OpenPayU_ConfigurationTest extends PHPUnit_Framework_TestCase
{

const PHP_SDK_VERSION = 'PHP SDK 2.1.6';
const PHP_SDK_VERSION = 'PHP SDK 2.2.X-DEV';
const API_VERSION = '2.1';
const POS_ID = 'PosId';
const SIGNATURE_KEY = 'SignatureKey';
const OAUTH_CLIENT_ID = 'OauthClientId';
const OAUTH_CLIENT_SECRET = 'OauthClientSecret';


public function testValidApiVersion()
{
//then
$this->assertEquals(self::API_VERSION, OpenPayU_Configuration::getApiVersion());
}

public function testSetValidEnvironment()
{
//when
OpenPayU_Configuration::setEnvironment('secure');

//then
$this->assertEquals('secure', OpenPayU_Configuration::getEnvironment());
}

Expand All @@ -32,76 +47,160 @@ public function testSetValidEnvironment()
*/
public function testSetInvalidEnvironment()
{
//when
OpenPayU_Configuration::setEnvironment('environment');
}

public function testSecureServiceUrl()
{
//when
OpenPayU_Configuration::setEnvironment('secure');

//then
$this->assertEquals('https://secure.payu.com/api/v2_1/', OpenPayU_Configuration::getServiceUrl());
}

public function testCustomServiceUrl()
{
//when
OpenPayU_Configuration::setEnvironment('custom', 'http://testdomain.com', 'testapi/', 'vTest_1/');

//then
$this->assertEquals('http://testdomain.com/testapi/vTest_1/', OpenPayU_Configuration::getServiceUrl());
}

public function testSecureOauthEndpoint()
{
//when
OpenPayU_Configuration::setEnvironment('secure');

//then
$this->assertEquals('https://secure.payu.com/pl/standard/user/oauth/authorize', OpenPayU_Configuration::getOauthEndpoint());
}

public function testCustomOauthEndpointUrl()
{
//when
OpenPayU_Configuration::setEnvironment('custom', 'http://testdomain.com', 'testapi/', 'vTest_1/');

//then
$this->assertEquals('http://testdomain.com/pl/standard/user/oauth/authorize', OpenPayU_Configuration::getOauthEndpoint());
}


public function testSetValidHashAlgorithm()
{
//when
OpenPayU_Configuration::setHashAlgorithm('SHA');

//then
$this->assertEquals('SHA', OpenPayU_Configuration::getHashAlgorithm());
}

/**
* @expectedException OpenPayU_Exception_Configuration
* @expectedExceptionMessage Hash algorithm "hash"" is not available
* @expectedExceptionMessage Hash algorithm "MD5"" is not available
*/
public function testSetInvalidHashAlgorithm()
{
OpenPayU_Configuration::setHashAlgorithm('hash');
//when
OpenPayU_Configuration::setHashAlgorithm('MD5');
}

public function testMerchantPosId()
{
OpenPayU_Configuration::setMerchantPosId('PosId');
$this->assertEquals('PosId', OpenPayU_Configuration::getMerchantPosId());
//when
OpenPayU_Configuration::setMerchantPosId(self::POS_ID);

//then
$this->assertEquals(self::POS_ID, OpenPayU_Configuration::getMerchantPosId());
}

public function testSignatureKey()
{
OpenPayU_Configuration::setSignatureKey('SignatureKey');
$this->assertEquals('SignatureKey', OpenPayU_Configuration::getSignatureKey());
//when
OpenPayU_Configuration::setSignatureKey(self::SIGNATURE_KEY);

//then
$this->assertEquals(self::SIGNATURE_KEY, OpenPayU_Configuration::getSignatureKey());
}

public function testServiceUrl()
public function testOauthClientId()
{
OpenPayU_Configuration::setEnvironment('secure');
$this->assertEquals('https://secure.payu.com/api/v2_1/', OpenPayU_Configuration::getServiceUrl());
//when
OpenPayU_Configuration::setOauthClientId(self::OAUTH_CLIENT_ID);

//then
$this->assertEquals(self::OAUTH_CLIENT_ID, OpenPayU_Configuration::getOauthClientId());
}

public function testFullSenderName(){
$this->assertEquals('Generic@'.self::PHP_SDK_VERSION, OpenPayU_Configuration::getFullSenderName());
public function testOauthClientSecret()
{
//when
OpenPayU_Configuration::setOauthClientSecret(self::OAUTH_CLIENT_SECRET);

//then
$this->assertEquals(self::OAUTH_CLIENT_SECRET, OpenPayU_Configuration::getOauthClientSecret());
}

/**
* @expectedException OpenPayU_Exception_Configuration
* @expectedExceptionMessage Oauth token cache class is not instance of OauthCacheInterface
*/
public function testNotOautchCacheInterfaceOfOauthTokenCache()
{
//when
OpenPayU_Configuration::setOauthTokenCache(new stdClass());
}

public function testOautchCacheInterfaceOfOauthTokenCache()
{
//given
$cacheFile = new OauthCacheFile('./');

//when
OpenPayU_Configuration::setOauthTokenCache($cacheFile);

//then
$this->assertInstanceOf('OauthCacheFile', OpenPayU_Configuration::getOauthTokenCache());
}

public function testFullSenderName()
{
//then
$this->assertEquals('Generic@' . self::PHP_SDK_VERSION, OpenPayU_Configuration::getFullSenderName());
}


/**
* @test
*/
public function shouldReturnValidSenderFullNameWhenSenderIsGiven(){
public function shouldReturnValidSenderFullNameWhenSenderIsGiven()
{
//given
OpenPayU_Configuration::setSender("Test Data");

//then
$this->assertEquals('Test Data@' . self::PHP_SDK_VERSION, OpenPayU_Configuration::getFullSenderName());
}

/**
* @test
*/
public function shouldReturnValidSDKVersionWhenComposerFileIsGiven(){
//when
$sdkVersion = OpenPayU_Configuration::getSdkVersion();
public function shouldReturnValidSDKVersionWhenComposerFileIsGiven()
{
//then
$this->assertEquals(self::PHP_SDK_VERSION,$sdkVersion);
$this->assertEquals(self::PHP_SDK_VERSION, OpenPayU_Configuration::getSdkVersion());
}

/**
* @test
*/
public function shouldReturnDefgaultSDKVersionWhenComposerFileIsNotGiven(){
//given
$OpenPayU_ConfigurationMock = $this->getMock('OpenPayU_Configuration');
$OpenPayU_ConfigurationMock->expects($this->any())->method('getComposerFilePath')
->will($this->returnValue('mock.json'));
//when
$sdkVersion = OpenPayU_Configuration::getSdkVersion();
public function shouldDefaultSDKVersionAndFromJsonIsTheSame()
{
//then
$this->assertEquals(self::PHP_SDK_VERSION,$sdkVersion);
$this->assertEquals(OpenPayU_Configuration::DEFAULT_SDK_VERSION, OpenPayU_Configuration::getSdkVersion());
}


}

0 comments on commit fde022e

Please sign in to comment.