Skip to content

Commit

Permalink
Merge pull request #5585 from magento-tsg/2.4-develop-com-pr11
Browse files Browse the repository at this point in the history
[TSG-Commerce] Tests for 2.4 (pr11)
  • Loading branch information
zakdma authored Apr 15, 2020
2 parents 985c679 + 768b7fc commit ea7af78
Show file tree
Hide file tree
Showing 33 changed files with 2,585 additions and 274 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestFramework\Downloadable\Model;

use Magento\Downloadable\Model\ResourceModel\Link\Purchased as PurchasedResource;
use Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory;

/**
* Delete records from downloadable_link_purchased associated with provided order
*/
class RemoveLinkPurchasedByOrderIncrementId
{
/** @var CollectionFactory */
private $linkCollectionFactory;

/** @var PurchasedResource */
private $purchasedResource;

/**
* @param CollectionFactory $linkCollectionFactory
* @param PurchasedResource $purchasedResource
*/
public function __construct(CollectionFactory $linkCollectionFactory, PurchasedResource $purchasedResource)
{
$this->linkCollectionFactory = $linkCollectionFactory;
$this->purchasedResource = $purchasedResource;
}

/**
* Remove records from downloadable_link_purchased related to provided order
*
* @param string $orderIncrementId
* @return void
*/
public function execute(string $orderIncrementId): void
{
$collection = $this->linkCollectionFactory->create();
$collection->addFieldToFilter('order_increment_id', $orderIncrementId);
foreach ($collection as $item) {
$this->purchasedResource->delete($item);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ protected function setUp()
/**
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
* @magentoDbIsolation enabled
*
* @return void
*/
public function testExport()
public function testExport(): void
{
$this->model->setWriter(
$this->objectManager->create(
Expand All @@ -109,8 +111,10 @@ public function testExport()
/**
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php
* @magentoDbIsolation enabled
*
* @return void
*/
public function testExportSpecialChars()
public function testExportSpecialChars(): void
{
$this->model->setWriter(
$this->objectManager->create(
Expand All @@ -125,8 +129,10 @@ public function testExportSpecialChars()
/**
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_product_links_data.php
* @magentoDbIsolation enabled
*
* @return void
*/
public function testExportWithProductLinks()
public function testExportWithProductLinks(): void
{
$this->model->setWriter(
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
Expand All @@ -143,8 +149,10 @@ public function testExportWithProductLinks()
* @magentoDbIsolation enabled
* @covers \Magento\CatalogImportExport\Model\Export\Product::export
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
*
* @return void
*/
public function testExportStockItemAttributesAreFilled()
public function testExportStockItemAttributesAreFilled(): void
{
$this->markTestSkipped('Test needs to be skipped.');
$fileWrite = $this->createMock(\Magento\Framework\Filesystem\File\Write::class);
Expand Down Expand Up @@ -176,8 +184,9 @@ public function testExportStockItemAttributesAreFilled()
* Verify header columns (that stock item attributes column headers are present)
*
* @param array $headerColumns
* @return void
*/
public function verifyHeaderColumns(array $headerColumns)
public function verifyHeaderColumns(array $headerColumns): void
{
foreach (self::$stockItemAttributes as $stockItemAttribute) {
$this->assertContains(
Expand All @@ -192,8 +201,9 @@ public function verifyHeaderColumns(array $headerColumns)
* Verify row data (stock item attribute values)
*
* @param array $rowData
* @return void
*/
public function verifyRow(array $rowData)
public function verifyRow(array $rowData): void
{
foreach (self::$stockItemAttributes as $stockItemAttribute) {
$this->assertNotSame(
Expand All @@ -208,8 +218,10 @@ public function verifyRow(array $rowData)
* Verifies if exception processing works properly
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
*
* @return void
*/
public function testExceptionInGetExportData()
public function testExceptionInGetExportData(): void
{
$this->markTestSkipped('Test needs to be skipped.');
$exception = new \Exception('Error');
Expand Down Expand Up @@ -258,8 +270,10 @@ public function testExceptionInGetExportData()
* Verify if fields wrapping works correct when "Fields Enclosure" option enabled
*
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
*
* @return void
*/
public function testExportWithFieldsEnclosure()
public function testExportWithFieldsEnclosure(): void
{
$this->model->setParameters(
[
Expand All @@ -284,8 +298,10 @@ public function testExportWithFieldsEnclosure()
* Verify that "category ids" filter correctly applies to export result
*
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_categories.php
*
* @return void
*/
public function testCategoryIdsFilter()
public function testCategoryIdsFilter(): void
{
$this->model->setWriter(
$this->objectManager->create(
Expand Down Expand Up @@ -313,8 +329,10 @@ public function testCategoryIdsFilter()
* Verify that export processed successfully with wrong category path
*
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_broken_categories_path.php
*
* @return void
*/
public function testExportWithWrongCategoryPath()
public function testExportWithWrongCategoryPath(): void
{
$this->model->setWriter(
$this->objectManager->create(
Expand All @@ -329,8 +347,10 @@ public function testExportWithWrongCategoryPath()
* Test 'hide from product page' export for non-default store.
*
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_images.php
*
* @return void
*/
public function testExportWithMedia()
public function testExportWithMedia(): void
{
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
Expand Down Expand Up @@ -359,6 +379,7 @@ public function testExportWithMedia()

/**
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
*
* @return void
*/
public function testExportWithCustomOptions(): void
Expand Down Expand Up @@ -403,12 +424,19 @@ public function testExportWithCustomOptions(): void
/** @var \Magento\Framework\File\Csv $csv */
$csv = $this->objectManager->get(\Magento\Framework\File\Csv::class);
$data = $csv->getData($varDirectory->getAbsolutePath('test_product_with_custom_options_and_second_store.csv'));
$keys = array_shift($data);
$products = [];
foreach ($data as $productData) {
$products[] = array_combine($keys, $productData);
}
$products = array_filter($products, function (array $product) {
return $product['sku'] === 'simple';
});
$customOptionData = [];
foreach ($data[0] as $columnNumber => $columnName) {
if ($columnName === 'custom_options') {
$customOptionData['admin_store'] = $this->parseExportedCustomOption($data[1][$columnNumber]);
$customOptionData[$storeCode] = $this->parseExportedCustomOption($data[2][$columnNumber]);
}

foreach ($products as $product) {
$storeCode = $product['store_view_code'] ?: 'admin_store';
$customOptionData[$storeCode] = $this->parseExportedCustomOption($product['custom_options']);
}

self::assertSame($expectedData, $customOptionData);
Expand All @@ -418,8 +446,10 @@ public function testExportWithCustomOptions(): void
* Check that no duplicate entities when multiple custom options used
*
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_options.php
*
* @return void
*/
public function testExportWithMultipleOptions()
public function testExportWithMultipleOptions(): void
{
$expectedCount = 1;
$resultsFilename = 'export_results.csv';
Expand All @@ -442,6 +472,8 @@ public function testExportWithMultipleOptions()
}

/**
* Parse exported custom options
*
* @param string $exportedCustomOption
* @return array
*/
Expand Down Expand Up @@ -476,8 +508,10 @@ function ($input) {
* @magentoConfigFixture current_store catalog/price/scope 1
* @magentoDbIsolation disabled
* @magentoAppArea adminhtml
*
* @return void
*/
public function testExportProductWithTwoWebsites()
public function testExportProductWithTwoWebsites(): void
{
$globalStoreCode = 'admin';
$secondStoreCode = 'fixture_second_store';
Expand Down Expand Up @@ -539,17 +573,19 @@ public function testExportProductWithTwoWebsites()
/**
* Verify that "stock status" filter correctly applies to export result
*
* @magentoDataFixture Magento/Catalog/_files/multiple_products_with_few_out_of_stock.php
* @dataProvider filterByQuantityAndStockStatusDataProvider
*
* @param string $value
* @param array $productsIncluded
* @param array $productsNotIncluded
* @magentoDataFixture Magento/Catalog/_files/multiple_products_with_few_out_of_stock.php
* @dataProvider filterByQuantityAndStockStatusDataProvider
* @return void
*/
public function testFilterByQuantityAndStockStatus(
string $value,
array $productsIncluded,
array $productsNotIncluded
) {
): void {
$exportData = $this->doExport(['quantity_and_stock_status' => $value]);
foreach ($productsIncluded as $productName) {
$this->assertContains($productName, $exportData);
Expand All @@ -569,35 +605,37 @@ public function filterByQuantityAndStockStatusDataProvider(): array
[
'Simple Product OOS',
'Simple Product Not Visible',
'Simple Product Visible and InStock'
'Simple Product Visible and InStock',
],
[
]
],
],
[
'1',
[
'Simple Product Not Visible',
'Simple Product Visible and InStock'
'Simple Product Visible and InStock',
],
[
'Simple Product OOS'
]
'Simple Product OOS',
],
],
[
'0',
[
'Simple Product OOS'
'Simple Product OOS',
],
[
'Simple Product Not Visible',
'Simple Product Visible and InStock'
]
]
'Simple Product Visible and InStock',
],
],
];
}

/**
* Perform export
*
* @param array $filters
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@

$productModel->setTypeId(
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
)->setId(
1
)->setAttributeSetId(
4
)->setName(
Expand Down
Loading

0 comments on commit ea7af78

Please sign in to comment.