Skip to content

Commit c077da6

Browse files
committed
Merge pull request #625 from magento-troll/S45_Bugfixes
[Troll] S45 bugfixes
2 parents 8fc2cde + 1eeae7f commit c077da6

File tree

13 files changed

+204
-17
lines changed

13 files changed

+204
-17
lines changed

app/code/Magento/Catalog/Model/Product/Link.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ class Link extends \Magento\Framework\Model\AbstractModel
4949
*/
5050
protected $_linkCollectionFactory;
5151

52+
/**
53+
* @var \Magento\CatalogInventory\Helper\Stock
54+
*/
55+
protected $stockHelper;
56+
5257
/**
5358
* @param \Magento\Framework\Model\Context $context
5459
* @param \Magento\Framework\Registry $registry
5560
* @param \Magento\Catalog\Model\Resource\Product\Link\CollectionFactory $linkCollectionFactory
5661
* @param \Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory $productCollectionFactory
62+
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
5763
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
5864
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
5965
* @param array $data
@@ -63,12 +69,14 @@ public function __construct(
6369
\Magento\Framework\Registry $registry,
6470
\Magento\Catalog\Model\Resource\Product\Link\CollectionFactory $linkCollectionFactory,
6571
\Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory $productCollectionFactory,
72+
\Magento\CatalogInventory\Helper\Stock $stockHelper,
6673
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
6774
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
6875
array $data = []
6976
) {
7077
$this->_linkCollectionFactory = $linkCollectionFactory;
7178
$this->_productCollectionFactory = $productCollectionFactory;
79+
$this->stockHelper = $stockHelper;
7280
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
7381
}
7482

@@ -128,6 +136,7 @@ public function getAttributeTypeTable($type)
128136
public function getProductCollection()
129137
{
130138
$collection = $this->_productCollectionFactory->create()->setLinkModel($this);
139+
$this->stockHelper->addInStockFilterToCollection($collection);
131140
return $collection;
132141
}
133142

app/code/Magento/Catalog/Test/Unit/Model/Product/LinkTest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ class LinkTest extends \PHPUnit_Framework_TestCase
1919
*/
2020
protected $resource;
2121

22+
/**
23+
* @var \Magento\CatalogInventory\Helper\Stock|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $stockHelperMock;
26+
27+
/**
28+
* @var \Magento\Catalog\Model\Resource\Product\Link\Product\Collection|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
protected $productCollection;
31+
2232
protected function setUp()
2333
{
2434
$linkCollection = $this->getMockBuilder(
@@ -35,20 +45,20 @@ protected function setUp()
3545
$linkCollectionFactory->expects($this->any())
3646
->method('create')
3747
->will($this->returnValue($linkCollection));
38-
$productCollection = $this->getMockBuilder(
48+
$this->productCollection = $this->getMockBuilder(
3949
'Magento\Catalog\Model\Resource\Product\Link\Product\Collection'
4050
)->disableOriginalConstructor()->setMethods(
4151
['setLinkModel']
4252
)->getMock();
43-
$productCollection->expects($this->any())->method('setLinkModel')->will($this->returnSelf());
53+
$this->productCollection->expects($this->any())->method('setLinkModel')->will($this->returnSelf());
4454
$productCollectionFactory = $this->getMockBuilder(
4555
'Magento\Catalog\Model\Resource\Product\Link\Product\CollectionFactory'
4656
)->disableOriginalConstructor()->setMethods(
4757
['create']
4858
)->getMock();
4959
$productCollectionFactory->expects($this->any())
5060
->method('create')
51-
->will($this->returnValue($productCollection));
61+
->will($this->returnValue($this->productCollection));
5262

5363
$this->resource = $this->getMock(
5464
'Magento\Framework\Model\Resource\AbstractResource',
@@ -63,11 +73,19 @@ protected function setUp()
6373
]
6474
);
6575

76+
$this->stockHelperMock = $this->getMockBuilder('Magento\CatalogInventory\Helper\Stock')
77+
->disableOriginalConstructor()
78+
->getMock();
79+
6680
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6781
$this->model = $objectManager->getObject(
6882
'Magento\Catalog\Model\Product\Link',
69-
['linkCollectionFactory' => $linkCollectionFactory, 'productCollectionFactory' => $productCollectionFactory,
70-
'resource' => $this->resource]
83+
[
84+
'linkCollectionFactory' => $linkCollectionFactory,
85+
'productCollectionFactory' => $productCollectionFactory,
86+
'resource' => $this->resource,
87+
'stockHelper' => $this->stockHelperMock
88+
]
7189
);
7290
}
7391

@@ -109,6 +127,10 @@ public function testGetAttributeTypeTable()
109127

110128
public function testGetProductCollection()
111129
{
130+
$this->stockHelperMock
131+
->expects($this->once())
132+
->method('addInStockFilterToCollection')
133+
->with($this->productCollection);
112134
$this->assertInstanceOf(
113135
'Magento\Catalog\Model\Resource\Product\Link\Product\Collection',
114136
$this->model->getProductCollection()

app/code/Magento/CatalogUrlRewrite/Model/Product/Plugin/Import.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ protected function canonicalUrlRewriteGenerate()
320320
$urls = [];
321321
foreach ($this->products as $productId => $productsByStores) {
322322
foreach ($productsByStores as $storeId => $product) {
323-
$urls[] = $this->urlRewriteFactory->create()
324-
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
325-
->setEntityId($productId)
326-
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
327-
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
328-
->setStoreId($storeId);
323+
if ($this->productUrlPathGenerator->getUrlPath($product)) {
324+
$urls[] = $this->urlRewriteFactory->create()
325+
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
326+
->setEntityId($productId)
327+
->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId))
328+
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product))
329+
->setStoreId($storeId);
330+
}
329331
}
330332
}
331333

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Product/Plugin/ImportTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public function testClearProductUrls()
670670
/**
671671
* Cover canonicalUrlRewriteGenerate().
672672
*/
673-
public function testCanonicalUrlRewriteGenerate()
673+
public function testCanonicalUrlRewriteGenerateWithUrlPath()
674674
{
675675
$productId = 'product_id';
676676
$requestPath = 'simple-product.html';
@@ -691,6 +691,10 @@ public function testCanonicalUrlRewriteGenerate()
691691
->expects($this->once())
692692
->method('getUrlPathWithSuffix')
693693
->will($this->returnValue($requestPath));
694+
$this->productUrlPathGenerator
695+
->expects($this->once())
696+
->method('getUrlPath')
697+
->will($this->returnValue('urlPath'));
694698
$this->productUrlPathGenerator
695699
->expects($this->once())
696700
->method('getCanonicalUrlPath')
@@ -734,6 +738,36 @@ public function testCanonicalUrlRewriteGenerate()
734738
);
735739
}
736740

741+
/**
742+
* Cover canonicalUrlRewriteGenerate().
743+
*/
744+
public function testCanonicalUrlRewriteGenerateWithEmptyUrlPath()
745+
{
746+
$productId = 'product_id';
747+
$storeId = 10;
748+
$product = $this
749+
->getMockBuilder('Magento\Catalog\Model\Product')
750+
->disableOriginalConstructor()
751+
->getMock();
752+
$productsByStores = [$storeId => $product];
753+
$products = [
754+
$productId => $productsByStores,
755+
];
756+
757+
$this->setPropertyValue($this->import, 'products', $products);
758+
759+
$this->productUrlPathGenerator
760+
->expects($this->once())
761+
->method('getUrlPath')
762+
->will($this->returnValue(''));
763+
$this->urlRewriteFactory
764+
->expects($this->never())
765+
->method('create');
766+
767+
$actualResult = $this->invokeMethod($this->import, 'canonicalUrlRewriteGenerate');
768+
$this->assertEquals([], $actualResult);
769+
}
770+
737771
/**
738772
* Cover categoriesUrlRewriteGenerate().
739773
*/

app/code/Magento/Checkout/Block/Cart/Crosssell.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ protected function _getCollection()
199199
);
200200
$this->_addProductAttributesAndPrices($collection);
201201

202-
$this->stockHelper->addInStockFilterToCollection($collection);
203-
204202
return $collection;
205203
}
206204
}

dev/tests/api-functional/framework/Magento/TestFramework/Bootstrap/WebapiDocBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WebapiDocBlock extends \Magento\TestFramework\Bootstrap\DocBlock
1818
protected function _getSubscribers(\Magento\TestFramework\Application $application)
1919
{
2020
$subscribers = parent::_getSubscribers($application);
21-
array_unshift($subscribers, new \Magento\TestFramework\Annotation\ApiDataFixture($this->_fixturesBaseDir));
21+
$subscribers[] = new \Magento\TestFramework\Annotation\ApiDataFixture($this->_fixturesBaseDir);
2222
return $subscribers;
2323
}
2424
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\TestFramework\Helper\Bootstrap;
1010
use Magento\TestFramework\TestCase\WebapiAbstract;
1111

12+
/**
13+
* @magentoAppIsolation enabled
14+
*/
1215
class ProductLinkManagementInterfaceTest extends WebapiAbstract
1316
{
1417
const SERVICE_NAME = 'catalogProductLinkManagementV1';
@@ -85,7 +88,7 @@ protected function assertLinkedProducts($productSku, $linkType)
8588

8689
/**
8790
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
88-
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
91+
* @magentoApiDataFixture Magento/Catalog/_files/product_virtual_in_stock.php
8992
*/
9093
public function testAssign()
9194
{

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
namespace Magento\Catalog\Api;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
910
use Magento\TestFramework\TestCase\WebapiAbstract;
1011
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
1112

13+
/**
14+
* @magentoAppIsolation enabled
15+
*/
1216
class ProductRepositoryInterfaceTest extends WebapiAbstract
1317
{
1418
const SERVICE_NAME = 'catalogProductRepositoryV1';
@@ -139,6 +143,9 @@ public function testProductLinks()
139143
ProductInterface::STATUS => 1,
140144
ProductInterface::TYPE_ID => 'simple',
141145
ProductInterface::ATTRIBUTE_SET_ID => 4,
146+
ProductInterface::EXTENSION_ATTRIBUTES_KEY => [
147+
'stock_item' => $this->getStockItemData()
148+
]
142149
];
143150

144151
$this->saveProduct($productData);
@@ -778,4 +785,36 @@ public function testTierPrices()
778785
$response = $this->deleteProduct($productData[ProductInterface::SKU]);
779786
$this->assertTrue($response);
780787
}
788+
789+
/**
790+
* @return array
791+
*/
792+
private function getStockItemData()
793+
{
794+
return [
795+
StockItemInterface::IS_IN_STOCK => 1,
796+
StockItemInterface::QTY => 100500,
797+
StockItemInterface::IS_QTY_DECIMAL => 1,
798+
StockItemInterface::SHOW_DEFAULT_NOTIFICATION_MESSAGE => 0,
799+
StockItemInterface::USE_CONFIG_MIN_QTY => 0,
800+
StockItemInterface::USE_CONFIG_MIN_SALE_QTY => 0,
801+
StockItemInterface::MIN_QTY => 1,
802+
StockItemInterface::MIN_SALE_QTY => 1,
803+
StockItemInterface::MAX_SALE_QTY => 100,
804+
StockItemInterface::USE_CONFIG_MAX_SALE_QTY => 0,
805+
StockItemInterface::USE_CONFIG_BACKORDERS => 0,
806+
StockItemInterface::BACKORDERS => 0,
807+
StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY => 0,
808+
StockItemInterface::NOTIFY_STOCK_QTY => 0,
809+
StockItemInterface::USE_CONFIG_QTY_INCREMENTS => 0,
810+
StockItemInterface::QTY_INCREMENTS => 0,
811+
StockItemInterface::USE_CONFIG_ENABLE_QTY_INC => 0,
812+
StockItemInterface::ENABLE_QTY_INCREMENTS => 0,
813+
StockItemInterface::USE_CONFIG_MANAGE_STOCK => 1,
814+
StockItemInterface::MANAGE_STOCK => 1,
815+
StockItemInterface::LOW_STOCK_DATE => null,
816+
StockItemInterface::IS_DECIMAL_DIVIDED => 0,
817+
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
818+
];
819+
}
781820
}

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductLinkManagementTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
namespace Magento\GroupedProduct\Api;
88

9+
/**
10+
* @magentoAppIsolation enabled
11+
*/
912
class ProductLinkManagementTest extends \Magento\TestFramework\TestCase\WebapiAbstract
1013
{
1114
const SERVICE_NAME = 'catalogProductLinkManagementV1';

dev/tests/api-functional/testsuite/Magento/GroupedProduct/Api/ProductRepositoryInterfaceTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\GroupedProduct\Api;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
910
use Magento\TestFramework\TestCase\WebapiAbstract;
1011

1112
class ProductRepositoryInterfaceTest extends WebapiAbstract
@@ -126,6 +127,9 @@ public function testProductLinks()
126127
ProductInterface::STATUS => 1,
127128
ProductInterface::TYPE_ID => 'simple',
128129
ProductInterface::ATTRIBUTE_SET_ID => 4,
130+
ProductInterface::EXTENSION_ATTRIBUTES_KEY => [
131+
'stock_item' => $this->getStockItemData()
132+
]
129133
];
130134

131135
$this->saveProduct($productData);
@@ -200,4 +204,36 @@ public function testProductLinks()
200204
$this->deleteProduct("product_simple_500");
201205
$this->deleteProduct("group_product_500");
202206
}
207+
208+
/**
209+
* @return array
210+
*/
211+
private function getStockItemData()
212+
{
213+
return [
214+
StockItemInterface::IS_IN_STOCK => 1,
215+
StockItemInterface::QTY => 100500,
216+
StockItemInterface::IS_QTY_DECIMAL => 1,
217+
StockItemInterface::SHOW_DEFAULT_NOTIFICATION_MESSAGE => 0,
218+
StockItemInterface::USE_CONFIG_MIN_QTY => 0,
219+
StockItemInterface::USE_CONFIG_MIN_SALE_QTY => 0,
220+
StockItemInterface::MIN_QTY => 1,
221+
StockItemInterface::MIN_SALE_QTY => 1,
222+
StockItemInterface::MAX_SALE_QTY => 100,
223+
StockItemInterface::USE_CONFIG_MAX_SALE_QTY => 0,
224+
StockItemInterface::USE_CONFIG_BACKORDERS => 0,
225+
StockItemInterface::BACKORDERS => 0,
226+
StockItemInterface::USE_CONFIG_NOTIFY_STOCK_QTY => 0,
227+
StockItemInterface::NOTIFY_STOCK_QTY => 0,
228+
StockItemInterface::USE_CONFIG_QTY_INCREMENTS => 0,
229+
StockItemInterface::QTY_INCREMENTS => 0,
230+
StockItemInterface::USE_CONFIG_ENABLE_QTY_INC => 0,
231+
StockItemInterface::ENABLE_QTY_INCREMENTS => 0,
232+
StockItemInterface::USE_CONFIG_MANAGE_STOCK => 1,
233+
StockItemInterface::MANAGE_STOCK => 1,
234+
StockItemInterface::LOW_STOCK_DATE => null,
235+
StockItemInterface::IS_DECIMAL_DIVIDED => 0,
236+
StockItemInterface::STOCK_STATUS_CHANGED_AUTO => 0,
237+
];
238+
}
203239
}

0 commit comments

Comments
 (0)