Skip to content

Commit

Permalink
Merge pull request #6564 from magento-tsg/2.4-develop-sidecar-pr13
Browse files Browse the repository at this point in the history
[Sidecar] Fixes for 2.4 (pr13)
  • Loading branch information
zakdma authored Jan 29, 2021
2 parents 2ef2147 + 7fbf9aa commit 9faf621
Show file tree
Hide file tree
Showing 10 changed files with 635 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Api;

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

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testGet()
public function testGet(): void
{
$productSku = 'configurable';

Expand Down Expand Up @@ -54,8 +57,10 @@ public function testGet()

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testGetList()
public function testGetList(): void
{
$productSku = 'configurable';

Expand Down Expand Up @@ -90,8 +95,9 @@ public function testGetList()
}

/**
* @return void
*/
public function testGetUndefinedProduct()
public function testGetUndefinedProduct(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage(
Expand All @@ -104,8 +110,10 @@ public function testGetUndefinedProduct()

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testGetUndefinedOption()
public function testGetUndefinedOption(): void
{
$expectedMessage = 'The "%1" entity that was requested doesn\'t exist. Verify the entity and try again.';
$productSku = 'configurable';
Expand All @@ -127,8 +135,10 @@ public function testGetUndefinedOption()

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testDelete()
public function testDelete(): void
{
$productSku = 'configurable';

Expand All @@ -144,8 +154,10 @@ public function testDelete()
/**
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
*
* @return void
*/
public function testAdd()
public function testAdd(): void
{
/** @var AttributeRepositoryInterface $attributeRepository */
$attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class);
Expand Down Expand Up @@ -181,8 +193,10 @@ public function testAdd()

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testUpdate()
public function testUpdate(): void
{
$productSku = 'configurable';
$configurableAttribute = $this->getConfigurableAttribute($productSku);
Expand Down Expand Up @@ -218,8 +232,10 @@ public function testUpdate()

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testUpdateWithoutOptionId()
public function testUpdateWithoutOptionId(): void
{
$productSku = 'configurable';
/** @var AttributeRepositoryInterface $attributeRepository */
Expand Down Expand Up @@ -257,6 +273,19 @@ public function testUpdateWithoutOptionId()
$this->assertEquals($option['label'], $configurableAttribute[0]['label']);
}

/**
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*
* @return void
*/
public function testDeleteNotExistsOption(): void
{
$message = (string)__('The option that was requested doesn\'t exist. Verify the entity and try again.');
$this->expectExceptionMessage($message);
$this->expectException(\Exception::class);
$this->delete('configurable', 555);
}

/**
* @param string $productSku
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,66 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Block\Adminhtml\Category\Checkboxes;

use Magento\Catalog\Helper\DefaultCategory;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Checks category chooser block behaviour
*
* @see \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree
*
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
class TreeTest extends \PHPUnit\Framework\TestCase
class TreeTest extends TestCase
{
/** @var \Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree */
protected $block;
/** @var ObjectManagerInterface */
private $objectManager;

/** @var Tree */
private $block;

/** @var SerializerInterface */
private $json;

/** @var DefaultCategory */
private $defaultCategoryHelper;

/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Block\Adminhtml\Category\Checkboxes\Tree::class
);
$this->objectManager = Bootstrap::getObjectManager();
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Tree::class);
$this->json = $this->objectManager->get(SerializerInterface::class);
$this->defaultCategoryHelper = $this->objectManager->get(DefaultCategory::class);
}

public function testSetGetCategoryIds()
/**
* @return void
*/
public function testSetGetCategoryIds(): void
{
$this->block->setCategoryIds([1, 4, 7, 56, 2]);
$this->assertEquals([1, 4, 7, 56, 2], $this->block->getCategoryIds());
}

/**
* @magentoDataFixture Magento/Catalog/_files/categories.php
*
* @return void
*/
public function testGetTreeJson()
public function testGetTreeJson(): void
{
$jsonTree = $this->block->getTreeJson();
$this->assertStringContainsString('Default Category (4)', $jsonTree);
Expand All @@ -45,4 +76,17 @@ public function testGetTreeJson()
$this->assertStringContainsString('Category 12 (2)', $jsonTree);
$this->assertStringMatchesFormat('%s"path":"1\/2\/%s\/%s\/%s"%s', $jsonTree);
}

/**
* @return void
*/
public function testGetTreeJsonWithSelectedCategory(): void
{
$this->block->setCategoryIds($this->defaultCategoryHelper->getId());
$result = $this->json->unserialize($this->block->getTreeJson());
$item = reset($result);
$this->assertNotEmpty($item);
$this->assertStringContainsString('Default Category', $item['text']);
$this->assertTrue($item['checked']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Controller\Adminhtml\Category\Image;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;

/**
* Test cases related to upload category image.
*
* @see \Magento\Catalog\Controller\Adminhtml\Category\Image\Upload
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
*/
class UploadTest extends AbstractBackendController
{
/** @var Filesystem */
private $filesystem;

/** @var WriteInterface */
private $tmpDirectory;

/** @var SerializerInterface */
private $json;

/** @var string */
private $fileToRemove;

/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();

$this->filesystem = $this->_objectManager->get(Filesystem::class);
$this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
$this->json = $this->_objectManager->get(SerializerInterface::class);
}

/**
* @inheritdoc
*/
protected function tearDown(): void
{
if (file_exists($this->fileToRemove)) {
unlink($this->fileToRemove);
}

parent::tearDown();
}

/**
* @return void
*/
public function testWithNotAllowedFileExtension(): void
{
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue('param_name', 'image');
$this->prepareFile('empty.csv');
$this->dispatch('backend/catalog/category_image/upload');
$responseBody = $this->json->unserialize($this->getResponse()->getBody());
$this->assertNotEmpty($responseBody['error']);
$this->assertStringContainsString((string)__('File validation failed.'), $responseBody['error']);
}

/**
* Prepare file
*
* @param string $fileName
* @return void
*/
private function prepareFile(string $fileName): void
{
$this->tmpDirectory->create($this->tmpDirectory->getAbsolutePath());
$filePath = $this->tmpDirectory->getAbsolutePath($fileName);
$this->fileToRemove = $filePath;
$fixtureDir = realpath(__DIR__ . '/../../../../_files');
$this->tmpDirectory->getDriver()->copy($fixtureDir . DIRECTORY_SEPARATOR . $fileName, $filePath);
$_FILES['image'] = [
'name' => $fileName,
'type' => 'image',
'tmp_name' => $filePath,
'error' => 0,
'size' => 12500,
];
}
}
Loading

0 comments on commit 9faf621

Please sign in to comment.