Exemplo n.º 1
0
 /**
  * Test converting JSON with unknown data to {@link HppResponse}.
  */
 public function testFromJsonHppResponseUnknownData()
 {
     $path = SampleJsonData::UNKNOWN_DATA_HPP_RESPONSE_JSON_PATH;
     $prefix = __DIR__ . '/../../../resources';
     $json = file_get_contents($prefix . $path);
     $hppResponseExpected = SampleJsonData::generateValidHppResponse();
     $hppResponseConverted = JsonUtils::fromJsonHppResponse($json);
     SampleJsonData::checkValidHppResponse($hppResponseExpected, $hppResponseConverted, $this);
     SampleJsonData::checkValidHppResponseSupplementaryData($hppResponseConverted, $this);
 }
 public function testHash()
 {
     $hppRequest = SampleJsonData::generateValidHppRequest(false);
     $hppRequest->setTimeStamp(self::TIMESTAMP);
     $hppRequest->setMerchantId(self::MERCHANT_ID);
     $hppRequest->setOrderId(self::ORDER_ID);
     $hppRequest->setAmount(self::AMOUNT);
     $hppRequest->setCurrency(self::CURRENCY);
     $expectedHash = "e96eed4869a6d682e8fdbb88703ed81faa58f4df";
     $actualHash = $hppRequest->hash("mysecret")->getHash();
     $this->assertEquals($expectedHash, $actualHash, "Card storage hash does not match expected.");
 }
Exemplo n.º 3
0
 public function testHash()
 {
     $hppRequest = SampleJsonData::generateValidHppRequest(false);
     $hppRequest->setTimeStamp(self::TIMESTAMP);
     $hppRequest->setMerchantId(self::MERCHANT_ID);
     $hppRequest->setOrderId(self::ORDER_ID);
     $hppRequest->setAmount(self::AMOUNT);
     $hppRequest->setCurrency(self::CURRENCY);
     $expectedHash = "cc72c08e529b3bc153481eda9533b815cef29de3";
     $actualHash = $hppRequest->hash("mysecret")->getHash();
     $this->assertEquals($expectedHash, $actualHash, "Card storage hash does not match expected.");
 }
 /**
  * Test converting a {@link HppRequest} object to JSON. Includes validation and generation of defaults.
  */
 public function testValidationFailsPostDimensions()
 {
     $hppRequest = SampleJsonData::generateValidHppRequestWithEmptyDefaults(false);
     //limit is 255
     $postDimensions = str_repeat('a', 256);
     //testing add method
     $hppRequest = $hppRequest->addPostDimensions($postDimensions);
     try {
         ValidationUtils::validate($hppRequest);
         $this->fail("This HppRequest should have validation errors.");
     } catch (RealexValidationException $e) {
         $validationMessages = $e->getValidationMessages();
         $this->assertEquals(ValidationMessages::hppRequest_postDimensions_size, $validationMessages[0]);
     }
 }
 /**
  * Test supplementary data second field
  */
 public function testCardSupplementaryData2()
 {
     $hppRequest = SampleJsonData::generateValidHppRequest(false);
     $hppRequest->generateDefaults(SampleJsonData::SECRET);
     $supplementaryData1 = "";
     $supplementaryData2 = "";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should have no validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = " azAZ09'\",+“”._- & ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "\\/@!?%()*:£\$&€#[]|";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "=ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "ÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæ";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "çèéêëìíîïðñòóôõö÷ø¤ù";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $supplementaryData2 = "úûüýþÿŒŽšœžŸ¥";
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $supplementaryData2;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $charsAtMax = str_repeat("1", 255);
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $charsAtMax;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
     } catch (RealexValidationException $e) {
         $this->fail("This HppRequest should not have validation errors.");
     }
     $supplementaryData1 = "";
     $charsOverMax = str_repeat("a", 256);
     $supplementaryData = array();
     $supplementaryData[] = $supplementaryData1;
     $supplementaryData[] = $charsOverMax;
     $hppRequest->setSupplementaryData($supplementaryData);
     try {
         ValidationUtils::validate($hppRequest);
         $this->fail("This HppRequest should have validation errors.");
     } catch (RealexValidationException $e) {
         $validationMessages = $e->getValidationMessages();
         $this->assertEquals(ValidationMessages::hppRequest_supplementary_data_size, $validationMessages[0]);
     }
 }
     * @param HppResponse $hppResponse
     * @param PHPUnit_Framework_TestCase $testCase
     */
    public static function checkValidHppResponseSupplementaryData(HppResponse $hppResponse, PHPUnit_Framework_TestCase $testCase)
    {
        $supplementaryData = $hppResponse->getSupplementaryData();
        $testCase->assertEquals(self::UNKNOWN_ONE_VALUE, $supplementaryData[self::UNKNOWN_ONE_KEY], "Json conversion incorrect Unknown one");
        $testCase->assertEquals(self::UNKNOWN_TWO_VALUE, $supplementaryData[self::UNKNOWN_TWO_KEY], "Json conversion incorrect Unknown one");
        $testCase->assertEquals(self::UNKNOWN_THREE_VALUE, $supplementaryData[self::UNKNOWN_THREE_KEY], "Json conversion incorrect Unknown one");
        $testCase->assertEquals(self::UNKNOWN_FOUR_VALUE, $supplementaryData[self::UNKNOWN_FOUR_KEY], "Json conversion incorrect Unknown one");
        $testCase->assertEquals(sizeof(self::$SUPPLEMENTARY_DATA), sizeof($supplementaryData), "Json conversion incorrect size");
    }
    /**
     * Checks request post dimensions matches expected values.
     *
     * @param HppRequest $hppRequestConverted
     * @param PHPUnit_Framework_TestCase $testCase
     */
    public static function checkValidHppRequestPostDimensions(HppRequest $hppRequestConverted, PHPUnit_Framework_TestCase $testCase)
    {
        $postDimensions = $hppRequestConverted->getPostDimensions();
        $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect ");
        $testCase->assertEquals(sizeof(self::POST_DIMENSIONS), sizeof($postDimensions), "Json conversion incorrect size");
        $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET);
        $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET);
        $postDimensions = $hppRequestConverted->getPostDimensions();
        $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect ");
    }
}
SampleJsonData::Init();