Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the software version to be the detailed request information on Omise dashboard #29

Merged
merged 2 commits into from Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions omise/controllers/front/base.php
Expand Up @@ -10,6 +10,18 @@
require_once _PS_MODULE_DIR_ . 'omise/setting.php';
}

/**
* Specify the software version when sending the request to Omise API. The specified versions will be displayed at
* Omise dashboard.
*
* This constant is used to append to request header, User-Agent. The request is send by library, Omise PHP.
*
* @see OmiseApiResource::genOptions() The function in library, Omise PHP, that uses this constant.
*/
if (! defined('OMISE_USER_AGENT_SUFFIX')) {
define('OMISE_USER_AGENT_SUFFIX', sprintf('OmisePrestaShop/%s PrestaShop/%s', Omise::MODULE_VERSION, _PS_VERSION_));
}

abstract class OmiseBasePaymentModuleFrontController extends ModuleFrontController
{
protected $charge;
Expand Down
@@ -0,0 +1,64 @@
<?php
use \Mockery as m;

class OmiseBasePaymentModuleFrontControllerTest extends PHPUnit_Framework_TestCase
{
public function setup()
{
$this->getMockBuilder(get_class(new stdClass()))
->setMockClassName('ModuleFrontController')
->setMethods(
array(
'__construct',
)
)
->getMock();

$this->getMockBuilder(get_class(new stdClass()))
->setMockClassName('PaymentModule')
->setMethods(
array(
'__construct',
)
)
->getMock();

m::mock('alias:\OmiseChargeClass');
m::mock('alias:\OmiseTransactionModel');
m::mock('alias:\PaymentOrder');

$this->getMockBuilder('OmiseBasePaymentModuleFrontController')
->getMockForAbstractClass();
}

/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testOmiseUserAgentSuffix_beforeCreateOmiseCharge_omisePrestaShopVersionForOmiseUserAgentSuffixMustBeDefined()
{
$omise_prestashop_version = 'OmisePrestaShop/' . Omise::MODULE_VERSION;

$omise_user_agent_suffix = explode(' ', OMISE_USER_AGENT_SUFFIX);

$this->assertEquals($omise_prestashop_version, $omise_user_agent_suffix[0]);
}

/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testOmiseUserAgentSuffix_beforeCreateOmiseCharge_prestaShopVersionForOmiseUserAgentSuffixMustBeDefined()
{
$prestashop_version = 'PrestaShop/' . _PS_VERSION_;

$omise_user_agent_suffix = explode(' ', OMISE_USER_AGENT_SUFFIX);

$this->assertEquals($prestashop_version, $omise_user_agent_suffix[1]);
}

public function tearDown()
{
m::close();
}
}