Skip to content

Commit

Permalink
MAGETWO-87062: [EngCom Team] Batch 4. Forwardports to 2.3-develop #1285
Browse files Browse the repository at this point in the history
 - Merge Pull Request magento-engcom/magento2ce#1285 from magento-engcom-team/magento2:batch-4-forwardport-2.3-develop
 - Merged commits:
   1. ad6c0af
   2. 6d3d70a
   3. 6b0c02c
   4. c8abb13
   5. c6a9b5f
   6. c867b81
   7. 88a3ad0
   8. d87e316
   9. c76b04c
   10. 5ae2109
   11. 931133a
   12. 4c927a0
   13. 060a8f9
   14. 4da2a7d
   15. 008ef55
   16. d3642e8
   17. d37ce08
   18. b22b232
   19. 6c02a2d
   20. f2ec2ea
  • Loading branch information
Oleksii Korshenko committed Jan 23, 2018
2 parents 8e77e2f + f2ec2ea commit 4921802
Show file tree
Hide file tree
Showing 23 changed files with 448 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ define([

if (component) {
component.visible(visible);

/*eslint-disable max-depth */
if (_.isFunction(component.clear)) {
component.clear();
}
}
}
}, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
*/
public function isCategoryProperForGenerating(Category $category, $storeId)
{
if ($category->getParentId() != \Magento\Catalog\Model\Category::TREE_ROOT_ID) {
list(, $rootCategoryId) = $category->getParentIds();
$parentIds = $category->getParentIds();
if (count($parentIds) >= 2) {
$rootCategoryId = $parentIds[1];
return $rootCategoryId == $this->storeManager->getStore($storeId)->getRootCategoryId();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class ProductScopeRewriteGeneratorTest extends \PHPUnit\Framework\TestCase
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
private $serializer;

/** @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject */
private $categoryMock;

public function setUp()
{
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
Expand Down Expand Up @@ -83,6 +86,10 @@ function ($value) {
$this->storeViewService = $this->getMockBuilder(\Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class)
->disableOriginalConstructor()->getMock();
$this->storeManager = $this->createMock(StoreManagerInterface::class);
$storeRootCategoryId = 2;
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
$store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId));
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
$mergeDataProviderFactory = $this->createPartialMock(
\Magento\UrlRewrite\Model\MergeDataProviderFactory::class,
['create']
Expand All @@ -103,6 +110,7 @@ function ($value) {
'mergeDataProviderFactory' => $mergeDataProviderFactory
]
);
$this->categoryMock = $this->getMockBuilder(Category::class)->disableOriginalConstructor()->getMock();
}

public function testGenerationForGlobalScope()
Expand All @@ -112,12 +120,6 @@ public function testGenerationForGlobalScope()
$product->expects($this->any())->method('getStoreIds')->will($this->returnValue([1]));
$this->storeViewService->expects($this->once())->method('doesEntityHaveOverriddenUrlKeyForStore')
->will($this->returnValue(false));
$categoryMock = $this->getMockBuilder(Category::class)
->disableOriginalConstructor()
->getMock();
$categoryMock->expects($this->once())
->method('getParentId')
->willReturn(1);
$this->initObjectRegistryFactory([]);
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
$canonical->setRequestPath('category-1')
Expand Down Expand Up @@ -149,25 +151,21 @@ public function testGenerationForGlobalScope()
'category-3_3' => $current,
'category-4_4' => $anchorCategories
],
$this->productScopeGenerator->generateForGlobalScope([$categoryMock], $product, 1)
$this->productScopeGenerator->generateForGlobalScope([$this->categoryMock], $product, 1)
);
}

public function testGenerationForSpecificStore()
{
$storeRootCategoryId = 2;
$category_id = 4;
$product = $this->createMock(\Magento\Catalog\Model\Product::class);
$product->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
$product->expects($this->never())->method('getStoreIds');
$storeRootCategoryId = 'root-for-store-id';
$category = $this->createMock(\Magento\Catalog\Model\Category::class);
$category->expects($this->any())->method('getParentIds')
$this->categoryMock->expects($this->any())->method('getParentIds')
->will($this->returnValue(['root-id', $storeRootCategoryId]));
$category->expects($this->any())->method('getParentId')->will($this->returnValue('parent_id'));
$category->expects($this->any())->method('getId')->will($this->returnValue('category_id'));
$store = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
$store->expects($this->any())->method('getRootCategoryId')->will($this->returnValue($storeRootCategoryId));
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
$this->initObjectRegistryFactory([$category]);
$this->categoryMock->expects($this->any())->method('getId')->will($this->returnValue($category_id));
$this->initObjectRegistryFactory([$this->categoryMock]);
$canonical = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
$canonical->setRequestPath('category-1')
->setStoreId(1);
Expand All @@ -184,7 +182,7 @@ public function testGenerationForSpecificStore()

$this->assertEquals(
['category-1_1' => $canonical],
$this->productScopeGenerator->generateForSpecificStoreView(1, [$category], $product, 1)
$this->productScopeGenerator->generateForSpecificStoreView(1, [$this->categoryMock], $product, 1)
);
}

Expand Down Expand Up @@ -212,4 +210,40 @@ protected function initObjectRegistryFactory($entities)
->with(['entities' => $entities])
->will($this->returnValue($objectRegistry));
}

/**
* Test the possibility of url rewrite generation.
*
* @param array $parentIds
* @param bool $expectedResult
* @dataProvider isCategoryProperForGeneratingDataProvider
*/
public function testIsCategoryProperForGenerating($parentIds, $expectedResult)
{
$storeId = 1;
$this->categoryMock->expects(self::any())->method('getParentIds')->willReturn($parentIds);
$result = $this->productScopeGenerator->isCategoryProperForGenerating(
$this->categoryMock,
$storeId
);
self::assertEquals(
$expectedResult,
$result
);
}

/**
* Data provider for testIsCategoryProperForGenerating.
*
* @return array
*/
public function isCategoryProperForGeneratingDataProvider()
{
return [
[['0'], false],
[['1'], false],
[['1', '2'], true],
[['1', '3'], false],
];
}
}
6 changes: 6 additions & 0 deletions app/code/Magento/Customer/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/customers/resetPassword" method="POST">
<service class="Magento\Customer\Api\AccountManagementInterface" method="resetPassword"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/customers/:customerId/confirm" method="GET">
<service class="Magento\Customer\Api\AccountManagementInterface" method="getConfirmationStatus"/>
<resources>
Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/ImportExport/Helper/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Magento\ImportExport\Helper;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Stdlib\DateTime;
use Magento\ImportExport\Model\Import;

/**
Expand Down Expand Up @@ -127,4 +126,14 @@ protected function getFilePath($filename)
{
return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename);
}

/**
* Get csv delimiter from request.
*
* @return string
*/
public function getDelimiter()
{
return $this->_request->getParam(Import::FIELD_FIELD_SEPARATOR, ',');
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/ImportExport/Model/Report/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ protected function createSourceCsvModel($sourceFile)
return $this->sourceCsvFactory->create(
[
'file' => $sourceFile,
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR),
'delimiter' => $this->reportHelper->getDelimiter(),
]
);
}
Expand Down
25 changes: 25 additions & 0 deletions app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ class ReportTest extends \PHPUnit\Framework\TestCase
*/
protected $report;

/**
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
*/
private $requestMock;

/**
* Set up
*/
protected function setUp()
{
$this->context = $this->createMock(\Magento\Framework\App\Helper\Context::class);
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
->disableOriginalConstructor()
->getMock();
$this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
$this->timezone = $this->createPartialMock(
\Magento\Framework\Stdlib\DateTime\Timezone::class,
['date', 'getConfigTimezone', 'diff', 'format']
Expand Down Expand Up @@ -159,4 +168,20 @@ public function testGetReportSize()
$result = $this->report->getReportSize('file');
$this->assertNull($result);
}

/**
* Test getDelimiter() take into consideration request param '_import_field_separator'.
*/
public function testGetDelimiter()
{
$testDelimiter = 'some delimiter';
$this->requestMock->expects($this->once())
->method('getParam')
->with($this->identicalTo(\Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR))
->willReturn($testDelimiter);
$this->assertEquals(
$testDelimiter,
$this->report->getDelimiter()
);
}
}
14 changes: 13 additions & 1 deletion app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class CsvTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$testDelimiter = 'some_delimiter';

$this->reportHelperMock = $this->createMock(\Magento\ImportExport\Helper\Report::class);
$this->reportHelperMock->expects($this->any())->method('getDelimiter')->willReturn($testDelimiter);

$this->outputCsvFactoryMock = $this->createPartialMock(
\Magento\ImportExport\Model\Export\Adapter\CsvFactory::class,
Expand All @@ -65,7 +67,17 @@ protected function setUp()
[23 => 'first error'],
[27 => 'second error']
);
$this->sourceCsvFactoryMock->expects($this->any())->method('create')->willReturn($this->sourceCsvMock);
$this->sourceCsvFactoryMock
->expects($this->any())
->method('create')
->with(
[
'file' => 'some_file_name',
'directory' => null,
'delimiter' => $testDelimiter
]
)
->willReturn($this->sourceCsvMock);

$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);

Expand Down
10 changes: 8 additions & 2 deletions app/code/Magento/Sales/Model/Order/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ public function getStateDefaultStatus($state)
*/
public function getStatusLabel($code)
{
$code = $this->maskStatusForArea($this->state->getAreaCode(), $code);
$area = $this->state->getAreaCode();
$code = $this->maskStatusForArea($area, $code);
$status = $this->orderStatusFactory->create()->load($code);

if ($area == 'adminhtml') {
return $status->getLabel();
}

return $status->getStoreLabel();
}

Expand Down Expand Up @@ -211,7 +217,7 @@ public function getStateStatuses($state, $addLabels = true)
foreach ($collection as $item) {
$status = $item->getData('status');
if ($addLabels) {
$statuses[$status] = $item->getStoreLabel();
$statuses[$status] = $this->getStatusLabel($status);
} else {
$statuses[] = $status;
}
Expand Down
45 changes: 42 additions & 3 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,41 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
*/
protected $orderStatusCollectionFactoryMock;

/**
* @var \Magento\Sales\Model\Order\StatusFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $statusFactoryMock;

/**
* @var \Magento\Sales\Model\Order\Status
*/
protected $orderStatusModel;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManagerMock;

protected function setUp()
{
$orderStatusFactory = $this->createMock(\Magento\Sales\Model\Order\StatusFactory::class);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->orderStatusModel = $objectManager->getObject(\Magento\Sales\Model\Order\Status::class, [
'storeManager' => $this->storeManagerMock,
]);
$this->statusFactoryMock = $this->getMockBuilder(\Magento\Sales\Model\Order\StatusFactory::class)
->setMethods(['load', 'create'])
->getMock();
$this->orderStatusCollectionFactoryMock = $this->createPartialMock(
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class,
['create']
);
$this->salesConfig = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
$this->salesConfig = $objectManager
->getObject(
\Magento\Sales\Model\Order\Config::class,
[
'orderStatusFactory' => $orderStatusFactory,
'orderStatusFactory' => $this->statusFactoryMock,
'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock
]
);
Expand Down Expand Up @@ -147,6 +170,22 @@ public function testGetStatuses($state, $joinLabels, $collectionData, $expectedR
->method('joinStates')
->will($this->returnValue($collectionData));

$this->statusFactoryMock->method('create')
->willReturnSelf();

$this->statusFactoryMock->method('load')
->willReturn($this->orderStatusModel);

$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeMock->method('getId')
->willReturn(1);

$this->storeManagerMock->method('getStore')
->with($this->anything())
->willReturn($storeMock);

$this->orderStatusModel->setData('store_labels', [1 => 'Pending label']);

$result = $this->salesConfig->getStateStatuses($state, $joinLabels);
$this->assertSame($expectedResult, $result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// @codingStandardsIgnoreFile

/** @var \Magento\Sales\Block\Adminhtml\Order\View\History $block */
?>
<div id="order_history_block" class="edit-order-comments">
<?php if ($block->canAddComment()):?>
Expand Down
Loading

0 comments on commit 4921802

Please sign in to comment.