Skip to content

Commit d16e9c8

Browse files
committed
Merge remote-tracking branch 'origin/2.1.8-develop' into 2.1.8-develop-pr19
2 parents be5df16 + 3016ddf commit d16e9c8

File tree

54 files changed

+1986
-374
lines changed

Some content is hidden

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

54 files changed

+1986
-374
lines changed

app/code/Magento/Catalog/Block/Product/View/Attributes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Magento\Framework\Phrase;
1616
use Magento\Framework\Pricing\PriceCurrencyInterface;
1717

18+
/**
19+
* Product attributes block.
20+
*/
1821
class Attributes extends \Magento\Framework\View\Element\Template
1922
{
2023
/**
@@ -59,6 +62,7 @@ public function getProduct()
5962
if (!$this->_product) {
6063
$this->_product = $this->_coreRegistry->registry('product');
6164
}
65+
6266
return $this->_product;
6367
}
6468

@@ -96,6 +100,7 @@ public function getAdditionalData(array $excludeAttr = [])
96100
}
97101
}
98102
}
103+
99104
return $data;
100105
}
101106
}
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Block\Product\View;
7+
8+
use Magento\Framework\DataObject;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Attributes test.
13+
*/
14+
class AttributesTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* Object manager.
18+
*
19+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
20+
*/
21+
private $objectManager;
22+
23+
/**
24+
* Attributes block.
25+
*
26+
* @var \Magento\Catalog\Block\Product\View\Attributes
27+
*/
28+
private $block;
29+
30+
/**
31+
* Context model.
32+
*
33+
* @var \Magento\Catalog\Block\Product\Context|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $context;
36+
37+
/**
38+
* Registry.
39+
*
40+
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $registry;
43+
44+
/**
45+
* Currency price convert/format model.
46+
*
47+
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $priceCurrency;
50+
51+
/**
52+
* Product model.
53+
*
54+
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $product;
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function setUp()
62+
{
63+
$this->context = $this->getMockBuilder(\Magento\Catalog\Block\Product\Context::class)
64+
->disableOriginalConstructor()
65+
->getMock();
66+
67+
$this->registry = $this->getMockBuilder(\Magento\Framework\Registry::class)
68+
->disableOriginalConstructor()
69+
->getMock();
70+
71+
$this->context->expects($this->any())
72+
->method('getRegistry')
73+
->willReturn($this->registry);
74+
75+
$this->priceCurrency = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)
76+
->disableOriginalConstructor()
77+
->setMethods([])
78+
->getMockForAbstractClass();
79+
80+
$this->product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
81+
->disableOriginalConstructor()
82+
->setMethods(['getAttributes', 'hasData'])
83+
->getMock();
84+
85+
$this->block = new \Magento\Catalog\Block\Product\View\Attributes(
86+
$this->context,
87+
$this->registry,
88+
$this->priceCurrency
89+
);
90+
91+
$this->getObjectManager()->setBackwardCompatibleProperty($this->block, '_product', $this->product);
92+
}
93+
94+
/**
95+
* @covers \Magento\Catalog\Block\Product\View\Attributes::getAdditionalData
96+
* @dataProvider getAdditionalDataProvider
97+
*
98+
* @param array $attributes
99+
* @param bool $productHasAttributeValue
100+
* @param array $excludedAttributes
101+
* @param array $expectedResult
102+
* @return void
103+
*/
104+
public function testGetAdditionalData(
105+
$attributes,
106+
$productHasAttributeValue,
107+
$excludedAttributes,
108+
$expectedResult
109+
) {
110+
$this->product->expects(self::once())->method('getAttributes')
111+
->willReturn($attributes);
112+
113+
$this->product->expects(self::any())->method('hasData')
114+
->with('attribute')
115+
->willReturn($productHasAttributeValue);
116+
117+
$this->priceCurrency->expects(self::any())
118+
->method('convertAndFormat')
119+
->withAnyParameters()
120+
->willReturn('test');
121+
122+
self::assertEquals($expectedResult, $this->block->getAdditionalData($excludedAttributes));
123+
}
124+
125+
/**
126+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
127+
*
128+
* @return array
129+
*/
130+
public function getAdditionalDataProvider()
131+
{
132+
return [
133+
'No Attributes' => [
134+
[],
135+
false,
136+
[],
137+
[]
138+
],
139+
'With Invisible On Frontend Attribute' => [
140+
[
141+
$this->prepareAttributeMock(['is_visible_on_front' => false])
142+
],
143+
false,
144+
[],
145+
[]
146+
],
147+
'With Excluded On Frontend Attribute' => [
148+
[
149+
$this->prepareAttributeMock(
150+
[
151+
'attribute_code' => 'excluded_attribute',
152+
'is_visible_on_front' => false
153+
]
154+
)
155+
],
156+
false,
157+
['excluded_attribute'],
158+
[]
159+
],
160+
'Product Has No Attribute Value' => [
161+
[
162+
$this->prepareAttributeMock(
163+
[
164+
'attribute_code' => 'attribute',
165+
'store_label' => 'Test Attribute',
166+
'is_visible_on_front' => true,
167+
]
168+
)
169+
],
170+
false,
171+
[],
172+
[
173+
'attribute' => [
174+
'label' => 'Test Attribute',
175+
'value' => 'N/A',
176+
'code' => 'attribute',
177+
]
178+
]
179+
],
180+
'Product With Null Attribute Value' => [
181+
[
182+
$this->prepareAttributeMock(
183+
[
184+
'attribute_code' => 'attribute',
185+
'store_label' => 'Test Attribute',
186+
'is_visible_on_front' => true,
187+
'value' => null
188+
]
189+
)
190+
],
191+
true,
192+
[],
193+
[
194+
'attribute' => [
195+
'label' => 'Test Attribute',
196+
'value' => 'No',
197+
'code' => 'attribute',
198+
]
199+
]
200+
],
201+
'Product With Price Attribute' => [
202+
[
203+
$this->prepareAttributeMock(
204+
[
205+
'attribute_code' => 'attribute',
206+
'store_label' => 'Test Attribute',
207+
'is_visible_on_front' => true,
208+
'frontend_input' => 'price',
209+
'value' => '2.1'
210+
]
211+
)
212+
],
213+
true,
214+
[],
215+
[
216+
'attribute' => [
217+
'label' => 'Test Attribute',
218+
'value' => 'test',
219+
'code' => 'attribute',
220+
]
221+
]
222+
],
223+
'Product With Phrase Attribute Value' => [
224+
[
225+
$this->prepareAttributeMock(
226+
[
227+
'attribute_code' => 'attribute',
228+
'store_label' => 'Test Attribute',
229+
'is_visible_on_front' => true,
230+
'frontend_input' => 'price',
231+
'value' => __('test')
232+
]
233+
)
234+
],
235+
true,
236+
[],
237+
[
238+
'attribute' => [
239+
'label' => 'Test Attribute',
240+
'value' => 'test',
241+
'code' => 'attribute',
242+
]
243+
]
244+
],
245+
];
246+
}
247+
248+
/**
249+
* Return object manager.
250+
*
251+
* @return ObjectManager
252+
*/
253+
private function getObjectManager()
254+
{
255+
if ($this->objectManager === null) {
256+
$this->objectManager = new ObjectManager($this);
257+
}
258+
259+
return $this->objectManager;
260+
}
261+
262+
/**
263+
* Prepare attribute mock.
264+
*
265+
* @param array $data
266+
* @return \Magento\Eav\Model\Entity\Attribute
267+
*/
268+
private function prepareAttributeMock($data = [])
269+
{
270+
$attributeValue = isset($data['value']) ? $data['value']: null;
271+
272+
/** @var \PHPUnit_Framework_MockObject_MockObject $frontendModel */
273+
$frontendModel = $this->getMockBuilder(
274+
\Magento\Eav\Model\Entity\Attribute\Frontend\DefaultFrontend::class
275+
)
276+
->disableOriginalConstructor()
277+
->setMethods(['getValue'])
278+
->getMock();
279+
280+
$frontendModel->expects(self::any())
281+
->method('getValue')
282+
->willReturn($attributeValue);
283+
284+
$attribute = $this->getObjectManager()->getObject(
285+
\Magento\Eav\Model\Entity\Attribute::class,
286+
['data' => $data]
287+
);
288+
$this->getObjectManager()->setBackwardCompatibleProperty($attribute, '_frontend', $frontendModel);
289+
290+
return $attribute;
291+
}
292+
}

app/code/Magento/Cms/Helper/Page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function prepareResultPage(Action $action, $pageId = null)
156156

157157
$this->_eventManager->dispatch(
158158
'cms_page_render',
159-
['page' => $this->_page, 'controller_action' => $action]
159+
['page' => $this->_page, 'controller_action' => $action, 'request' => $this->_getRequest()]
160160
);
161161

162162
if ($this->_page->getCustomLayoutUpdateXml() && $inRange) {

app/code/Magento/Cms/Setup/UpgradeData.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class UpgradeData implements UpgradeDataInterface
1515
{
16+
/**
17+
* @deprecated
18+
*/
1619
const PRIVACY_COOKIE_PAGE_ID = 4;
1720

1821
/**
@@ -234,7 +237,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
234237
</table>
235238
</div>
236239
EOD;
237-
$privacyAndCookiePolicyPage = $this->createPage()->load(self::PRIVACY_COOKIE_PAGE_ID);
240+
$privacyAndCookiePolicyPage = $this->createPage()->load(
241+
'privacy-policy-cookie-restriction-mode',
242+
'identifier'
243+
);
238244
$privacyAndCookiePolicyPageId = $privacyAndCookiePolicyPage->getId();
239245
if ($privacyAndCookiePolicyPageId) {
240246
$privacyAndCookiePolicyPage->setContent($newPageContent);

0 commit comments

Comments
 (0)