Skip to content

Commit 54b6de9

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents eebf603 + b094f4c commit 54b6de9

File tree

6 files changed

+178
-45
lines changed

6 files changed

+178
-45
lines changed

app/code/Magento/Catalog/Model/Category/FileInfo.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class FileInfo
4343
*/
4444
private $baseDirectory;
4545

46+
/**
47+
* @var ReadInterface
48+
*/
49+
private $pubDirectory;
50+
4651
/**
4752
* @param Filesystem $filesystem
4853
* @param Mime $mime
@@ -82,6 +87,20 @@ private function getBaseDirectory()
8287
return $this->baseDirectory;
8388
}
8489

90+
/**
91+
* Get Pub Directory read instance
92+
*
93+
* @return ReadInterface
94+
*/
95+
private function getPubDirectory()
96+
{
97+
if (!isset($this->pubDirectory)) {
98+
$this->pubDirectory = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
99+
}
100+
101+
return $this->pubDirectory;
102+
}
103+
85104
/**
86105
* Retrieve MIME type of requested file
87106
*
@@ -135,7 +154,7 @@ private function getFilePath($fileName)
135154
{
136155
$filePath = ltrim($fileName, '/');
137156

138-
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath();
157+
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath($filePath);
139158
$isFileNameBeginsWithMediaDirectoryPath = $this->isBeginsWithMediaDirectoryPath($fileName);
140159

141160
// if the file is not using a relative path, it resides in the catalog/category media directory
@@ -160,7 +179,7 @@ public function isBeginsWithMediaDirectoryPath($fileName)
160179
{
161180
$filePath = ltrim($fileName, '/');
162181

163-
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath();
182+
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath($filePath);
164183
$isFileNameBeginsWithMediaDirectoryPath = strpos($filePath, $mediaDirectoryRelativeSubpath) === 0;
165184

166185
return $isFileNameBeginsWithMediaDirectoryPath;
@@ -169,14 +188,22 @@ public function isBeginsWithMediaDirectoryPath($fileName)
169188
/**
170189
* Get media directory subpath relative to base directory path
171190
*
191+
* @param string $filePath
172192
* @return string
173193
*/
174-
private function getMediaDirectoryPathRelativeToBaseDirectoryPath()
194+
private function getMediaDirectoryPathRelativeToBaseDirectoryPath(string $filePath = '')
175195
{
176-
$baseDirectoryPath = $this->getBaseDirectory()->getAbsolutePath();
196+
$baseDirectory = $this->getBaseDirectory();
197+
$baseDirectoryPath = $baseDirectory->getAbsolutePath();
177198
$mediaDirectoryPath = $this->getMediaDirectory()->getAbsolutePath();
199+
$pubDirectoryPath = $this->getPubDirectory()->getAbsolutePath();
178200

179201
$mediaDirectoryRelativeSubpath = substr($mediaDirectoryPath, strlen($baseDirectoryPath));
202+
$pubDirectory = $baseDirectory->getRelativePath($pubDirectoryPath);
203+
204+
if (strpos($mediaDirectoryRelativeSubpath, $pubDirectory) === 0 && strpos($filePath, $pubDirectory) !== 0) {
205+
$mediaDirectoryRelativeSubpath = substr($mediaDirectoryRelativeSubpath, strlen($pubDirectory));
206+
}
180207

181208
return $mediaDirectoryRelativeSubpath;
182209
}

app/code/Magento/Catalog/Test/Unit/Model/Category/FileInfoTest.php

Lines changed: 87 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,41 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\File\Mime;
1111
use Magento\Framework\Filesystem;
12-
use Magento\Framework\Filesystem\Directory\WriteInterface;
1312
use Magento\Framework\Filesystem\Directory\ReadInterface;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
1416

15-
class FileInfoTest extends \PHPUnit\Framework\TestCase
17+
/**
18+
* Test for Magento\Catalog\Model\Category\FileInfo class.
19+
*/
20+
class FileInfoTest extends TestCase
1621
{
1722
/**
18-
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
23+
* @var Filesystem|MockObject
1924
*/
2025
private $filesystem;
2126

2227
/**
23-
* @var Mime|\PHPUnit_Framework_MockObject_MockObject
28+
* @var Mime|MockObject
2429
*/
2530
private $mime;
2631

2732
/**
28-
* @var WriteInterface|\PHPUnit_Framework_MockObject_MockObject
33+
* @var WriteInterface|MockObject
2934
*/
3035
private $mediaDirectory;
3136

3237
/**
33-
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
38+
* @var ReadInterface|MockObject
3439
*/
3540
private $baseDirectory;
3641

42+
/**
43+
* @var ReadInterface|MockObject
44+
*/
45+
private $pubDirectory;
46+
3747
/**
3848
* @var FileInfo
3949
*/
@@ -44,30 +54,43 @@ protected function setUp()
4454
$this->mediaDirectory = $this->getMockBuilder(WriteInterface::class)
4555
->getMockForAbstractClass();
4656

47-
$this->baseDirectory = $this->getMockBuilder(ReadInterface::class)
57+
$this->baseDirectory = $baseDirectory = $this->getMockBuilder(ReadInterface::class)
58+
->getMockForAbstractClass();
59+
60+
$this->pubDirectory = $pubDirectory = $this->getMockBuilder(ReadInterface::class)
4861
->getMockForAbstractClass();
4962

5063
$this->filesystem = $this->getMockBuilder(Filesystem::class)
5164
->disableOriginalConstructor()
5265
->getMock();
53-
$this->filesystem->expects($this->any())
54-
->method('getDirectoryWrite')
66+
67+
$this->filesystem->method('getDirectoryWrite')
5568
->with(DirectoryList::MEDIA)
5669
->willReturn($this->mediaDirectory);
5770

58-
$this->filesystem->expects($this->any())
59-
->method('getDirectoryRead')
60-
->with(DirectoryList::ROOT)
61-
->willReturn($this->baseDirectory);
71+
$this->filesystem->method('getDirectoryRead')
72+
->willReturnCallback(
73+
function ($arg) use ($baseDirectory, $pubDirectory) {
74+
if ($arg === DirectoryList::PUB) {
75+
return $pubDirectory;
76+
}
77+
return $baseDirectory;
78+
}
79+
);
6280

6381
$this->mime = $this->getMockBuilder(Mime::class)
6482
->disableOriginalConstructor()
6583
->getMock();
6684

67-
$this->baseDirectory->expects($this->any())
68-
->method('getAbsolutePath')
69-
->with(null)
70-
->willReturn('/a/b/c');
85+
$this->baseDirectory->method('getAbsolutePath')
86+
->willReturn('/a/b/c/');
87+
88+
$this->baseDirectory->method('getRelativePath')
89+
->with('/a/b/c/pub/')
90+
->willReturn('pub/');
91+
92+
$this->pubDirectory->method('getAbsolutePath')
93+
->willReturn('/a/b/c/pub/');
7194

7295
$this->model = new FileInfo(
7396
$this->filesystem,
@@ -85,12 +108,12 @@ public function testGetMimeType()
85108
$this->mediaDirectory->expects($this->at(0))
86109
->method('getAbsolutePath')
87110
->with(null)
88-
->willReturn('/a/b/c/pub/media');
111+
->willReturn('/a/b/c/pub/media/');
89112

90113
$this->mediaDirectory->expects($this->at(1))
91114
->method('getAbsolutePath')
92115
->with(null)
93-
->willReturn('/a/b/c/pub/media');
116+
->willReturn('/a/b/c/pub/media/');
94117

95118
$this->mediaDirectory->expects($this->at(2))
96119
->method('getAbsolutePath')
@@ -113,13 +136,11 @@ public function testGetStat()
113136

114137
$expected = ['size' => 1];
115138

116-
$this->mediaDirectory->expects($this->any())
117-
->method('getAbsolutePath')
139+
$this->mediaDirectory->method('getAbsolutePath')
118140
->with(null)
119-
->willReturn('/a/b/c/pub/media');
141+
->willReturn('/a/b/c/pub/media/');
120142

121-
$this->mediaDirectory->expects($this->once())
122-
->method('stat')
143+
$this->mediaDirectory->method('stat')
123144
->with($mediaPath . $fileName)
124145
->willReturn($expected);
125146

@@ -130,22 +151,52 @@ public function testGetStat()
130151
$this->assertEquals(1, $result['size']);
131152
}
132153

133-
public function testIsExist()
154+
/**
155+
* @param $fileName
156+
* @param $fileMediaPath
157+
* @dataProvider isExistProvider
158+
*/
159+
public function testIsExist($fileName, $fileMediaPath)
134160
{
135-
$mediaPath = '/catalog/category';
161+
$this->mediaDirectory->method('getAbsolutePath')
162+
->willReturn('/a/b/c/pub/media/');
136163

137-
$fileName = '/filename.ext1';
138-
139-
$this->mediaDirectory->expects($this->any())
140-
->method('getAbsolutePath')
141-
->with(null)
142-
->willReturn('/a/b/c/pub/media');
143-
144-
$this->mediaDirectory->expects($this->once())
145-
->method('isExist')
146-
->with($mediaPath . $fileName)
164+
$this->mediaDirectory->method('isExist')
165+
->with($fileMediaPath)
147166
->willReturn(true);
148167

149168
$this->assertTrue($this->model->isExist($fileName));
150169
}
170+
171+
public function isExistProvider()
172+
{
173+
return [
174+
['/filename.ext1', '/catalog/category/filename.ext1'],
175+
['/pub/media/filename.ext1', 'filename.ext1'],
176+
['/media/filename.ext1', 'filename.ext1']
177+
];
178+
}
179+
180+
/**
181+
* @param $fileName
182+
* @param $expected
183+
* @dataProvider isBeginsWithMediaDirectoryPathProvider
184+
*/
185+
public function testIsBeginsWithMediaDirectoryPath($fileName, $expected)
186+
{
187+
$this->mediaDirectory->method('getAbsolutePath')
188+
->willReturn('/a/b/c/pub/media/');
189+
190+
$this->assertEquals($expected, $this->model->isBeginsWithMediaDirectoryPath($fileName));
191+
}
192+
193+
public function isBeginsWithMediaDirectoryPathProvider()
194+
{
195+
return [
196+
['/pub/media/test/filename.ext1', true],
197+
['/media/test/filename.ext1', true],
198+
['/test/filename.ext1', false],
199+
['test2/filename.ext1', false]
200+
];
201+
}
151202
}

app/code/Magento/Reports/Model/ResourceModel/Product/Sold/Collection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
use Magento\Framework\DB\Select;
1515

1616
/**
17+
* Data collection.
18+
*
1719
* @SuppressWarnings(PHPMD.DepthOfInheritance)
1820
* @api
1921
* @since 100.0.2
2022
*/
2123
class Collection extends \Magento\Reports\Model\ResourceModel\Order\Collection
2224
{
2325
/**
24-
* Set Date range to collection
26+
* Set Date range to collection.
2527
*
2628
* @param int $from
2729
* @param int $to
@@ -79,6 +81,10 @@ public function addOrderedQty($from = '', $to = '')
7981
)->having(
8082
'order_items.qty_ordered > ?',
8183
0
84+
)->columns(
85+
'SUM(order_items.qty_ordered) as ordered_qty'
86+
)->group(
87+
'order_items.product_id'
8288
);
8389
return $this;
8490
}
@@ -116,6 +122,8 @@ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
116122
}
117123

118124
/**
125+
* @inheritdoc
126+
*
119127
* @return Select
120128
* @since 100.2.0
121129
*/

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ define([
573573
applyCoupon : function(code){
574574
this.loadArea(['items', 'shipping_method', 'totals', 'billing_method'], true, {'order[coupon][code]':code, reset_shipping: 0});
575575
this.orderItemChanged = false;
576+
jQuery('html, body').animate({
577+
scrollTop: 0
578+
});
576579
},
577580

578581
addProduct : function(id){

0 commit comments

Comments
 (0)