<commit_before><?php

namespace Omnipay\AuthorizeNet;

use Omnipay\Tests\GatewayTestCase;

class CIMGatewayTest extends GatewayTestCase
{
    /** @var CIMGateway */
    protected $gateway;
    protected $createCardOptions;
    protected $purchaseOptions;
    protected $captureOptions;
    protected $authorizeOptions;
    protected $refundOptions;

    public function setUp()
    {
        parent::setUp();

        $this->gateway = new CIMGateway($this->getHttpClient(), $this->getHttpRequest());

        $this->createCardOptions = array(
            'email' => "<EMAIL>",
            'card' => $this->getValidCard(),
            'testMode' => true,
            'forceCardUpdate' => true
        );

        $this->authorizeOptions = array(
            'cardReference' => '{"customerProfileId":"28972084","customerPaymentProfileId":"26317840","customerShippingAddressId":"27057149"}',
            'amount' => 10.00,
            'description' => 'authorize'
        );

        $this->captureOptions = array(
            'amount' => '10.00',
            'description' => 'capture',
            'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',
        );

        $this->refundOptions = array(
            'amount' => '10.00',
            'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',
            'description' => 'refund'
        );
    }

    public function testLiveEndpoint()
    {
        $this->assertEquals(
            'https://api2.authorize.net/xml/v1/request.api',
            $this->gateway->getLiveEndpoint()
        );
    }

    public function testDeveloperEndpoint()
    {
        $this->assertEquals(
            'https://apitest.authorize.net/xml/v1/request.api',
            $this->gateway->getDeveloperEndpoint()
        );
    }

    public function testCreateCardSuccess()
    {
        $this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt'));

        $response = $this->gateway->createCard($this->createCardOptions)->send();

        $this->assertTrue($response->isSuccessful());
        $this->assertSame(
            '{"customerProfileId":"28972084","customerPaymentProfileId":"26485433"}',
            $response->getCardReference()
        );
        $this->assertSame('Successful.', $response->getMessage());
    }

    public function testShouldCreateCardIfDuplicateCustomerProfileExists()
    {
        $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
        'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));

        $response = $this->gateway->createCard($this->createCardOptions)->send();
<commit_msg>Extended PR #78 test to CIM gateway.<commit_after><?php

namespace Omnipay\AuthorizeNet;

use Omnipay\Tests\GatewayTestCase;

class CIMGatewayTest extends GatewayTestCase
{
    /** @var CIMGateway */
    protected $gateway;
    protected $createCardOptions;
    protected $purchaseOptions;
    protected $captureOptions;
    protected $authorizeOptions;
    protected $refundOptions;

    public function setUp()
    {
        parent::setUp();

        $this->gateway = new CIMGateway($this->getHttpClient(), $this->getHttpRequest());

        $this->gateway->initialize([
            'hashSecret' => 'HASHYsecretyThang',
        ]);

        $this->createCardOptions = array(
            'email' => "<EMAIL>",
            'card' => $this->getValidCard(),
            'testMode' => true,
            'forceCardUpdate' => true
        );

        $this->authorizeOptions = array(
            'cardReference' => '{"customerProfileId":"28972084","customerPaymentProfileId":"26317840","customerShippingAddressId":"27057149"}',
            'amount' => 10.00,
            'description' => 'authorize'
        );

        $this->captureOptions = array(
            'amount' => '10.00',
            'description' => 'capture',
            'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',
        );

        $this->refundOptions = array(
            'amount' => '10.00',
            'transactionReference' => '{"approvalCode":"DMK100","transId":"2220001902","cardReference":"{\"customerProfileId\":\"28972084\",\"customerPaymentProfileId\":\"26317840\",\"customerShippingAddressId\":\"27057149\"}"}',
            'description' => 'refund'
        );
    }

    public function testLiveEndpoint()
    {
        $this->assertEquals(
            'https://api2.authorize.net/xml/v1/request.api',
            $this->gateway->getLiveEndpoint()
        );
    }

    public function testDeveloperEndpoint()
    {
        $this->assertEquals(
            'https://apitest.authorize.net/xml/v1/request.api',
            $this->gateway->getDeveloperEndpoint()
        );
    }

    // Added for PR #78
    public function testHashSecret()
    {
        $this->assertEquals(
            'HASHYsecretyThang',
            $this->gateway->getHashSecret()
        );
    }

    public function testCreateCardSuccess()
    {
        $this->setMockHttpResponse(array('CIMCreateCardSuccess.txt','CIMGetPaymentProfileSuccess.txt'));

        $response = $this->gateway->createCard($this->createCardOptions)->send();

        $this->assertTrue($response->isSuccessful());
        $this->assertSame(
            '{"customerProfileId":"28972084","customerPaymentProfileId":"26485433"}',
            $response->getCardReference()
        );
        $this->assertSame('Successful.', $response->getMessage());
    }

    public function testShouldCreateCardIfDuplicateCustomerProfileExists()
    {
        $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
        'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));

        $response = $this->gateway->createCard($this->createCardOptions)->send();

{'fraction_non_alphanumeric': 0.1598224195338513, 'fraction_numerical': 0.04154114475979071, 'mean_word_length': 2.972292191435768, 'pattern_counts': {'":': 34, '<': 7, '<?xml version=': 0, '>': 97, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253220', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1766, 'n_words': 215}