Skip to content

Commit a216afb

Browse files
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-56116' into MAGETWO-56116
2 parents a6f19c3 + 943c610 commit a216afb

File tree

22 files changed

+124
-121
lines changed

22 files changed

+124
-121
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333

3434
/**
3535
* @param \Magento\UrlRewrite\Model\StorageInterface $object
36-
* @param void $result
36+
* @param null $result
3737
* @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls
3838
* @return void
3939
* @SuppressWarnings(PHPMD.UnusedFormalParameter)

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/StorageTest.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,52 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Category\Plugin;
87

98
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
109
use Magento\CatalogUrlRewrite\Model\Category\ProductFactory;
1110
use Magento\UrlRewrite\Model\StorageInterface;
12-
use Magento\CatalogUrlRewrite\Model\Category\Plugin\Storage;
11+
use Magento\CatalogUrlRewrite\Model\Category\Plugin\Storage as CategoryStoragePlugin;
1312
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1413
use Magento\UrlRewrite\Model\UrlFinderInterface;
1514
use Magento\CatalogUrlRewrite\Model\Category\Product;
1615
use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product as ProductResourceModel;
1716

1817
class StorageTest extends \PHPUnit_Framework_TestCase
1918
{
20-
/** @var Storage */
21-
private $model;
19+
/**
20+
* @var CategoryStoragePlugin
21+
*/
22+
private $plugin;
2223

23-
/** @var ProductFactory|\PHPUnit_Framework_MockObject_MockObject */
24+
/**
25+
* @var ProductFactory|\PHPUnit_Framework_MockObject_MockObject
26+
*/
2427
private $productFactory;
2528

26-
/** @var UrlFinderInterface|\PHPUnit_Framework_MockObject_MockObject */
29+
/**
30+
* @var UrlFinderInterface|\PHPUnit_Framework_MockObject_MockObject
31+
*/
2732
private $urlFinder;
2833

29-
/** @var StorageInterface|\PHPUnit_Framework_MockObject_MockObject */
34+
/**
35+
* @var StorageInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
3037
private $storage;
3138

32-
/** @var Product|\PHPUnit_Framework_MockObject_MockObject */
39+
/**
40+
* @var Product|\PHPUnit_Framework_MockObject_MockObject
41+
*/
3342
private $product;
3443

35-
/** @var ProductResourceModel|\PHPUnit_Framework_MockObject_MockObject */
44+
/**
45+
* @var ProductResourceModel|\PHPUnit_Framework_MockObject_MockObject
46+
*/
3647
private $productResourceModel;
3748

38-
/** @var UrlRewrite|\PHPUnit_Framework_MockObject_MockObject */
49+
/**
50+
* @var UrlRewrite|\PHPUnit_Framework_MockObject_MockObject
51+
*/
3952
private $urlRewrite;
4053

4154
protected function setUp()
@@ -59,8 +72,8 @@ protected function setUp()
5972
->setMethods(['getMetadata', 'getEntityType', 'getIsAutogenerated', 'getUrlRewriteId', 'getEntityId'])
6073
->getMock();
6174

62-
$this->model = (new ObjectManager($this))->getObject(
63-
Storage::class,
75+
$this->plugin = (new ObjectManager($this))->getObject(
76+
CategoryStoragePlugin::class,
6477
[
6578
'productFactory' => $this->productFactory,
6679
'urlFinder' => $this->urlFinder
@@ -85,6 +98,6 @@ public function testAfterReplace()
8598
$this->product->expects(static::once())->method('getResource')->willReturn($this->productResourceModel);
8699
$this->productResourceModel->expects(static::once())->method('saveMultiple')->willReturnSelf();
87100

88-
$this->model->afterReplace($this->storage, null, $productUrls);
101+
$this->plugin->afterReplace($this->storage, null, $productUrls);
89102
}
90103
}

app/code/Magento/CmsUrlRewrite/Test/Unit/Plugin/Cms/Model/ResourceModel/PageTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ class PageTest extends \PHPUnit_Framework_TestCase
3030
*/
3131
protected $cmsPageResourceMock;
3232

33-
/**
34-
* @var \Closure
35-
*/
36-
protected $closureMock;
37-
3833
protected function setUp()
3934
{
4035
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4136

42-
$this->closureMock = function () {
43-
return 'URL Rewrite Result';
44-
};
45-
4637
$this->urlPersistMock = $this->getMockBuilder(\Magento\UrlRewrite\Model\UrlPersistInterface::class)
4738
->getMockForAbstractClass();
4839

@@ -62,7 +53,7 @@ protected function setUp()
6253
);
6354
}
6455

65-
public function testAroundDeletePositive()
56+
public function testAfterDeletePositive()
6657
{
6758
$productId = 100;
6859

@@ -93,7 +84,7 @@ public function testAroundDeletePositive()
9384
);
9485
}
9586

96-
public function testAroundDeleteNegative()
87+
public function testAfterDeleteNegative()
9788
{
9889
$this->cmsPageMock->expects($this->once())
9990
->method('isDeleted')

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Builder/Plugin.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Catalog\Model\ProductFactory;
1010
use Magento\ConfigurableProduct\Model\Product\Type;
1111
use Magento\Catalog\Model\Product;
12-
use Magento\Catalog\Controller\Adminhtml\Product\Builder;
12+
use Magento\Catalog\Controller\Adminhtml\Product\Builder as CatalogProductBuilder;
1313
use Magento\Framework\App\RequestInterface;
1414

1515
class Plugin
@@ -35,18 +35,17 @@ public function __construct(ProductFactory $productFactory, Type\Configurable $c
3535
}
3636

3737
/**
38-
* @param Builder $subject
38+
* Set type and data to configurable product
39+
*
40+
* @param CatalogProductBuilder $subject
3941
* @param Product $product
4042
* @param RequestInterface $request
4143
* @return Product
4244
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4345
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
4446
*/
45-
public function afterBuild(
46-
Builder $subject,
47-
Product $product,
48-
RequestInterface $request
49-
) {
47+
public function afterBuild(CatalogProductBuilder $subject, Product $product, RequestInterface $request)
48+
{
5049
if ($request->has('attributes')) {
5150
$attributes = $request->getParam('attributes');
5251
if (!empty($attributes)) {

app/code/Magento/ConfigurableProduct/Model/Plugin/AroundProductRepositorySave.php renamed to app/code/Magento/ConfigurableProduct/Model/Plugin/ProductRepositorySave.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
1515
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1616

17-
/**
18-
* Class AroundProductRepositorySave
19-
*/
20-
class AroundProductRepositorySave
17+
class ProductRepositorySave
2118
{
2219
/**
2320
* @var ProductAttributeRepositoryInterface
@@ -42,6 +39,8 @@ public function __construct(
4239
}
4340

4441
/**
42+
* Validate product links and reset configurable attributes to configurable product
43+
*
4544
* @param ProductRepositoryInterface $subject
4645
* @param ProductInterface $result
4746
* @param ProductInterface $product

app/code/Magento/ConfigurableProduct/Model/Product/Validator/Plugin.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __construct(
4848
}
4949

5050
/**
51+
* Set configurable type to product
52+
*
5153
* @param Product\Validator $subject
5254
* @param Product $product
5355
* @param RequestInterface $request
@@ -58,7 +60,7 @@ public function __construct(
5860
public function beforeValidate(
5961
\Magento\Catalog\Model\Product\Validator $subject,
6062
\Magento\Catalog\Model\Product $product,
61-
\Magento\Framework\App\RequestInterface $request,
63+
RequestInterface $request,
6264
DataObject $response
6365
) {
6466
if ($request->has('attributes')) {
@@ -81,7 +83,7 @@ public function afterValidate(
8183
\Magento\Catalog\Model\Product\Validator $subject,
8284
$result,
8385
\Magento\Catalog\Model\Product $product,
84-
\Magento\Framework\App\RequestInterface $request,
86+
RequestInterface $request,
8587
DataObject $response
8688
) {
8789
$variationProducts = (array)$request->getPost('variations-matrix');

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Builder/PluginTest.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class PluginTest extends \PHPUnit_Framework_TestCase
5252
*/
5353
protected $subjectMock;
5454

55-
/**
56-
* @var \Closure
57-
*/
58-
protected $closureMock;
59-
6055
protected function setUp()
6156
{
6257
$this->productFactoryMock = $this->getMock(
@@ -124,9 +119,6 @@ protected function setUp()
124119
'',
125120
false
126121
);
127-
$this->closureMock = function () use ($product) {
128-
return $product;
129-
};
130122
$this->plugin = new \Magento\ConfigurableProduct\Controller\Adminhtml\Product\Builder\Plugin(
131123
$this->productFactoryMock,
132124
$this->configurableTypeMock
@@ -137,7 +129,7 @@ protected function setUp()
137129
* @return void
138130
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
139131
*/
140-
public function testAroundBuild()
132+
public function testAfterBuild()
141133
{
142134
$this->requestMock->expects($this->once())->method('has')->with('attributes')->will($this->returnValue(true));
143135
$valueMap = [
@@ -260,7 +252,7 @@ public function testAroundBuild()
260252
);
261253
}
262254

263-
public function testAroundBuildWhenProductNotHaveAttributeAndRequiredParameters()
255+
public function testAfterBuildWhenProductNotHaveAttributeAndRequiredParameters()
264256
{
265257
$valueMap = [
266258
['attributes', null, null],
@@ -287,7 +279,7 @@ public function testAroundBuildWhenProductNotHaveAttributeAndRequiredParameters(
287279
);
288280
}
289281

290-
public function testAroundBuildWhenAttributesAreEmpty()
282+
public function testAfterBuildWhenAttributesAreEmpty()
291283
{
292284
$valueMap = [['popup', null, false], ['product', null, 'product'], ['id', false, false]];
293285
$this->requestMock->expects($this->once())->method('has')->with('attributes')->will($this->returnValue(false));
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\ProductFactory;
1313
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
14-
use Magento\ConfigurableProduct\Model\Plugin\AroundProductRepositorySave;
14+
use Magento\ConfigurableProduct\Model\Plugin\ProductRepositorySave;
1515
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1616
use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1718
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1819

1920
/**
20-
* Class AroundProductRepositorySaveTest
21+
* Class ProductRepositorySaveTest
2122
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2223
*/
23-
class AroundProductRepositorySaveTest extends \PHPUnit_Framework_TestCase
24+
class ProductRepositorySaveTest extends \PHPUnit_Framework_TestCase
2425
{
2526
/**
2627
* @var ProductAttributeRepositoryInterface|MockObject
@@ -63,7 +64,7 @@ class AroundProductRepositorySaveTest extends \PHPUnit_Framework_TestCase
6364
private $option;
6465

6566
/**
66-
* @var AroundProductRepositorySave
67+
* @var ProductRepositorySave
6768
*/
6869
private $plugin;
6970

@@ -97,13 +98,16 @@ protected function setUp()
9798

9899
$this->option = $this->getMockForAbstractClass(OptionInterface::class);
99100

100-
$this->plugin = new AroundProductRepositorySave(
101-
$this->productAttributeRepository,
102-
$this->productFactory
101+
$this->plugin = (new ObjectManager($this))->getObject(
102+
ProductRepositorySave::class,
103+
[
104+
'productAttributeRepository' => $this->productAttributeRepository,
105+
'productFactory' => $this->productFactory
106+
]
103107
);
104108
}
105109

106-
public function testAroundSaveWhenProductIsSimple()
110+
public function testAfterSaveWhenProductIsSimple()
107111
{
108112
$this->product->expects(static::once())
109113
->method('getTypeId')
@@ -117,7 +121,7 @@ public function testAroundSaveWhenProductIsSimple()
117121
);
118122
}
119123

120-
public function testAroundSaveWithoutOptions()
124+
public function testAfterSaveWithoutOptions()
121125
{
122126
$this->product->expects(static::once())
123127
->method('getTypeId')
@@ -147,7 +151,7 @@ public function testAroundSaveWithoutOptions()
147151
* @expectedException \Magento\Framework\Exception\InputException
148152
* @expectedExceptionMessage Products "5" and "4" have the same set of attribute values.
149153
*/
150-
public function testAroundSaveWithLinks()
154+
public function testAfterSaveWithLinks()
151155
{
152156
$links = [4, 5];
153157
$this->product->expects(static::once())
@@ -189,7 +193,7 @@ public function testAroundSaveWithLinks()
189193
* @expectedException \Magento\Framework\Exception\InputException
190194
* @expectedExceptionMessage Product with id "4" does not contain required attribute "color".
191195
*/
192-
public function testAroundSaveWithLinksWithMissingAttribute()
196+
public function testAfterSaveWithLinksWithMissingAttribute()
193197
{
194198
$simpleProductId = 4;
195199
$links = [$simpleProductId, 5];
@@ -246,7 +250,7 @@ public function testAroundSaveWithLinksWithMissingAttribute()
246250
* @expectedException \Magento\Framework\Exception\InputException
247251
* @expectedExceptionMessage Products "5" and "4" have the same set of attribute values.
248252
*/
249-
public function testAroundSaveWithLinksWithDuplicateAttributes()
253+
public function testAfterSaveWithLinksWithDuplicateAttributes()
250254
{
251255
$links = [4, 5];
252256
$attributeCode = 'color';

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Validator/PluginTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testBeforeValidate()
119119
);
120120
}
121121

122-
public function testAroundValidateWithVariationsValid()
122+
public function testAfterValidateWithVariationsValid()
123123
{
124124
$matrix = ['products'];
125125

@@ -165,7 +165,7 @@ public function testAroundValidateWithVariationsValid()
165165
);
166166
}
167167

168-
public function testAroundValidateWithVariationsInvalid()
168+
public function testAfterValidateWithVariationsInvalid()
169169
{
170170
$matrix = ['products'];
171171

@@ -212,7 +212,7 @@ public function testAroundValidateWithVariationsInvalid()
212212
);
213213
}
214214

215-
public function testAroundValidateIfVariationsNotExist()
215+
public function testAfterValidateIfVariationsNotExist()
216216
{
217217
$this->requestMock->expects(
218218
$this->once()
@@ -233,7 +233,7 @@ public function testAroundValidateIfVariationsNotExist()
233233
);
234234
}
235235

236-
public function testAroundValidateWithVariationsAndRequiredAttributes()
236+
public function testAfterValidateWithVariationsAndRequiredAttributes()
237237
{
238238
$matrix = [
239239
['data1', 'data2', 'configurable_attribute' => ['data1']],

0 commit comments

Comments
 (0)