Skip to content

Commit 22e384c

Browse files
Merge branch '2.4-develop' into gl_pr_arrows_may16_2022
2 parents 33d090d + 645e14e commit 22e384c

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\Json\Helper\Data;
1616
use Psr\Log\LoggerInterface;
17+
use Magento\Framework\App\Action\HttpPostActionInterface;
1718

18-
class UpdateItemQty extends Action
19+
class UpdateItemQty extends Action implements HttpPostActionInterface
1920
{
2021
/**
2122
* @var Sidebar
@@ -61,12 +62,12 @@ public function __construct(
6162
}
6263

6364
/**
64-
* @return $this
65+
* @inheritdoc
6566
*/
6667
public function execute()
6768
{
6869
$itemId = (int)$this->getRequest()->getParam('item_id');
69-
$itemQty = $this->getRequest()->getParam('item_qty') * 1;
70+
$itemQty = (float)$this->getRequest()->getParam('item_qty') * 1;
7071
$itemQty = $this->quantityProcessor->prepareQuantity($itemQty);
7172

7273
try {

app/code/Magento/Checkout/Test/Unit/Controller/Sidebar/UpdateItemQtyTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,47 @@ public function testExecuteWithException(): void
244244

245245
$this->assertEquals('json represented', $this->updateItemQty->execute());
246246
}
247+
248+
/**
249+
* @return void
250+
*/
251+
public function testExecuteWithWrongRequestParams(): void
252+
{
253+
$this->requestMock
254+
->method('getParam')
255+
->withConsecutive(['item_id'], ['item_qty'])
256+
->willReturnOnConsecutiveCalls(0, 'error');
257+
258+
$this->sidebarMock->expects($this->once())
259+
->method('checkQuoteItem')
260+
->with(0)
261+
->willThrowException(new LocalizedException(__('Error!')));
262+
263+
$this->sidebarMock->expects($this->once())
264+
->method('getResponseData')
265+
->with('Error!')
266+
->willReturn(
267+
[
268+
'success' => false,
269+
'error_message' => 'Error!'
270+
]
271+
);
272+
273+
$this->jsonHelperMock->expects($this->once())
274+
->method('jsonEncode')
275+
->with(
276+
[
277+
'success' => false,
278+
'error_message' => 'Error!'
279+
]
280+
)
281+
->willReturn('json encoded');
282+
283+
$this->responseMock->expects($this->once())
284+
->method('representJson')
285+
->with('json encoded')
286+
->willReturn('json represented');
287+
288+
$this->assertEquals('json represented', $this->updateItemQty->execute());
289+
}
247290
}

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/Category/Plugin/StorageTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\App\ResourceConnection;
1616
use Magento\Framework\Exception\NoSuchEntityException;
1717
use Magento\Framework\Filesystem;
18+
use Magento\Framework\Filesystem\Directory\Write;
1819
use Magento\Framework\Filesystem\Driver\File;
1920
use Magento\Framework\ObjectManagerInterface;
2021
use Magento\ImportExport\Model\Import;
@@ -67,6 +68,9 @@ class StorageTest extends TestCase
6768
/** @var Data */
6869
private $importDataResource;
6970

71+
/** @var Write */
72+
private $mediaDirectory;
73+
7074
/**
7175
* @inheritdoc
7276
*/
@@ -85,6 +89,7 @@ protected function setUp(): void
8589
$this->importDataResource = $this->objectManager->get(Data::class);
8690
$this->appParams = Bootstrap::getInstance()->getBootstrap()->getApplication()
8791
->getInitParams()[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS];
92+
$this->mediaDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
8893
}
8994

9095
/**
@@ -182,17 +187,14 @@ private function prepareFile(string $fileName): Csv
182187
*/
183188
private function updateUploader(): void
184189
{
190+
$mediaDir = !$this->mediaDirectory->getDriver() instanceof File ?
191+
DirectoryList::MEDIA : $this->appParams[DirectoryList::MEDIA][DirectoryList::PATH];
192+
$destDir = $mediaDir . DIRECTORY_SEPARATOR . $this->mediaConfig->getBaseMediaPath();
193+
$tmpDir = $mediaDir . DIRECTORY_SEPARATOR . 'import';
194+
$this->mediaDirectory->create($this->mediaConfig->getBaseMediaPath());
195+
$this->mediaDirectory->create('import');
196+
$this->import->setParameters([Import::FIELD_NAME_IMG_FILE_DIR => $tmpDir]);
185197
$uploader = $this->import->getUploader();
186-
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
187-
$destDir = $rootDirectory->getRelativePath(
188-
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
189-
. DIRECTORY_SEPARATOR . $this->mediaConfig->getBaseMediaPath()
190-
);
191-
$tmpDir = $rootDirectory->getRelativePath(
192-
$this->appParams[DirectoryList::MEDIA][DirectoryList::PATH]
193-
);
194-
$rootDirectory->create($destDir);
195-
$rootDirectory->create($tmpDir);
196198
$uploader->setDestDir($destDir);
197199
$uploader->setTmpDir($tmpDir);
198200
}

0 commit comments

Comments
 (0)