Skip to content

Commit

Permalink
Merge branch '2.4-develop' into Refactoring-AdminCreateStoreViewTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Shikha Mishra committed Nov 18, 2021
2 parents 978dfcf + 0af0fba commit 1488797
Show file tree
Hide file tree
Showing 27 changed files with 396 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQ
$result->addData($this->checkQtyIncrements($stockItem, $qty)->getData());

$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
if (!$stockItem->getIsQtyDecimal() && (floor($qty) !== $qty)) {
if (!$stockItem->getIsQtyDecimal() && (floor($qty) !== (float) $qty)) {
$result->setHasError(true)
->setMessage(__('You cannot use decimal quantity for this product.'))
->setErrorCode('qty_decimal')
Expand Down
20 changes: 4 additions & 16 deletions app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class Storage extends \Magento\Framework\DataObject
protected $_coreFileStorageDb = null;

/**
* Cms wysiwyg images
*
* @var \Magento\Cms\Helper\Wysiwyg\Images
*/
protected $_cmsWysiwygImages = null;
Expand Down Expand Up @@ -109,36 +107,26 @@ class Storage extends \Magento\Framework\DataObject
protected $_session;

/**
* Directory database factory
*
* @var \Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory
*/
protected $_directoryDatabaseFactory;

/**
* Storage database factory
*
* @var \Magento\MediaStorage\Model\File\Storage\DatabaseFactory
*/
protected $_storageDatabaseFactory;

/**
* Storage file factory
*
* @var \Magento\MediaStorage\Model\File\Storage\FileFactory
*/
protected $_storageFileFactory;

/**
* Storage collection factory
*
* @var \Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory
*/
protected $_storageCollectionFactory;

/**
* Uploader factory
*
* @var \Magento\MediaStorage\Model\File\UploaderFactory
*/
protected $_uploaderFactory;
Expand Down Expand Up @@ -745,8 +733,8 @@ private function getResizedParams(string $source): array
$configWidth = $this->_resizeParameters['width'];
$configHeight = $this->_resizeParameters['height'];

//phpcs:ignore Generic.PHP.NoSilencedErrors
[$imageWidth, $imageHeight] = @getimagesize($source);
$driver = $this->_directory->getDriver();
[$imageWidth, $imageHeight] = getimagesizefromstring($driver->fileGetContents($source));

if ($imageWidth && $imageHeight) {
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
Expand Down Expand Up @@ -999,7 +987,7 @@ private function getAllowedPathPattern()
);
$regExp = '/^(';
$or = '';
foreach($mediaGalleryImageFolders as $folder) {
foreach ($mediaGalleryImageFolders as $folder) {
$folderPattern = str_replace('/', '[\/]+', $folder);
$regExp .= $or . $folderPattern . '\b(?!-)(?:\/?[a-zA-Z0-9\-\_]+)*\/?$';
$or = '|';
Expand All @@ -1013,7 +1001,7 @@ private function getAllowedPathPattern()
/**
* Get allowed media gallery image folders
*
* example:
* Example:
* [
* [0 => 'wysiwyg'],
* [0 => 'catalog', 1 => 'category']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class StorageTest extends TestCase
*/
private $fileMock;

/**
* @var array
*/
private $allowedImageExtensions = [
'jpg' => 'image/jpg',
'jpeg' => 'image/jpeg',
Expand Down Expand Up @@ -366,13 +369,13 @@ public function testGetDirsCollectionCreateSubDirectories()
}

/**
* @param array $exclude
* @param array $include
* @param array $fileNames
* @param array $expectedRemoveKeys
* @param $path
* @param $callNum
* @param string $dirsFilter
* @throws \Exception
* @dataProvider dirsCollectionDataProvider
*/
public function testGetDirsCollection($path, $callNum, $dirsFilter='')
public function testGetDirsCollection($path, $callNum, $dirsFilter = '')
{
$this->generalTestGetDirsCollection($path, $callNum, $dirsFilter);
}
Expand Down Expand Up @@ -517,6 +520,9 @@ public function testUploadFile()
[$thumbnailTargetPath, true],
]
);
$this->driverMock->expects(self::once())
->method('fileGetContents')
->willReturn('some content');

$image = $this->getMockBuilder(Image::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
class WriteFactory extends BaseWriteFactory
{
/**
* Object Manager
*
* @var ObjectManagerInterface
*/
private $objectManager;
Expand All @@ -32,19 +30,29 @@ class WriteFactory extends BaseWriteFactory
*/
private $driverPool;

/**
* Deny List Validator
*
* @var DenyListPathValidator
*/
private $denyListPathValidator;

/**
* WriteFactory constructor.
*
* @param ObjectManagerInterface $objectManager
* @param BaseDriverPool $driverPool
* @param DenyListPathValidator|null $denyListPathValidator
*/
public function __construct(
ObjectManagerInterface $objectManager,
BaseDriverPool $driverPool
BaseDriverPool $driverPool,
?DenyListPathValidator $denyListPathValidator = null
) {
$this->objectManager = $objectManager;
$this->driverPool = $driverPool;
parent::__construct($driverPool);
$this->denyListPathValidator = $denyListPathValidator;
parent::__construct($driverPool, $denyListPathValidator);
}

/**
Expand All @@ -64,7 +72,7 @@ public function create(

$validators = [
'pathValidator' => new PathValidator($driver),
'denyListPathValidator' => new DenyListPathValidator($driver)
'denyListPathValidator' => $this->denyListPathValidator ?: new DenyListPathValidator($driver)
];

$pathValidator = new CompositePathValidator($validators);
Expand All @@ -82,6 +90,5 @@ public function create(
} else {
return parent::create($path, $driverCode, $createPermissions);
}

}
}
15 changes: 15 additions & 0 deletions app/code/Magento/Sales/Model/Order/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,21 @@ public function setCcLast4($ccLast4)
return $this->setData(OrderPaymentInterface::CC_LAST_4, $ccLast4);
}

/**
* @inheritDoc
*
* Because cc_last_4 data attribute violates data contract (use underscore (_) between alphanumerical characters),
* this ad hoc method is for setting cc_last_4 data value in \Magento\Framework\Api\DataObjectHelper::_setDataValues
*/
public function setCustomAttribute($attributeCode, $attributeValue)
{
if ($attributeCode === OrderPaymentInterface::CC_LAST_4) {
return parent::setData(OrderPaymentInterface::CC_LAST_4, $attributeValue);
}

return parent::setCustomAttribute($attributeCode, $attributeValue);
}

/**
* @inheritdoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function testNoAuthorizedServices()
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$responseContent = curl_exec($connection);
$this->assertEquals(curl_getinfo($connection, CURLINFO_HTTP_CODE), 401);
$this->assertStringContainsString("The consumer isn't authorized to access %resources.", $responseContent);
$this->assertStringContainsString(
"The consumer isn't authorized to access %resources.",
htmlspecialchars_decode($responseContent, ENT_QUOTES)
);
}

public function testInvalidWsdlUrlNoServices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

namespace Magento\AdvancedPricingImportExport\Model\Export;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\File\Csv;
use Magento\TestFramework\Indexer\TestCase;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Filesystem;
use Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing as ExportAdvancedPricing;
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\Write;
use Magento\ImportExport\Model\Export\Adapter\Csv as ExportAdapterCsv;
use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing as ImportAdvancedPricing;
use Magento\ImportExport\Model\Import\Source\Csv as ImportSourceCsv;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\Import\Source\Csv as ImportSourceCsv;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Indexer\TestCase;

/**
* Test for \Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing
Expand All @@ -41,6 +41,11 @@ class AdvancedPricingTest extends TestCase
*/
protected $fileSystem;

/**
* @var Write
*/
private $directory;

// @codingStandardsIgnoreStart
public static function setUpBeforeClass(): void
{
Expand All @@ -64,6 +69,7 @@ protected function setUp(): void

$this->objectManager = Bootstrap::getObjectManager();
$this->fileSystem = $this->objectManager->get(Filesystem::class);
$this->directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
$this->model = $this->objectManager->create(ExportAdvancedPricing::class);
}

Expand Down Expand Up @@ -179,7 +185,7 @@ public function testExportImportOfAdvancedPricing(): void
{
$simpleSku = 'simple';
$secondSimpleSku = 'second_simple';
$csvfile = uniqid('importexport_') . '.csv';
$csvfile = $this->directory->getAbsolutePath(uniqid('importexport_') . '.csv');
$exportContent = $this->exportData($csvfile);
$this->assertStringContainsString(
\sprintf('%s,"All Websites [USD]","ALL GROUPS",10.0000,3.00,Discount', $secondSimpleSku),
Expand Down Expand Up @@ -269,10 +275,7 @@ private function updateTierPriceDataInCsv(string $csvfile): void
],
];

/** @var Csv $csv */
$csv = $this->objectManager->get(Csv::class);
$varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$csv->appendData($varDirectory->getAbsolutePath($csvfile), $csvNewData);
$this->updateCsvFile($csvfile, $csvNewData);
}

/**
Expand All @@ -281,16 +284,15 @@ private function updateTierPriceDataInCsv(string $csvfile): void
*/
private function exportData($csvFile)
{
$this->model->setWriter(
Bootstrap::getObjectManager()
->create(
ExportAdapterCsv::class,
['fileSystem' => $this->fileSystem, 'destination' => $csvFile]
)
);
$writer = Bootstrap::getObjectManager()->create(ExportAdapterCsv::class, ['fileSystem' => $this->fileSystem]);

$this->model->setWriter($writer);
$exportContent = $this->model->export();
$this->assertNotEmpty($exportContent);

$driver = $this->directory->getDriver();
$driver->filePutContents($this->directory->getAbsolutePath($csvFile), $exportContent);

return $exportContent;
}

Expand All @@ -301,12 +303,11 @@ private function importData($csvFile)
{
/** @var ImportAdvancedPricing $importModel */
$importModel = $this->objectManager->create(ImportAdvancedPricing::class);
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$source = $this->objectManager->create(
ImportSourceCsv::class,
[
'file' => $csvFile,
'directory' => $directory
'directory' => $this->directory
]
);
$errors = $importModel->setParameters(
Expand Down Expand Up @@ -366,4 +367,24 @@ private function removeImportedProducts(array $skus): void
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
}

/**
* Appends csv data to the file
*
* @param string $filePath
* @param array $csv
* @return void
*/
private function updateCsvFile(string $filePath, array $csv): void
{
$driver = $this->directory->getDriver();
$driver->deleteFile($filePath);
$fileResource = $driver->fileOpen($filePath, 'w');

foreach ($csv as $dataRow) {
$driver->filePutCsv($fileResource, $dataRow);
}

$driver->fileClose($fileResource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function testImportDelete()
$index = 0;
$ids = [];
$origPricingData = [];
$skus = ['simple'];
while (isset($skus[$index])) {
$ids[$index] = $productRepository->get($skus[$index])->getId();
$origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
Expand All @@ -192,12 +193,16 @@ public function testImportDelete()
$exportModel->setWriter(
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\ImportExport\Model\Export\Adapter\Csv::class,
['fileSystem' => $this->fileSystem, 'destination' => $csvfile]
['fileSystem' => $this->fileSystem]
)
);
$this->assertNotEmpty($exportModel->export());
$exportContent = $exportModel->export();
$this->assertNotEmpty($exportContent);

$errors = $this->doImport($csvfile, DirectoryList::VAR_DIR, Import::BEHAVIOR_DELETE, true);
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
$directory->getDriver()->filePutContents($directory->getAbsolutePath($csvfile), $exportContent);

$errors = $this->doImport($csvfile, DirectoryList::VAR_IMPORT_EXPORT, Import::BEHAVIOR_DELETE, true);

$this->assertTrue(
$errors->getErrorsCount() == 0,
Expand Down
Loading

0 comments on commit 1488797

Please sign in to comment.