SettlementTest.php 3.75 KB
Newer Older
Ketan's avatar
Ketan 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Paypal\Model\Report;

class SettlementTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @magentoDbIsolation enabled
     */
    public function testFetchAndSave()
    {
        /** @var $model \Magento\Paypal\Model\Report\Settlement; */
        $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
            \Magento\Paypal\Model\Report\Settlement::class
        );
        $connection = $this->createPartialMock(\Magento\Framework\Filesystem\Io\Sftp::class, ['rawls', 'read']);
        $filename = 'STL-00000000.00.abc.CSV';
        $connection->expects($this->once())->method('rawls')->will($this->returnValue([$filename => []]));
        $connection->expects($this->once())->method('read')->with($filename, $this->anything());
        $model->fetchAndSave($connection);
    }

    /**
     * @param array $config
     * @expectedException \InvalidArgumentException
     * @dataProvider createConnectionExceptionDataProvider
     */
    public function testCreateConnectionException($config)
    {
        \Magento\Paypal\Model\Report\Settlement::createConnection($config);
    }

    /**
     * @param array $automaticMode
     * @param array $expectedResult
     *
     * @dataProvider createAutomaticModeDataProvider
     *
     * @magentoConfigFixture default_store paypal/fetch_reports/active 0
     * @magentoConfigFixture default_store paypal/fetch_reports/ftp_ip 192.168.0.1
     * @magentoConfigFixture current_store paypal/fetch_reports/active 1
     * @magentoConfigFixture current_store paypal/fetch_reports/ftp_ip 127.0.0.1
     * @magentoConfigFixture current_store paypal/fetch_reports/ftp_path /tmp
     * @magentoConfigFixture current_store paypal/fetch_reports/ftp_login login
     * @magentoConfigFixture current_store paypal/fetch_reports/ftp_password password
     * @magentoConfigFixture current_store paypal/fetch_reports/ftp_sandbox 0
     * @magentoDbIsolation enabled
     */
    public function testGetSftpCredentials($automaticMode, $expectedResult)
    {
        /** @var $model \Magento\Paypal\Model\Report\Settlement; */
        $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
            \Magento\Paypal\Model\Report\Settlement::class
        );

        $result = $model->getSftpCredentials($automaticMode);

        $this->assertEquals($expectedResult, $result);
    }

    /**
     * @return array
     */
    public function createConnectionExceptionDataProvider()
    {
        return [
            [[]],
            [['username' => 'test', 'password' => 'test', 'path' => '/']],
            [['hostname' => 'example.com', 'password' => 'test', 'path' => '/']],
            [['hostname' => 'example.com', 'username' => 'test', 'path' => '/']],
            [['hostname' => 'example.com', 'username' => 'test', 'password' => 'test']]
        ];
    }

    /**
     * @return array
     */
    public function createAutomaticModeDataProvider()
    {
        return [
            [
                true,
                [
                    [
                        'hostname' => '127.0.0.1',
                        'path' => '/tmp',
                        'username' => 'login',
                        'password' => 'password',
                        'sandbox' => '0'
                    ]
                ]
            ],
            [
                false,
                [
                    [
                        'hostname' => '127.0.0.1',
                        'path' => '/tmp',
                        'username' => 'login',
                        'password' => 'password',
                        'sandbox' => '0'
                    ]
                ]
            ],
        ];
    }
}