Skip to content

Commit 87c34a1

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-prs
- merged with '2.4-develop-fast-lane-prs' branch
2 parents 6382421 + 286a05f commit 87c34a1

File tree

9 files changed

+81
-45
lines changed

9 files changed

+81
-45
lines changed

app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CmsUrlRewrite\Plugin\Cms\Model\Store;
99

10+
use Magento\Cms\Api\Data\PageInterface;
1011
use Magento\Cms\Api\PageRepositoryInterface;
1112
use Magento\CmsUrlRewrite\Model\CmsPageUrlRewriteGenerator;
1213
use Magento\Framework\Api\SearchCriteriaBuilder;
@@ -21,6 +22,8 @@
2122
*/
2223
class View
2324
{
25+
private const ALL_STORE_VIEWS = '0';
26+
2427
/**
2528
* @var UrlPersistInterface
2629
*/
@@ -89,14 +92,27 @@ private function generateCmsPagesUrls(int $storeId): array
8992
{
9093
$rewrites = [];
9194
$urls = [];
92-
$searchCriteria = $this->searchCriteriaBuilder->create();
93-
$cmsPagesCollection = $this->pageRepository->getList($searchCriteria)->getItems();
94-
foreach ($cmsPagesCollection as $page) {
95+
96+
foreach ($this->getCmsPageItems() as $page) {
9597
$page->setStoreId($storeId);
9698
$rewrites[] = $this->cmsPageUrlRewriteGenerator->generate($page);
9799
}
98100
$urls = array_merge($urls, ...$rewrites);
99101

100102
return $urls;
101103
}
104+
105+
/**
106+
* Return cms page items for all store view
107+
*
108+
* @return PageInterface[]
109+
*/
110+
private function getCmsPageItems(): array
111+
{
112+
$searchCriteria = $this->searchCriteriaBuilder->addFilter('store_id', self::ALL_STORE_VIEWS)
113+
->create();
114+
$list = $this->pageRepository->getList($searchCriteria);
115+
116+
return $list->getItems();
117+
}
102118
}

app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public function destruct()
5454
{
5555
if (is_object($this->_fileHandler)) {
5656
$this->_fileHandler->close();
57+
$this->resolveDestination();
58+
}
59+
}
60+
61+
/**
62+
* Remove temporary destination
63+
*
64+
* @return void
65+
*/
66+
private function resolveDestination(): void
67+
{
68+
// only temporary file located directly in var folder
69+
if (strpos($this->_destination, '/') === false) {
5770
$this->_directoryHandle->delete($this->_destination);
5871
}
5972
}

app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ public function draw()
8080
$lines = [];
8181

8282
// draw Product name
83-
$lines[0] = [
84-
[
83+
$lines[0][] = [
8584
'text' => $this->string->split($this->prepareText((string)$item->getName()), 35, true, true),
8685
'feed' => 35
87-
]
8886
];
8987

9088
// draw SKU

app/code/Magento/Store/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<preference for="Magento\Framework\App\Router\PathConfigInterface" type="Magento\Store\Model\PathConfig" />
6666
<type name="Magento\Framework\App\ActionInterface">
6767
<plugin name="storeCheck" type="Magento\Store\App\Action\Plugin\StoreCheck"/>
68-
<plugin name="designLoader" type="Magento\Framework\App\Action\Plugin\LoadDesignPlugin"/>
6968
<plugin name="eventDispatch" type="Magento\Framework\App\Action\Plugin\EventDispatchPlugin"/>
7069
<plugin name="actionFlagNoDispatch" type="Magento\Framework\App\Action\Plugin\ActionFlagNoDispatchPlugin"/>
7170
</type>

lib/internal/Magento/Framework/App/Action/Plugin/LoadDesignPlugin.php renamed to app/code/Magento/Theme/Plugin/LoadDesignPlugin.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\Action\Plugin;
7+
namespace Magento\Theme\Plugin;
88

99
use Magento\Framework\App\ActionInterface;
1010
use Magento\Framework\Config\Dom\ValidationException;
@@ -21,12 +21,12 @@ class LoadDesignPlugin
2121
/**
2222
* @var DesignLoader
2323
*/
24-
protected $_designLoader;
24+
private $designLoader;
2525

2626
/**
2727
* @var MessageManagerInterface
2828
*/
29-
protected $messageManager;
29+
private $messageManager;
3030

3131
/**
3232
* @param DesignLoader $designLoader
@@ -36,7 +36,7 @@ public function __construct(
3636
DesignLoader $designLoader,
3737
MessageManagerInterface $messageManager
3838
) {
39-
$this->_designLoader = $designLoader;
39+
$this->designLoader = $designLoader;
4040
$this->messageManager = $messageManager;
4141
}
4242

@@ -50,7 +50,7 @@ public function __construct(
5050
public function beforeExecute(ActionInterface $subject)
5151
{
5252
try {
53-
$this->_designLoader->load();
53+
$this->designLoader->load();
5454
} catch (LocalizedException $e) {
5555
if ($e->getPrevious() instanceof ValidationException) {
5656
/** @var MessageInterface $message */
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
7-
8-
namespace Magento\Framework\App\Test\Unit\Action\Plugin;
6+
namespace Magento\Theme\Test\Unit\Plugin;
97

108
use Magento\Framework\App\Action\Action;
11-
use Magento\Framework\App\Action\Plugin\LoadDesignPlugin;
129
use Magento\Framework\App\ActionInterface;
1310
use Magento\Framework\Message\ManagerInterface;
1411
use Magento\Framework\View\DesignLoader;
12+
use Magento\Theme\Plugin\LoadDesignPlugin;
1513
use PHPUnit\Framework\MockObject\MockObject;
1614
use PHPUnit\Framework\TestCase;
1715

@@ -26,7 +24,7 @@ public function testBeforeExecute()
2624
$designLoaderMock = $this->createMock(DesignLoader::class);
2725

2826
/** @var MockObject|ManagerInterface $messageManagerMock */
29-
$messageManagerMock = $this->getMockForAbstractClass(ManagerInterface::class);
27+
$messageManagerMock = $this->createMock(ManagerInterface::class);
3028

3129
$plugin = new LoadDesignPlugin($designLoaderMock, $messageManagerMock);
3230

app/code/Magento/Theme/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@
105105
<argument name="scope" xsi:type="const">Magento\Store\Model\ScopeInterface::SCOPE_STORE</argument>
106106
</arguments>
107107
</virtualType>
108+
<type name="Magento\Framework\App\ActionInterface">
109+
<plugin name="designLoader" type="Magento\Theme\Plugin\LoadDesignPlugin"/>
110+
</type>
108111
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
109112
<arguments>
110113
<argument name="collections" xsi:type="array">

dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use PHPUnit\Framework\TestCase;
2626

2727
/**
28-
* Test for plugin which is listening store resource model and on save replace cms page url rewrites
28+
* Test for plugin which is listening store resource model and on save replace cms page url rewrites.
2929
*
3030
* @magentoAppArea adminhtml
3131
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -84,9 +84,10 @@ protected function setUp(): void
8484
/**
8585
* Test of replacing cms page url rewrites on create and delete store
8686
*
87+
* @magentoDataFixture Magento/Cms/_files/two_cms_page_with_same_url_for_different_stores.php
8788
* @magentoDataFixture Magento/Cms/_files/pages.php
8889
*/
89-
public function testUrlRewritesChangesAfterStoreSave()
90+
public function testUrlRewritesChangesAfterStoreSave(): void
9091
{
9192
$storeId = $this->createStore();
9293
$this->assertUrlRewritesCount($storeId, 'page100', 1);
@@ -98,16 +99,16 @@ public function testUrlRewritesChangesAfterStoreSave()
9899
}
99100

100101
/**
101-
* Assert url rewrites count by store id
102+
* Assert url rewrites count by store id and request path
102103
*
103104
* @param int $storeId
104-
* @param string $pageIdentifier
105+
* @param string $requestPath
105106
* @param int $expectedCount
106107
*/
107-
private function assertUrlRewritesCount(int $storeId, string $pageIdentifier, int $expectedCount): void
108+
private function assertUrlRewritesCount(int $storeId, string $requestPath, int $expectedCount): void
108109
{
109110
$data = [
110-
UrlRewrite::REQUEST_PATH => $pageIdentifier,
111+
UrlRewrite::REQUEST_PATH => $requestPath,
111112
UrlRewrite::STORE_ID => $storeId
112113
];
113114
$urlRewrites = $this->urlFinder->findAllByData($data);
@@ -116,8 +117,6 @@ private function assertUrlRewritesCount(int $storeId, string $pageIdentifier, in
116117

117118
/**
118119
* Create test store
119-
*
120-
* @return int
121120
*/
122121
private function createStore(): int
123122
{
@@ -134,7 +133,6 @@ private function createStore(): int
134133
* Delete test store
135134
*
136135
* @param int $storeId
137-
* @return void
138136
*/
139137
private function deleteStore(int $storeId): void
140138
{

dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Filesystem;
12+
use Magento\ImportExport\Model\Import;
1213
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use PHPUnit\Framework\TestCase;
@@ -28,43 +29,53 @@ class CsvTest extends TestCase
2829
*/
2930
private $objectManager;
3031

31-
/**
32-
* @var Csv
33-
*/
34-
private $csv;
35-
3632
/**
3733
* @inheritdoc
3834
*/
3935
protected function setUp(): void
4036
{
41-
parent::setUp();
42-
4337
$this->objectManager = Bootstrap::getObjectManager();
44-
$this->csv = $this->objectManager->create(
45-
Csv::class,
46-
['destination' => $this->destination]
47-
);
4838
}
4939

5040
/**
5141
* Test to destruct export adapter
42+
*
43+
* @dataProvider destructDataProvider
44+
*
45+
* @param string $destination
46+
* @param bool $shouldBeDeleted
47+
* @return void
5248
*/
53-
public function testDestruct(): void
49+
public function testDestruct(string $destination, bool $shouldBeDeleted): void
5450
{
51+
$csv = $this->objectManager->create(Csv::class, ['destination' => $destination]);
5552
/** @var Filesystem $fileSystem */
5653
$fileSystem = $this->objectManager->get(Filesystem::class);
5754
$directoryHandle = $fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
5855
/** Assert that the destination file is present after construct */
5956
$this->assertFileExists(
60-
$directoryHandle->getAbsolutePath($this->destination),
57+
$directoryHandle->getAbsolutePath($destination),
6158
'The destination file was\'t created after construct'
6259
);
63-
/** Assert that the destination file was removed after destruct */
64-
$this->csv = null;
65-
$this->assertFileNotExists(
66-
$directoryHandle->getAbsolutePath($this->destination),
67-
'The destination file was\'t removed after destruct'
68-
);
60+
unset($csv);
61+
62+
if ($shouldBeDeleted) {
63+
$this->assertFileDoesNotExist($directoryHandle->getAbsolutePath($destination));
64+
} else {
65+
$this->assertFileExists($directoryHandle->getAbsolutePath($destination));
66+
}
67+
}
68+
69+
/**
70+
* DataProvider for testDestruct
71+
*
72+
* @return array
73+
*/
74+
public function destructDataProvider(): array
75+
{
76+
return [
77+
'temporary file' => [$this->destination, true],
78+
'import history file' => [Import::IMPORT_HISTORY_DIR . $this->destination, false],
79+
];
6980
}
7081
}

0 commit comments

Comments
 (0)