Skip to content

Commit 9faf621

Browse files
authored
Merge pull request #6564 from magento-tsg/2.4-develop-sidecar-pr13
[Sidecar] Fixes for 2.4 (pr13)
2 parents 2ef2147 + 7fbf9aa commit 9faf621

File tree

10 files changed

+635
-50
lines changed

10 files changed

+635
-50
lines changed

dev/tests/api-functional/testsuite/Magento/ConfigurableProduct/Api/OptionRepositoryTest.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
78

89
namespace Magento\ConfigurableProduct\Api;
910

@@ -21,8 +22,10 @@ class OptionRepositoryTest extends \Magento\TestFramework\TestCase\WebapiAbstrac
2122

2223
/**
2324
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
25+
*
26+
* @return void
2427
*/
25-
public function testGet()
28+
public function testGet(): void
2629
{
2730
$productSku = 'configurable';
2831

@@ -54,8 +57,10 @@ public function testGet()
5457

5558
/**
5659
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
60+
*
61+
* @return void
5762
*/
58-
public function testGetList()
63+
public function testGetList(): void
5964
{
6065
$productSku = 'configurable';
6166

@@ -90,8 +95,9 @@ public function testGetList()
9095
}
9196

9297
/**
98+
* @return void
9399
*/
94-
public function testGetUndefinedProduct()
100+
public function testGetUndefinedProduct(): void
95101
{
96102
$this->expectException(\Exception::class);
97103
$this->expectExceptionMessage(
@@ -104,8 +110,10 @@ public function testGetUndefinedProduct()
104110

105111
/**
106112
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
113+
*
114+
* @return void
107115
*/
108-
public function testGetUndefinedOption()
116+
public function testGetUndefinedOption(): void
109117
{
110118
$expectedMessage = 'The "%1" entity that was requested doesn\'t exist. Verify the entity and try again.';
111119
$productSku = 'configurable';
@@ -127,8 +135,10 @@ public function testGetUndefinedOption()
127135

128136
/**
129137
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
138+
*
139+
* @return void
130140
*/
131-
public function testDelete()
141+
public function testDelete(): void
132142
{
133143
$productSku = 'configurable';
134144

@@ -144,8 +154,10 @@ public function testDelete()
144154
/**
145155
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
146156
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
157+
*
158+
* @return void
147159
*/
148-
public function testAdd()
160+
public function testAdd(): void
149161
{
150162
/** @var AttributeRepositoryInterface $attributeRepository */
151163
$attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class);
@@ -181,8 +193,10 @@ public function testAdd()
181193

182194
/**
183195
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
196+
*
197+
* @return void
184198
*/
185-
public function testUpdate()
199+
public function testUpdate(): void
186200
{
187201
$productSku = 'configurable';
188202
$configurableAttribute = $this->getConfigurableAttribute($productSku);
@@ -218,8 +232,10 @@ public function testUpdate()
218232

219233
/**
220234
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
235+
*
236+
* @return void
221237
*/
222-
public function testUpdateWithoutOptionId()
238+
public function testUpdateWithoutOptionId(): void
223239
{
224240
$productSku = 'configurable';
225241
/** @var AttributeRepositoryInterface $attributeRepository */
@@ -257,6 +273,19 @@ public function testUpdateWithoutOptionId()
257273
$this->assertEquals($option['label'], $configurableAttribute[0]['label']);
258274
}
259275

276+
/**
277+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
278+
*
279+
* @return void
280+
*/
281+
public function testDeleteNotExistsOption(): void
282+
{
283+
$message = (string)__('The option that was requested doesn\'t exist. Verify the entity and try again.');
284+
$this->expectExceptionMessage($message);
285+
$this->expectException(\Exception::class);
286+
$this->delete('configurable', 555);
287+
}
288+
260289
/**
261290
* @param string $productSku
262291
* @return array

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Category/Checkboxes/TreeTest.php

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,66 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Block\Adminhtml\Category\Checkboxes;
79

10+
use Magento\Catalog\Helper\DefaultCategory;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
817
/**
18+
* Checks category chooser block behaviour
19+
*
20+
* @see \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree
21+
*
922
* @magentoAppArea adminhtml
1023
* @magentoDbIsolation enabled
1124
* @magentoAppIsolation enabled
1225
*/
13-
class TreeTest extends \PHPUnit\Framework\TestCase
26+
class TreeTest extends TestCase
1427
{
15-
/** @var \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree */
16-
protected $block;
28+
/** @var ObjectManagerInterface */
29+
private $objectManager;
30+
31+
/** @var Tree */
32+
private $block;
33+
34+
/** @var SerializerInterface */
35+
private $json;
1736

37+
/** @var DefaultCategory */
38+
private $defaultCategoryHelper;
39+
40+
/**
41+
* @inheritdoc
42+
*/
1843
protected function setUp(): void
1944
{
20-
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
21-
\Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree::class
22-
);
45+
$this->objectManager = Bootstrap::getObjectManager();
46+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Tree::class);
47+
$this->json = $this->objectManager->get(SerializerInterface::class);
48+
$this->defaultCategoryHelper = $this->objectManager->get(DefaultCategory::class);
2349
}
2450

25-
public function testSetGetCategoryIds()
51+
/**
52+
* @return void
53+
*/
54+
public function testSetGetCategoryIds(): void
2655
{
2756
$this->block->setCategoryIds([1, 4, 7, 56, 2]);
2857
$this->assertEquals([1, 4, 7, 56, 2], $this->block->getCategoryIds());
2958
}
3059

3160
/**
3261
* @magentoDataFixture Magento/Catalog/_files/categories.php
62+
*
63+
* @return void
3364
*/
34-
public function testGetTreeJson()
65+
public function testGetTreeJson(): void
3566
{
3667
$jsonTree = $this->block->getTreeJson();
3768
$this->assertStringContainsString('Default Category (4)', $jsonTree);
@@ -45,4 +76,17 @@ public function testGetTreeJson()
4576
$this->assertStringContainsString('Category 12 (2)', $jsonTree);
4677
$this->assertStringMatchesFormat('%s"path":"1\/2\/%s\/%s\/%s"%s', $jsonTree);
4778
}
79+
80+
/**
81+
* @return void
82+
*/
83+
public function testGetTreeJsonWithSelectedCategory(): void
84+
{
85+
$this->block->setCategoryIds($this->defaultCategoryHelper->getId());
86+
$result = $this->json->unserialize($this->block->getTreeJson());
87+
$item = reset($result);
88+
$this->assertNotEmpty($item);
89+
$this->assertStringContainsString('Default Category', $item['text']);
90+
$this->assertTrue($item['checked']);
91+
}
4892
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\Catalog\Controller\Adminhtml\Category\Image;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use Magento\Framework\Serialize\SerializerInterface;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
16+
17+
/**
18+
* Test cases related to upload category image.
19+
*
20+
* @see \Magento\Catalog\Controller\Adminhtml\Category\Image\Upload
21+
* @magentoAppArea adminhtml
22+
* @magentoDbIsolation enabled
23+
*/
24+
class UploadTest extends AbstractBackendController
25+
{
26+
/** @var Filesystem */
27+
private $filesystem;
28+
29+
/** @var WriteInterface */
30+
private $tmpDirectory;
31+
32+
/** @var SerializerInterface */
33+
private $json;
34+
35+
/** @var string */
36+
private $fileToRemove;
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function setUp(): void
42+
{
43+
parent::setUp();
44+
45+
$this->filesystem = $this->_objectManager->get(Filesystem::class);
46+
$this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
47+
$this->json = $this->_objectManager->get(SerializerInterface::class);
48+
}
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
protected function tearDown(): void
54+
{
55+
if (file_exists($this->fileToRemove)) {
56+
unlink($this->fileToRemove);
57+
}
58+
59+
parent::tearDown();
60+
}
61+
62+
/**
63+
* @return void
64+
*/
65+
public function testWithNotAllowedFileExtension(): void
66+
{
67+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
68+
$this->getRequest()->setPostValue('param_name', 'image');
69+
$this->prepareFile('empty.csv');
70+
$this->dispatch('backend/catalog/category_image/upload');
71+
$responseBody = $this->json->unserialize($this->getResponse()->getBody());
72+
$this->assertNotEmpty($responseBody['error']);
73+
$this->assertStringContainsString((string)__('File validation failed.'), $responseBody['error']);
74+
}
75+
76+
/**
77+
* Prepare file
78+
*
79+
* @param string $fileName
80+
* @return void
81+
*/
82+
private function prepareFile(string $fileName): void
83+
{
84+
$this->tmpDirectory->create($this->tmpDirectory->getAbsolutePath());
85+
$filePath = $this->tmpDirectory->getAbsolutePath($fileName);
86+
$this->fileToRemove = $filePath;
87+
$fixtureDir = realpath(__DIR__ . '/../../../../_files');
88+
$this->tmpDirectory->getDriver()->copy($fixtureDir . DIRECTORY_SEPARATOR . $fileName, $filePath);
89+
$_FILES['image'] = [
90+
'name' => $fileName,
91+
'type' => 'image',
92+
'tmp_name' => $filePath,
93+
'error' => 0,
94+
'size' => 12500,
95+
];
96+
}
97+
}

0 commit comments

Comments
 (0)