DataTest.php 3.51 KB
Newer Older
Giorgos Adam's avatar
Giorgos Adam committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

namespace Adyen\Payment\Tests\Helper;

Jeroen's avatar
Jeroen committed
26
class DataTest extends \PHPUnit\Framework\TestCase
Giorgos Adam's avatar
Giorgos Adam committed
27
{
Jeroen's avatar
Jeroen committed
28 29 30
    /**
     * @var \Adyen\Payment\Helper\Data
     */
Giorgos Adam's avatar
Giorgos Adam committed
31 32 33 34 35 36 37 38 39 40 41
    private $dataHelper;

    private function getSimpleMock($originalClassName)
    {
        return $this->getMockBuilder($originalClassName)
            ->disableOriginalConstructor()
            ->getMock();
    }

    public function setUp()
    {
Jeroen's avatar
Jeroen committed
42 43 44 45 46 47 48 49 50
        $context = $this->getSimpleMock(\Magento\Framework\App\Helper\Context::class);
        $encryptor = $this->getSimpleMock(\Magento\Framework\Encryption\EncryptorInterface::class);
        $dataStorage = $this->getSimpleMock(\Magento\Framework\Config\DataInterface::class);
        $country = $this->getSimpleMock(\Magento\Directory\Model\Config\Source\Country::class);
        $moduleList = $this->getSimpleMock(\Magento\Framework\Module\ModuleListInterface::class);
        $billingAgreementCollectionFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory::class);
        $assetRepo = $this->getSimpleMock(\Magento\Framework\View\Asset\Repository::class);
        $assetSource = $this->getSimpleMock(\Magento\Framework\View\Asset\Source::class);
        $notificationFactory = $this->getSimpleMock(\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory::class);
Giorgos Adam's avatar
Giorgos Adam committed
51

Jeroen's avatar
Jeroen committed
52
        $this->dataHelper = new \Adyen\Payment\Helper\Data($context, $encryptor, $dataStorage, $country, $moduleList,
Giorgos Adam's avatar
Giorgos Adam committed
53 54 55 56 57
            $billingAgreementCollectionFactory, $assetRepo, $assetSource, $notificationFactory);
    }

    public function testFormatAmount()
    {
Jeroen's avatar
Jeroen committed
58 59 60
        $this->assertEquals('1234', $this->dataHelper->formatAmount('12.34', 'EUR'));
        $this->assertEquals('1200', $this->dataHelper->formatAmount('12.00', 'USD'));
        $this->assertEquals('12', $this->dataHelper->formatAmount('12.00', 'JPY'));
Giorgos Adam's avatar
Giorgos Adam committed
61
    }
62 63 64
    
    public function testisPaymentMethodOpenInvoiceMethod()
    {
Jeroen's avatar
Jeroen committed
65 66 67 68 69 70 71
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('klarna'));
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('klarna_account'));
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('afterpay'));
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('afterpay_default'));
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('ratepay'));
        $this->assertEquals(false, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('ideal'));
        $this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('test_klarna'));
72
    }
Giorgos Adam's avatar
Giorgos Adam committed
73
}