Skip to content

Commit 9337fad

Browse files
committed
Merge remote-tracking branch 'origin/MC-38829' into 2.4-develop-pr46
2 parents ecf39a2 + a7c061c commit 9337fad

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

app/code/Magento/Paypal/Model/Report/Settlement.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ public function getSftpCredentials($automaticMode = false)
595595
protected function _fileNameToDate($filename)
596596
{
597597
// Currently filenames look like STL-YYYYMMDD, so that is what we care about.
598+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
598599
$dateSnippet = substr(basename($filename), 4, 8);
599600
$result = substr($dateSnippet, 0, 4) . '-' . substr($dateSnippet, 4, 2) . '-' . substr($dateSnippet, 6, 2);
600601
return $result;
@@ -603,13 +604,16 @@ protected function _fileNameToDate($filename)
603604
/**
604605
* Filter SFTP file list by filename format
605606
*
607+
* Single Account format = STL-yyyymmdd.sequenceNumber.version.format
608+
* Multiple Account format = STL-yyyymmdd.reportingWindow.sequenceNumber.totalFiles.version.format
609+
*
606610
* @param array $list List of files as per $connection->rawls()
607611
* @return array Trimmed down list of files
608612
*/
609613
protected function _filterReportsList($list)
610614
{
611615
$result = [];
612-
$pattern = '/^STL-(\d{8,8})\.(\d{2,2})\.(.{3,3})\.CSV$/';
616+
$pattern = '/^STL-(\d{8,8})\.((\d{2,2})|(([A-Z])\.(\d{2,2})\.(\d{2,2})))\.(.{3,3})\.CSV$/';
613617
foreach ($list as $filename => $data) {
614618
if (preg_match($pattern, $filename)) {
615619
$result[$filename] = $data;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Test\Unit\Model\Report;
9+
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
use Magento\Paypal\Model\Report\Settlement;
12+
use Magento\Framework\Filesystem\Io\Sftp;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test for paypal settlement
19+
*/
20+
class SettlementTest extends TestCase
21+
{
22+
/**
23+
* @var Settlement
24+
*/
25+
private $settlement;
26+
27+
/**
28+
* @var WriteInterface|MockObject
29+
*/
30+
private $tmpDirectory;
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
protected function setUp(): void
36+
{
37+
$objectManagerHelper = new ObjectManagerHelper($this);
38+
$this->tmpDirectory = $this->getMockBuilder(WriteInterface::class)
39+
->disableOriginalConstructor()
40+
->getMock();
41+
$this->settlement = $objectManagerHelper->getObject(
42+
Settlement::class,
43+
[
44+
'_tmpDirectory' => $this->tmpDirectory
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test for filter report list
51+
*
52+
* @return void
53+
*/
54+
public function testFilterReportList(): void
55+
{
56+
$this->tmpDirectory->method('getAbsolutePath')
57+
->willReturn('');
58+
/** @var Sftp|MockObject $connection */
59+
$connection = $this->getMockBuilder(Sftp::class)
60+
->onlyMethods(['rawls', 'read'])
61+
->disableOriginalConstructor()
62+
->getMock();
63+
$connection->method('rawls')
64+
->willReturn(
65+
[
66+
'STL-20201221.01.009.CSV' => 'Single account',
67+
'STL-20201221.H.01.01.009.CSV' => 'Multiple account',
68+
]
69+
);
70+
$connection->expects($this->exactly(2))->method('read')->willReturn(false);
71+
$this->settlement->fetchAndSave($connection);
72+
}
73+
}

0 commit comments

Comments
 (0)