Skip to content
Snippets Groups Projects
Commit c49a9d8b authored by Stanislav Lopukhov's avatar Stanislav Lopukhov
Browse files

MAGETWO-58600: Remove uses of unserialize in...

MAGETWO-58600: Remove uses of unserialize in \Magento\UrlRewrite\Model\UrlRewrite attribute metadata
parent cf72ff39
Branches
No related merge requests found
......@@ -5,8 +5,6 @@
*/
namespace Magento\CatalogUrlRewrite\Observer;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
class UrlRewriteHandler
{
/** @var \Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider */
......@@ -130,7 +128,7 @@ class UrlRewriteHandler
* @param int $storeId
* @param bool $saveRewriteHistory
* @param int|null $rootCategoryId
* @return UrlRewrite[]
* @return array
*/
public function getCategoryProductsUrlRewrites(
\Magento\Catalog\Model\Category $category,
......@@ -187,15 +185,17 @@ class UrlRewriteHandler
foreach ($categoryIds as $categoryId) {
$this->urlPersist->deleteByData(
[
UrlRewrite::ENTITY_ID => $categoryId,
UrlRewrite::ENTITY_TYPE =>
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::ENTITY_ID =>
$categoryId,
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::ENTITY_TYPE =>
\Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator::ENTITY_TYPE,
]
);
$this->urlPersist->deleteByData(
[
UrlRewrite::METADATA => $this->serializer->serialize(['category_id' => $categoryId]),
UrlRewrite::ENTITY_TYPE =>
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::METADATA =>
$this->serializer->serialize(['category_id' => $categoryId]),
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::ENTITY_TYPE =>
\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
]
);
......
......@@ -6,6 +6,7 @@
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Category;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
class ChildrenUrlRewriteGeneratorTest extends \PHPUnit_Framework_TestCase
{
......@@ -27,8 +28,14 @@ class ChildrenUrlRewriteGeneratorTest extends \PHPUnit_Framework_TestCase
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $mergeDataProvider;
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $serializerMock;
protected function setUp()
{
$this->serializerMock = $this->getMockBuilder(Json::class)
->disableOriginalConstructor()
->getMock();
$this->childrenCategoriesProvider = $this->getMockBuilder(
\Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider::class
)->disableOriginalConstructor()->getMock();
......@@ -84,13 +91,13 @@ class ChildrenUrlRewriteGeneratorTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($saveRewritesHistory));
$this->categoryUrlRewriteGeneratorFactory->expects($this->once())->method('create')
->will($this->returnValue($this->categoryUrlRewriteGenerator));
$url1 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$url1 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializerMock);
$url1->setRequestPath('category-1')
->setStoreId(1);
$url2 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$url2 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializerMock);
$url2->setRequestPath('category-2')
->setStoreId(2);
$url3 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite();
$url3 = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializerMock);
$url3->setRequestPath('category-1')
->setStoreId(1);
$this->categoryUrlRewriteGenerator->expects($this->once())->method('generate')
......
......@@ -8,9 +8,13 @@
namespace Magento\CatalogUrlRewrite\Test\Unit\Model;
use Magento\Catalog\Model\Category;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
/**
* Class CategoryUrlRewriteGeneratorTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CategoryUrlRewriteGeneratorTest extends \PHPUnit_Framework_TestCase
{
/** @var \PHPUnit_Framework_MockObject_MockObject */
......
......@@ -13,6 +13,7 @@ use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\CatalogUrlRewrite\Model\Map\DataCategoryUrlRewriteDatabaseMap;
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
use Magento\Framework\Serialize\Serializer\Json;
/**
* Class UrlRewriteFinderTest
......@@ -34,12 +35,16 @@ class UrlRewriteFinderTest extends \PHPUnit_Framework_TestCase
/** @var UrlRewriteFinder|\PHPUnit_Framework_MockObject_MockObject */
private $model;
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $serializerMock;
protected function setUp()
{
$this->serializerMock = $this->getMock(Json::class, [], [], '', false);
$this->databaseMapPoolMock = $this->getMock(DatabaseMapPool::class, [], [], '', false);
$this->urlFinderMock = $this->getMock(UrlFinderInterface::class);
$this->urlRewriteFactoryMock = $this->getMock(UrlRewriteFactory::class, ['create'], [], '', false);
$this->urlRewritePrototypeMock = new UrlRewrite();
$this->urlRewritePrototypeMock = new UrlRewrite([], $this->serializerMock);
$this->urlRewriteFactoryMock->expects($this->any())
->method('create')
......
......@@ -12,6 +12,8 @@ use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\UrlRewrite\Model\MergeDataProviderFactory;
use \Magento\UrlRewrite\Model\MergeDataProvider;
class UrlRewriteHandlerTest extends \PHPUnit_Framework_TestCase
{
......@@ -45,6 +47,11 @@ class UrlRewriteHandlerTest extends \PHPUnit_Framework_TestCase
*/
protected $collectionFactoryMock;
/**
* @var MergeDataProviderFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $mergeDataProviderFactoryMock;
/**
* @var Json|\PHPUnit_Framework_MockObject_MockObject
*/
......@@ -68,6 +75,17 @@ class UrlRewriteHandlerTest extends \PHPUnit_Framework_TestCase
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
->disableOriginalConstructor()
->getMock();
$this->mergeDataProviderFactoryMock = $this->getMockBuilder(MergeDataProviderFactory::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$mergeDataProviderMock = $this->getMockBuilder(MergeDataProvider::class)
->disableOriginalConstructor()
->getMock();
$this->mergeDataProviderFactoryMock->expects($this->any())
->method('create')
->willReturn($mergeDataProviderMock);
$this->serializerMock = $this->getMockBuilder(Json::class)
->disableOriginalConstructor()
->getMock();
......@@ -78,6 +96,7 @@ class UrlRewriteHandlerTest extends \PHPUnit_Framework_TestCase
$this->productUrlRewriteGeneratorMock,
$this->urlPersistMock,
$this->collectionFactoryMock,
$this->mergeDataProviderFactoryMock,
$this->serializerMock
);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment