SettlementTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Report;
  7. class SettlementTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @magentoDbIsolation enabled
  11. */
  12. public function testFetchAndSave()
  13. {
  14. /** @var $model \Magento\Paypal\Model\Report\Settlement; */
  15. $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  16. \Magento\Paypal\Model\Report\Settlement::class
  17. );
  18. $connection = $this->createPartialMock(\Magento\Framework\Filesystem\Io\Sftp::class, ['rawls', 'read']);
  19. $filename = 'STL-00000000.00.abc.CSV';
  20. $connection->expects($this->once())->method('rawls')->will($this->returnValue([$filename => []]));
  21. $connection->expects($this->once())->method('read')->with($filename, $this->anything());
  22. $model->fetchAndSave($connection);
  23. }
  24. /**
  25. * @param array $config
  26. * @expectedException \InvalidArgumentException
  27. * @dataProvider createConnectionExceptionDataProvider
  28. */
  29. public function testCreateConnectionException($config)
  30. {
  31. \Magento\Paypal\Model\Report\Settlement::createConnection($config);
  32. }
  33. /**
  34. * @param array $automaticMode
  35. * @param array $expectedResult
  36. *
  37. * @dataProvider createAutomaticModeDataProvider
  38. *
  39. * @magentoConfigFixture default_store paypal/fetch_reports/active 0
  40. * @magentoConfigFixture default_store paypal/fetch_reports/ftp_ip 192.168.0.1
  41. * @magentoConfigFixture current_store paypal/fetch_reports/active 1
  42. * @magentoConfigFixture current_store paypal/fetch_reports/ftp_ip 127.0.0.1
  43. * @magentoConfigFixture current_store paypal/fetch_reports/ftp_path /tmp
  44. * @magentoConfigFixture current_store paypal/fetch_reports/ftp_login login
  45. * @magentoConfigFixture current_store paypal/fetch_reports/ftp_password password
  46. * @magentoConfigFixture current_store paypal/fetch_reports/ftp_sandbox 0
  47. * @magentoDbIsolation enabled
  48. */
  49. public function testGetSftpCredentials($automaticMode, $expectedResult)
  50. {
  51. /** @var $model \Magento\Paypal\Model\Report\Settlement; */
  52. $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  53. \Magento\Paypal\Model\Report\Settlement::class
  54. );
  55. $result = $model->getSftpCredentials($automaticMode);
  56. $this->assertEquals($expectedResult, $result);
  57. }
  58. /**
  59. * @return array
  60. */
  61. public function createConnectionExceptionDataProvider()
  62. {
  63. return [
  64. [[]],
  65. [['username' => 'test', 'password' => 'test', 'path' => '/']],
  66. [['hostname' => 'example.com', 'password' => 'test', 'path' => '/']],
  67. [['hostname' => 'example.com', 'username' => 'test', 'path' => '/']],
  68. [['hostname' => 'example.com', 'username' => 'test', 'password' => 'test']]
  69. ];
  70. }
  71. /**
  72. * @return array
  73. */
  74. public function createAutomaticModeDataProvider()
  75. {
  76. return [
  77. [
  78. true,
  79. [
  80. [
  81. 'hostname' => '127.0.0.1',
  82. 'path' => '/tmp',
  83. 'username' => 'login',
  84. 'password' => 'password',
  85. 'sandbox' => '0'
  86. ]
  87. ]
  88. ],
  89. [
  90. false,
  91. [
  92. [
  93. 'hostname' => '127.0.0.1',
  94. 'path' => '/tmp',
  95. 'username' => 'login',
  96. 'password' => 'password',
  97. 'sandbox' => '0'
  98. ]
  99. ]
  100. ],
  101. ];
  102. }
  103. }