1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Marlon Ogone package. |
5
|
|
|
* |
6
|
|
|
* (c) Marlon BVBA <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ogone\Tests\ShaComposer; |
13
|
|
|
|
14
|
|
|
use Ogone\HashAlgorithm; |
15
|
|
|
use Ogone\Passphrase; |
16
|
|
|
use Ogone\PaymentResponse; |
17
|
|
|
use Ogone\ShaComposer\LegacyShaComposer; |
18
|
|
|
|
19
|
|
|
class LegacyShaComposerTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
const PASSPHRASE = 'passphrase-set-in-ogone-interface'; |
22
|
|
|
const SHA1STRING = '66BF34D8B3EF2136E0C267BDBC1F708B8D75A8AA'; |
23
|
|
|
const SHA256STRING = '882D85FCCC6112A33D3B8A571C11723CAA6B642EED70843B35B15ABA0C2AD637'; |
24
|
|
|
const SHA512STRING = '8552200DD108CB5633A27D6D0A1FAB54378CB2385BFCEB27487992D16F5A7565E5DD4D38C0F2DB294213CD02E434F311021749E6DAB187357F786E3F199781CA'; |
25
|
|
|
|
26
|
|
|
/** @test */ |
27
|
|
View Code Duplication |
public function defaultParameters() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$aRequest = $this->provideRequest(); |
30
|
|
|
$composer = new LegacyShaComposer(new Passphrase(self::PASSPHRASE)); |
|
|
|
|
31
|
|
|
$shaString = $composer->compose($aRequest); |
32
|
|
|
$this->assertEquals(self::SHA1STRING, $shaString); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** @test */ |
36
|
|
View Code Duplication |
public function Sha1StringCanBeComposed() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$aRequest = $this->provideRequest(); |
39
|
|
|
|
40
|
|
|
$composer = new LegacyShaComposer(new Passphrase(self::PASSPHRASE), new HashAlgorithm(HashAlgorithm::HASH_SHA1)); |
|
|
|
|
41
|
|
|
$shaString = $composer->compose($aRequest); |
42
|
|
|
|
43
|
|
|
$this->assertEquals(self::SHA1STRING, $shaString); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** @test */ |
47
|
|
View Code Duplication |
public function Sha256StringCanBeComposed() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$aRequest = $this->provideRequest(); |
50
|
|
|
|
51
|
|
|
$composer = new LegacyShaComposer(new Passphrase(self::PASSPHRASE), new HashAlgorithm(HashAlgorithm::HASH_SHA256)); |
|
|
|
|
52
|
|
|
$shaString = $composer->compose($aRequest); |
53
|
|
|
|
54
|
|
|
$this->assertEquals(self::SHA256STRING, $shaString); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @test */ |
58
|
|
View Code Duplication |
public function Sha512StringCanBeComposed() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$aRequest = $this->provideRequest(); |
61
|
|
|
|
62
|
|
|
$composer = new LegacyShaComposer(new Passphrase(self::PASSPHRASE), new HashAlgorithm(HashAlgorithm::HASH_SHA512)); |
|
|
|
|
63
|
|
|
$shaString = $composer->compose($aRequest); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(self::SHA512STRING, $shaString); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function provideRequest() |
69
|
|
|
{ |
70
|
|
|
return array( |
71
|
|
|
'ACCEPTANCE' => 'test123', |
72
|
|
|
'AMOUNT' => '19.08', |
73
|
|
|
'BRAND' => 'VISA', |
74
|
|
|
'CARDNO' => 'XXXXXXXXXXXX1111', |
75
|
|
|
'CN' => 'Marlon', |
76
|
|
|
'CURRENCY' => 'EUR', |
77
|
|
|
'ED' => '0113', |
78
|
|
|
'IP' => '81.82.214.142', |
79
|
|
|
'NCERROR' => 0, |
80
|
|
|
'ORDERID' => 2101947639, |
81
|
|
|
'PAYID' => 10673859, |
82
|
|
|
'PM' => 'CreditCard', |
83
|
|
|
'STATUS' => PaymentResponse::STATUS_AUTHORISED, |
84
|
|
|
'TRXDATE' => '07/05/11' |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.