Skip to content

Commit e903e18

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90637' into 2.3-develop-pr13
2 parents f49dbc5 + 7d94018 commit e903e18

File tree

134 files changed

+1616
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1616
-350
lines changed

app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function testBeforeSave($value, $errorMessage = null)
2121
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2222
);
2323
if ($errorMessage !== null) {
24-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
24+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
25+
$this->expectExceptionMessage($errorMessage);
2526
}
2627
$model->setValue($value);
2728
$object = $model->beforeSave();

app/code/Magento/Captcha/Test/Unit/Model/CaptchaFactoryTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ public function testCreateNegative()
5454
$this->returnValue($defaultCaptchaMock)
5555
);
5656

57-
$this->expectException(
58-
'InvalidArgumentException',
59-
'Magento\Captcha\Model\\' . ucfirst(
60-
$captchaType
61-
) . ' does not implement \Magento\Captcha\Model\CaptchaInterface'
62-
);
57+
$this->expectException('InvalidArgumentException');
58+
$this->expectExceptionMessage('Magento\Captcha\Model\\' . ucfirst($captchaType) .
59+
' does not implement \Magento\Captcha\Model\CaptchaInterface');
6360

6461
$this->assertEquals($defaultCaptchaMock, $this->_model->create($captchaType, 'form_id'));
6562
}

app/code/Magento/Catalog/Helper/Product/View.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public function __construct(
110110
private function preparePageMetadata(ResultPage $resultPage, $product)
111111
{
112112
$pageLayout = $resultPage->getLayout();
113-
$pageLayout->createBlock(\Magento\Catalog\Block\Breadcrumbs::class);
114-
115113
$pageConfig = $resultPage->getConfig();
116114

117115
$title = $product->getMetaTitle();
118116
if ($title) {
119117
$pageConfig->getTitle()->set($title);
118+
} else {
119+
$pageConfig->getTitle()->set($product->getName());
120120
}
121121

122122
$keyword = $product->getMetaKeyword();

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/HandlerFactoryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ protected function setUp()
2727

2828
public function testCreateWithInvalidType()
2929
{
30-
$this->expectException(
31-
'\InvalidArgumentException',
32-
\Magento\Framework\DataObject::class . ' does not implement ' .
33-
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class
34-
);
30+
$this->expectException('\InvalidArgumentException');
31+
$this->expectExceptionMessage(\Magento\Framework\DataObject::class . ' does not implement ' .
32+
\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\HandlerInterface::class);
3533
$this->_objectManagerMock->expects($this->never())->method('create');
3634
$this->_model->create(\Magento\Framework\DataObject::class);
3735
}

app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ public function testSaveWithException()
255255
*/
256256
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
257257
{
258-
$this->expectException($expectedException, $expectedExceptionMessage);
258+
$this->expectException($expectedException);
259+
$this->expectExceptionMessage($expectedExceptionMessage);
259260
$categoryId = 5;
260261
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
261262
$this->extensibleDataObjectConverterMock
@@ -284,7 +285,7 @@ public function saveWithValidateCategoryExceptionDataProvider()
284285
return [
285286
[
286287
true, \Magento\Framework\Exception\CouldNotSaveException::class,
287-
'Could not save category: Attribute "ValidateCategoryTest" is required.',
288+
'Could not save category: The "ValidateCategoryTest" attribute is required. Enter and try again.'
288289
], [
289290
'Something went wrong', \Magento\Framework\Exception\CouldNotSaveException::class,
290291
'Could not save category: Something went wrong'

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4848
$tableSwitcherMock
4949
);
5050

51-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
51+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
52+
$this->expectExceptionMessage($exceptionMessage);
5253

5354
$model->execute();
5455
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ protected function setUp()
2727

2828
public function testCreateWithInvalidType()
2929
{
30-
$this->expectException(
31-
'\InvalidArgumentException',
30+
$this->expectException('\InvalidArgumentException');
31+
$this->expectExceptionMessage(
3232
'Magento\Framework\DataObject does not implement \Magento\Catalog\Model\Product\CopyConstructorInterface'
3333
);
3434
$this->_objectManagerMock->expects($this->never())->method('create');
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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\Catalog\Test\Unit\ViewModel\Product;
9+
10+
use Magento\Catalog\Helper\Data as CatalogHelper;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\ViewModel\Product\Breadcrumbs;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
16+
/**
17+
* Unit test for Magento\Catalog\ViewModel\Product\Breadcrumbs.
18+
*/
19+
class BreadcrumbsTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var Breadcrumbs
23+
*/
24+
private $viewModel;
25+
26+
/**
27+
* @var CatalogHelper|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $catalogHelper;
30+
31+
/**
32+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $scopeConfig;
35+
36+
/**
37+
* @var ObjectManager
38+
*/
39+
private $objectManager;
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
protected function setUp()
45+
{
46+
$this->catalogHelper = $this->getMockBuilder(CatalogHelper::class)
47+
->setMethods(['getProduct'])
48+
->disableOriginalConstructor()
49+
->getMock();
50+
51+
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
52+
->setMethods(['getValue', 'isSetFlag'])
53+
->disableOriginalConstructor()
54+
->getMockForAbstractClass();
55+
56+
$this->viewModel = $this->getObjectManager()->getObject(
57+
Breadcrumbs::class,
58+
[
59+
'catalogData' => $this->catalogHelper,
60+
'scopeConfig' => $this->scopeConfig,
61+
]
62+
);
63+
}
64+
65+
/**
66+
* @return void
67+
*/
68+
public function testGetCategoryUrlSuffix()
69+
{
70+
$this->scopeConfig->expects($this->once())
71+
->method('getValue')
72+
->with('catalog/seo/category_url_suffix', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
73+
->willReturn('.html');
74+
75+
$this->assertEquals('.html', $this->viewModel->getCategoryUrlSuffix());
76+
}
77+
78+
/**
79+
* @return void
80+
*/
81+
public function testIsCategoryUsedInProductUrl()
82+
{
83+
$this->scopeConfig->expects($this->once())
84+
->method('isSetFlag')
85+
->with('catalog/seo/product_use_categories', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
86+
->willReturn(false);
87+
88+
$this->assertFalse($this->viewModel->isCategoryUsedInProductUrl());
89+
}
90+
91+
/**
92+
* @dataProvider productDataProvider
93+
*
94+
* @param Product|null $product
95+
* @param string $expectedName
96+
* @return void
97+
*/
98+
public function testGetProductName($product, string $expectedName)
99+
{
100+
$this->catalogHelper->expects($this->atLeastOnce())
101+
->method('getProduct')
102+
->willReturn($product);
103+
104+
$this->assertEquals($expectedName, $this->viewModel->getProductName());
105+
}
106+
107+
/**
108+
* @return array
109+
*/
110+
public function productDataProvider()
111+
{
112+
return [
113+
[$this->getObjectManager()->getObject(Product::class, ['data' => ['name' => 'Test']]), 'Test'],
114+
[null, ''],
115+
];
116+
}
117+
118+
/**
119+
* @return ObjectManager
120+
*/
121+
private function getObjectManager()
122+
{
123+
if (null === $this->objectManager) {
124+
$this->objectManager = new ObjectManager($this);
125+
}
126+
127+
return $this->objectManager;
128+
}
129+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Catalog\ViewModel\Product;
9+
10+
use Magento\Catalog\Helper\Data;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\DataObject;
13+
use Magento\Framework\View\Element\Block\ArgumentInterface;
14+
15+
/**
16+
* Product breadcrumbs view model.
17+
*/
18+
class Breadcrumbs extends DataObject implements ArgumentInterface
19+
{
20+
/**
21+
* Catalog data.
22+
*
23+
* @var Data
24+
*/
25+
private $catalogData;
26+
27+
/**
28+
* @var ScopeConfigInterface
29+
*/
30+
private $scopeConfig;
31+
32+
/**
33+
* @param Data $catalogData
34+
* @param ScopeConfigInterface $scopeConfig
35+
*/
36+
public function __construct(
37+
Data $catalogData,
38+
ScopeConfigInterface $scopeConfig
39+
) {
40+
parent::__construct();
41+
42+
$this->catalogData = $catalogData;
43+
$this->scopeConfig = $scopeConfig;
44+
}
45+
46+
/**
47+
* Returns category URL suffix.
48+
*
49+
* @return mixed
50+
*/
51+
public function getCategoryUrlSuffix()
52+
{
53+
return $this->scopeConfig->getValue(
54+
'catalog/seo/category_url_suffix',
55+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
56+
);
57+
}
58+
59+
/**
60+
* Checks if categories path is used for product URLs.
61+
*
62+
* @return bool
63+
*/
64+
public function isCategoryUsedInProductUrl(): bool
65+
{
66+
return $this->scopeConfig->isSetFlag(
67+
'catalog/seo/product_use_categories',
68+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
69+
);
70+
}
71+
72+
/**
73+
* Returns product name.
74+
*
75+
* @return string
76+
*/
77+
public function getProductName(): string
78+
{
79+
return $this->catalogData->getProduct() !== null
80+
? $this->catalogData->getProduct()->getName()
81+
: '';
82+
}
83+
}

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
<argument name="add_attribute" xsi:type="string">itemscope itemtype="http://schema.org/Product"</argument>
2929
</arguments>
3030
</referenceBlock>
31+
32+
<referenceBlock name="breadcrumbs" template="Magento_Catalog::product/breadcrumbs.phtml">
33+
<arguments>
34+
<argument name="viewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\Breadcrumbs</argument>
35+
</arguments>
36+
</referenceBlock>
37+
3138
<referenceContainer name="content">
3239
<container name="product.info.main" htmlTag="div" htmlClass="product-info-main" before="-">
3340
<container name="product.info.price" label="Product info auxiliary container" htmlTag="div" htmlClass="product-info-price">

0 commit comments

Comments
 (0)