Skip to content

Commit dc3fa2d

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-pr24
2 parents 24093ec + ec81173 commit dc3fa2d

File tree

6 files changed

+214
-5
lines changed

6 files changed

+214
-5
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Catalog\Model\ResourceModel\Category;
8+
9+
/**
10+
* Factory class for state dependent category collection
11+
*/
12+
class StateDependentCollectionFactory
13+
{
14+
/**
15+
* Object Manager instance
16+
*
17+
* @var \Magento\Framework\ObjectManagerInterface
18+
*/
19+
private $objectManager;
20+
21+
/**
22+
* Catalog category flat state
23+
*
24+
* @var \Magento\Catalog\Model\Indexer\Category\Flat\State
25+
*/
26+
private $catalogCategoryFlatState;
27+
28+
/**
29+
* Factory constructor
30+
*
31+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
32+
* @param \Magento\Catalog\Model\Indexer\Category\Flat\State $catalogCategoryFlatState
33+
*/
34+
public function __construct(
35+
\Magento\Framework\ObjectManagerInterface $objectManager,
36+
\Magento\Catalog\Model\Indexer\Category\Flat\State $catalogCategoryFlatState
37+
) {
38+
$this->objectManager = $objectManager;
39+
$this->catalogCategoryFlatState = $catalogCategoryFlatState;
40+
}
41+
42+
/**
43+
* Create class instance with specified parameters
44+
*
45+
* @param array $data
46+
* @return \Magento\Framework\Data\Collection\AbstractDb
47+
*/
48+
public function create(array $data = [])
49+
{
50+
return $this->objectManager->create(
51+
($this->catalogCategoryFlatState->isAvailable()) ? Flat\Collection::class : Collection::class,
52+
$data
53+
);
54+
}
55+
}

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Topmenu
2222
protected $catalogCategory;
2323

2424
/**
25-
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
25+
* @var \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory
2626
*/
2727
private $collectionFactory;
2828

@@ -40,13 +40,13 @@ class Topmenu
4040
* Initialize dependencies.
4141
*
4242
* @param \Magento\Catalog\Helper\Category $catalogCategory
43-
* @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
43+
* @param \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory
4444
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4545
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
4646
*/
4747
public function __construct(
4848
\Magento\Catalog\Helper\Category $catalogCategory,
49-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
49+
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
5050
\Magento\Store\Model\StoreManagerInterface $storeManager,
5151
\Magento\Catalog\Model\Layer\Resolver $layerResolver
5252
) {

app/code/Magento/Catalog/Test/Unit/Plugin/Block/TopmenuTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function setUp()
8787
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
8888
);
8989
$this->categoryCollectionFactoryMock = $this->createPartialMock(
90-
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory::class,
90+
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory::class,
9191
['create']
9292
);
9393

app/code/Magento/Deploy/Service/DeployStaticFile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public function deployFile($fileName, array $params = [])
8585
{
8686
$params['publish'] = true;
8787
$asset = $this->assetRepo->createAsset($this->resolveFile($fileName), $params);
88+
if (isset($params['replace'])) {
89+
$this->deleteFile($asset->getPath());
90+
}
8891

8992
$this->assetPublisher->publish($asset);
9093

app/code/Magento/Deploy/Service/DeployTranslationsDictionary.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public function deploy($area, $theme, $locale)
6868
'fileName' => $this->jsTranslationConfig->getDictionaryFileName(),
6969
'area' => $area,
7070
'theme' => $theme,
71-
'locale' => $locale
71+
'locale' => $locale,
72+
'replace' => true
7273
]
7374
);
7475
});
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Deploy\Test\Unit\Service;
9+
10+
use Magento\Deploy\Service\DeployStaticFile;
11+
use Magento\Framework\View\Asset\Repository;
12+
use Magento\Framework\View\Asset\Minification;
13+
use Magento\Framework\View\Asset\File;
14+
use Magento\Framework\View\Asset\PreProcessor\FileNameResolver;
15+
use Magento\Framework\App\View\Asset\Publisher;
16+
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Filesystem\DriverInterface;
18+
use Magento\Framework\Filesystem\Directory\WriteInterface;
19+
use PHPUnit_Framework_MockObject_MockObject as Mock;
20+
use PHPUnit_Framework_MockObject_Matcher_InvokedCount as InvokedCount;
21+
22+
class DeployStaticFileTest extends \PHPUnit\Framework\TestCase
23+
{
24+
/**
25+
* @var DeployStaticFile
26+
*/
27+
private $service;
28+
29+
/**
30+
* @var FileNameResolver | Mock
31+
*/
32+
private $fileNameResolver;
33+
34+
/**
35+
* @var Repository | Mock
36+
*/
37+
private $assetRepo;
38+
39+
/**
40+
* @var Publisher | Mock
41+
*/
42+
private $assetPublisher;
43+
44+
/**
45+
* @var Filesystem | Mock
46+
*/
47+
private $filesystem;
48+
49+
/**
50+
* @var Minification | Mock
51+
*/
52+
private $minification;
53+
54+
/**
55+
* @var DriverInterface | Mock
56+
*/
57+
private $fsDriver;
58+
59+
protected function setUp()
60+
{
61+
$this->fileNameResolver = $this->createPartialMock(FileNameResolver::class, ['resolve']);
62+
$this->assetRepo = $this->createPartialMock(Repository::class, ['createAsset']);
63+
$this->assetPublisher = $this->createPartialMock(Publisher::class, ['publish']);
64+
$this->filesystem = $this->createPartialMock(Filesystem::class, ['getDirectoryWrite']);
65+
$this->minification = $this->createMock(Minification::class);
66+
$this->fsDriver = $this->getMockForAbstractClass(DriverInterface::class);
67+
68+
$directory = $this->createMock(WriteInterface::class);
69+
70+
$directory->method('isExist')
71+
->willReturn(true);
72+
73+
$directory->method('getAbsolutePath')
74+
->willReturn('path');
75+
76+
$directory->method('getDriver')
77+
->willReturn($this->fsDriver);
78+
79+
$this->filesystem
80+
->method('getDirectoryWrite')
81+
->willReturn($directory);
82+
83+
$this->service = new DeployStaticFile(
84+
$this->filesystem,
85+
$this->assetRepo,
86+
$this->assetPublisher,
87+
$this->fileNameResolver,
88+
$this->minification
89+
);
90+
}
91+
92+
/**
93+
* @param string $fileName
94+
* @param array $params
95+
* @param InvokedCount $callDelete
96+
* @dataProvider deployFileDataProvider
97+
*/
98+
public function testDeployFile($fileName, array $params, InvokedCount $callDelete)
99+
{
100+
$file = $this->createMock(File::class);
101+
$file->method('getPath')
102+
->willReturn($fileName);
103+
104+
$this->fileNameResolver
105+
->method('resolve')
106+
->with($fileName)
107+
->willReturn($fileName);
108+
109+
$this->assetRepo
110+
->method('createAsset')
111+
->willReturn($file);
112+
113+
$this->fsDriver
114+
->method('isFile')
115+
->with('path')
116+
->willReturn(true);
117+
118+
$this->fsDriver
119+
->expects($callDelete)
120+
->method('deleteFile');
121+
122+
$this->service->deployFile($fileName, $params);
123+
}
124+
125+
/**
126+
* List of options for the file deploy.
127+
*
128+
* @return array
129+
*/
130+
public function deployFileDataProvider(): array
131+
{
132+
return [
133+
[
134+
'file1',
135+
['replace' => 'any value',],
136+
self::once()
137+
],
138+
[
139+
'file1',
140+
['replace' => false,],
141+
self::once()
142+
],
143+
[
144+
'file1',
145+
[],
146+
self::never()
147+
],
148+
];
149+
}
150+
}

0 commit comments

Comments
 (0)