Skip to content

Commit df69e82

Browse files
committed
fixed 'unit' test for related changes
1 parent c7822ff commit df69e82

File tree

3 files changed

+109
-165
lines changed

3 files changed

+109
-165
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Plugin/Webapi/Controller/Rest/InputParamsResolverTest.php

Lines changed: 0 additions & 164 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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\CatalogUrlRewrite\Test\Unit\Plugin\Webapi\Controller\Rest;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\CatalogUrlRewrite\Model\SetSaveRewriteHistory;
13+
use Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\ProductInputParamsResolver;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use Magento\Framework\Webapi\Rest\Request as RestRequest;
16+
use Magento\Webapi\Controller\Rest\InputParamsResolver;
17+
use Magento\Webapi\Controller\Rest\Router\Route;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Unit test for ProductInputParamsResolver plugin
23+
*/
24+
class ProductInputParamsResolverTest extends TestCase
25+
{
26+
/**
27+
* @var array
28+
*/
29+
private $result;
30+
31+
/**
32+
* @var ObjectManager
33+
*/
34+
private $objectManager;
35+
36+
/**
37+
* @var InputParamsResolver|MockObject
38+
*/
39+
private $subject;
40+
41+
/**
42+
* @var RestRequest|MockObject
43+
*/
44+
private $request;
45+
46+
/**
47+
* @var Product|MockObject
48+
*/
49+
private $product;
50+
51+
/**
52+
* @var Route|MockObject
53+
*/
54+
private $route;
55+
56+
/**
57+
* @var SetSaveRewriteHistory|MockObject
58+
*/
59+
private $rewriteHistoryMock;
60+
61+
/**
62+
* @var ProductInputParamsResolver
63+
*/
64+
private $plugin;
65+
66+
/**
67+
* @inheritdoc
68+
*/
69+
protected function setUp(): void
70+
{
71+
$this->route = $this->createMock(Route::class);
72+
$this->request = $this->createMock(RestRequest::class);
73+
$this->subject = $this->createMock(InputParamsResolver::class);
74+
$this->product = $this->createMock(Product::class);
75+
$this->rewriteHistoryMock = $this->createMock(SetSaveRewriteHistory::class);
76+
}
77+
78+
public function testAfterResolveWithProduct()
79+
{
80+
$this->subject->expects($this->any())
81+
->method('getRoute')
82+
->willReturn($this->route);
83+
84+
$this->result = [false, $this->product, 'test'];
85+
86+
$this->objectManager = new ObjectManager($this);
87+
$this->plugin = $this->objectManager->getObject(
88+
ProductInputParamsResolver::class,
89+
[
90+
'rewriteHistory' => $this->rewriteHistoryMock
91+
]
92+
);
93+
94+
$this->route->expects($this->once())
95+
->method('getServiceClass')
96+
->willReturn(ProductRepositoryInterface::class);
97+
$this->route->expects($this->once())
98+
->method('getServiceMethod')
99+
->willReturn('save');
100+
$this->rewriteHistoryMock->expects($this->once())
101+
->method('execute')
102+
->with($this->result, 'product', Product::class)
103+
->willReturn($this->result);
104+
105+
$this->plugin->afterResolve($this->subject, $this->result);
106+
}
107+
}

dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ public function testUpdateWithDefaultSortByAttribute()
252252
*/
253253
public function testUpdateUrlKey()
254254
{
255+
$this->_markTestAsRestOnly('Functionality available in REST mode only.');
256+
255257
$categoryId = 333;
256258
$categoryData = [
257259
'name' => 'Update Category Test Old Name',
@@ -302,7 +304,6 @@ public function testUpdateUrlKey()
302304
$this->assertEquals(CategoryUrlRewriteGenerator::ENTITY_TYPE, $urlRewrite->getEntityType());
303305
$this->assertEquals('update-category-test-new-name.html', $urlRewrite->getRequestPath());
304306

305-
306307
// check for the forward from the old name to the new name
307308
$storage = Bootstrap::getObjectManager()->get(\Magento\UrlRewrite\Model\Storage\DbStorage::class);
308309
$data = [

0 commit comments

Comments
 (0)