| @@ 10-125 (lines=116) @@ | ||
| 7 | ||
| 8 | use Ogone\DirectLink\DirectLinkMaintenanceResponse; |
|
| 9 | ||
| 10 | class DirectLinkMaintenanceResponseTest extends \PHPUnit_Framework_TestCase |
|
| 11 | { |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @test |
|
| 15 | * @expectedException InvalidArgumentException |
|
| 16 | */ |
|
| 17 | public function CantExistWithoutXmlFile() |
|
| 18 | { |
|
| 19 | $maintenanceResponse = new DirectLinkMaintenanceResponse(''); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** @test */ |
|
| 23 | public function ParametersCanBeRetrieved() |
|
| 24 | { |
|
| 25 | $xml = $this->provideXML(); |
|
| 26 | ||
| 27 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 28 | $this->assertEquals('5', $maintenanceResponse->getParam('orderid')); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @test |
|
| 33 | * @expectedException InvalidArgumentException |
|
| 34 | */ |
|
| 35 | public function RequestIsFilteredFromNonOgoneParameters() |
|
| 36 | { |
|
| 37 | $xml = $this->provideXML(); |
|
| 38 | ||
| 39 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 40 | $maintenanceResponse->getParam('unknown_param'); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @test |
|
| 45 | * @expectedException InvalidArgumentException |
|
| 46 | */ |
|
| 47 | public function ChecksInvalidXml() |
|
| 48 | { |
|
| 49 | $xml = $this->provideInvalidXML(); |
|
| 50 | ||
| 51 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** @test */ |
|
| 55 | public function ChecksStatus() |
|
| 56 | { |
|
| 57 | $xml = $this->provideXML(); |
|
| 58 | ||
| 59 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 60 | $this->assertTrue($maintenanceResponse->isSuccessful()); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** @test */ |
|
| 64 | public function AmountIsConvertedToCent() |
|
| 65 | { |
|
| 66 | $xml = $this->provideXML(); |
|
| 67 | ||
| 68 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 69 | $this->assertEquals(100, $maintenanceResponse->getParam('amount')); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function provideFloats() |
|
| 73 | { |
|
| 74 | return array( |
|
| 75 | array('17.89', 1789), |
|
| 76 | array('65.35', 6535), |
|
| 77 | array('12.99', 1299), |
|
| 78 | ); |
|
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * @test |
|
| 83 | * @dataProvider provideFloats |
|
| 84 | */ |
|
| 85 | public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
|
| 86 | { |
|
| 87 | $xml = $this->provideXML($string); |
|
| 88 | ||
| 89 | $maintenanceResponse = new DirectLinkMaintenanceResponse($xml); |
|
| 90 | $this->assertEquals($integer, $maintenanceResponse->getParam('amount')); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Helper method to setup an xml-string |
|
| 95 | */ |
|
| 96 | private function provideXML($amount = null) |
|
| 97 | { |
|
| 98 | ||
| 99 | $xml = '<?xml version="1.0"?> |
|
| 100 | <ncresponse |
|
| 101 | orderID="5" |
|
| 102 | PAYID="33146134" |
|
| 103 | NCERROR="0" |
|
| 104 | NCERRORPLUS="!" |
|
| 105 | ACCEPTANCE="" |
|
| 106 | STATUS="91" |
|
| 107 | AMOUNT="'.(($amount) ? $amount : '1').'" |
|
| 108 | CURRENCY="GBP"> |
|
| 109 | </ncresponse>'; |
|
| 110 | ||
| 111 | return $xml; |
|
| 112 | } |
|
| 113 | ||
| 114 | /** |
|
| 115 | * Helper method to setup an invalid xml-string |
|
| 116 | */ |
|
| 117 | private function provideInvalidXML() |
|
| 118 | { |
|
| 119 | $xml = '<?xml version="1.0"?> |
|
| 120 | <ncresponse |
|
| 121 | </ncresponse>'; |
|
| 122 | ||
| 123 | return $xml; |
|
| 124 | } |
|
| 125 | } |
|
| 126 | ||
| @@ 15-134 (lines=120) @@ | ||
| 12 | ||
| 13 | use Ogone\DirectLink\DirectLinkPaymentResponse; |
|
| 14 | ||
| 15 | class DirectLinkPaymentResponseTest extends \PHPUnit_Framework_TestCase |
|
| 16 | { |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @test |
|
| 20 | * @expectedException InvalidArgumentException |
|
| 21 | */ |
|
| 22 | public function CantExistWithoutXmlFile() |
|
| 23 | { |
|
| 24 | $paymentResponse = new DirectLinkPaymentResponse(''); |
|
| 25 | } |
|
| 26 | ||
| 27 | /** @test */ |
|
| 28 | public function ParametersCanBeRetrieved() |
|
| 29 | { |
|
| 30 | $xml = $this->provideXML(); |
|
| 31 | ||
| 32 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 33 | $this->assertEquals('123', $paymentResponse->getParam('orderid')); |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @test |
|
| 38 | * @expectedException InvalidArgumentException |
|
| 39 | */ |
|
| 40 | public function RequestIsFilteredFromNonOgoneParameters() |
|
| 41 | { |
|
| 42 | $xml = $this->provideXML(); |
|
| 43 | ||
| 44 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 45 | $paymentResponse->getParam('unknown_param'); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @test |
|
| 50 | * @expectedException InvalidArgumentException |
|
| 51 | */ |
|
| 52 | public function ChecksInvalidXml() |
|
| 53 | { |
|
| 54 | $xml = $this->provideInvalidXML(); |
|
| 55 | ||
| 56 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** @test */ |
|
| 60 | public function ChecksStatus() |
|
| 61 | { |
|
| 62 | $xml = $this->provideXML(); |
|
| 63 | ||
| 64 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 65 | $this->assertTrue($paymentResponse->isSuccessful()); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** @test */ |
|
| 69 | public function AmountIsConvertedToCent() |
|
| 70 | { |
|
| 71 | $xml = $this->provideXML(); |
|
| 72 | ||
| 73 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 74 | $this->assertEquals(100, $paymentResponse->getParam('amount')); |
|
| 75 | } |
|
| 76 | ||
| 77 | public function provideFloats() |
|
| 78 | { |
|
| 79 | return array( |
|
| 80 | array('17.89', 1789), |
|
| 81 | array('65.35', 6535), |
|
| 82 | array('12.99', 1299), |
|
| 83 | ); |
|
| 84 | } |
|
| 85 | ||
| 86 | /** |
|
| 87 | * @test |
|
| 88 | * @dataProvider provideFloats |
|
| 89 | */ |
|
| 90 | public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
|
| 91 | { |
|
| 92 | $xml = $this->provideXML($string); |
|
| 93 | ||
| 94 | $paymentResponse = new DirectLinkPaymentResponse($xml); |
|
| 95 | $this->assertEquals($integer, $paymentResponse->getParam('amount')); |
|
| 96 | } |
|
| 97 | ||
| 98 | /** |
|
| 99 | * Helper method to setup an xml-string |
|
| 100 | */ |
|
| 101 | private function provideXML($amount = null) |
|
| 102 | { |
|
| 103 | ||
| 104 | $xml = '<?xml version="1.0"?> |
|
| 105 | <ncresponse |
|
| 106 | ||
| 107 | ORDERID="123" |
|
| 108 | PAYID="0" |
|
| 109 | NCSTATUS="5" |
|
| 110 | NCERROR="" |
|
| 111 | ACCEPTANCE="" |
|
| 112 | STATUS="5" |
|
| 113 | AMOUNT="'.(($amount) ? $amount : '1').'" |
|
| 114 | CURRENCY="EUR" |
|
| 115 | PM="" |
|
| 116 | BRAND="" |
|
| 117 | NCERRORPLUS=""> |
|
| 118 | </ncresponse>'; |
|
| 119 | ||
| 120 | return $xml; |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * Helper method to setup an invalid xml-string |
|
| 125 | */ |
|
| 126 | private function provideInvalidXML() |
|
| 127 | { |
|
| 128 | $xml = '<?xml version="1.0"?> |
|
| 129 | <ncresponse |
|
| 130 | </ncresponse>'; |
|
| 131 | ||
| 132 | return $xml; |
|
| 133 | } |
|
| 134 | } |
|
| 135 | ||
| @@ 10-132 (lines=123) @@ | ||
| 7 | ||
| 8 | use Ogone\DirectLink\DirectLinkQueryResponse; |
|
| 9 | ||
| 10 | class DirectLinkQueryResponseTest extends \PHPUnit_Framework_TestCase |
|
| 11 | { |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @test |
|
| 15 | * @expectedException InvalidArgumentException |
|
| 16 | */ |
|
| 17 | public function CantExistWithoutXmlFile() |
|
| 18 | { |
|
| 19 | $queryResponse = new DirectLinkQueryResponse(''); |
|
| 20 | } |
|
| 21 | ||
| 22 | /** @test */ |
|
| 23 | public function ParametersCanBeRetrieved() |
|
| 24 | { |
|
| 25 | $xml = $this->provideXML(); |
|
| 26 | ||
| 27 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 28 | $this->assertEquals('5', $queryResponse->getParam('orderid')); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @test |
|
| 33 | * @expectedException InvalidArgumentException |
|
| 34 | */ |
|
| 35 | public function RequestIsFilteredFromNonOgoneParameters() |
|
| 36 | { |
|
| 37 | $xml = $this->provideXML(); |
|
| 38 | ||
| 39 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 40 | $queryResponse->getParam('unknown_param'); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @test |
|
| 45 | * @expectedException InvalidArgumentException |
|
| 46 | */ |
|
| 47 | public function ChecksInvalidXml() |
|
| 48 | { |
|
| 49 | $xml = $this->provideInvalidXML(); |
|
| 50 | ||
| 51 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** @test */ |
|
| 55 | public function ChecksStatus() |
|
| 56 | { |
|
| 57 | $xml = $this->provideXML(); |
|
| 58 | ||
| 59 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 60 | $this->assertTrue($queryResponse->isSuccessful()); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** @test */ |
|
| 64 | public function AmountIsConvertedToCent() |
|
| 65 | { |
|
| 66 | $xml = $this->provideXML(); |
|
| 67 | ||
| 68 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 69 | $this->assertEquals(450, $queryResponse->getParam('amount')); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function provideFloats() |
|
| 73 | { |
|
| 74 | return array( |
|
| 75 | array('17.89', 1789), |
|
| 76 | array('65.35', 6535), |
|
| 77 | array('12.99', 1299), |
|
| 78 | ); |
|
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * @test |
|
| 83 | * @dataProvider provideFloats |
|
| 84 | */ |
|
| 85 | public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
|
| 86 | { |
|
| 87 | $xml = $this->provideXML($string); |
|
| 88 | ||
| 89 | $queryResponse = new DirectLinkQueryResponse($xml); |
|
| 90 | $this->assertEquals($integer, $queryResponse->getParam('amount')); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Helper method to setup an xml-string |
|
| 95 | */ |
|
| 96 | private function provideXML($amount = null) |
|
| 97 | { |
|
| 98 | ||
| 99 | $xml = '<?xml version="1.0"?> |
|
| 100 | <ncresponse |
|
| 101 | orderID="5" |
|
| 102 | PAYID="33146134" |
|
| 103 | PAYIDSUB="" |
|
| 104 | NCSTATUS="0" |
|
| 105 | NCERROR="0" |
|
| 106 | NCERRORPLUS="!" |
|
| 107 | ACCEPTANCE="test123" |
|
| 108 | STATUS="91" |
|
| 109 | ECI="7" |
|
| 110 | AMOUNT="'.(($amount) ? $amount : '4.5').'" |
|
| 111 | CURRENCY="GBP" |
|
| 112 | PM="CreditCard" |
|
| 113 | BRAND="VISA" |
|
| 114 | CARDNO="XXXXXXXXXXXX1111" |
|
| 115 | IP="127.0.0.1"> |
|
| 116 | </ncresponse>'; |
|
| 117 | ||
| 118 | return $xml; |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * Helper method to setup an invalid xml-string |
|
| 123 | */ |
|
| 124 | private function provideInvalidXML() |
|
| 125 | { |
|
| 126 | $xml = '<?xml version="1.0"?> |
|
| 127 | <ncresponse |
|
| 128 | </ncresponse>'; |
|
| 129 | ||
| 130 | return $xml; |
|
| 131 | } |
|
| 132 | } |
|
| 133 | ||