Skip to content

Commit a0178bf

Browse files
Merge pull request #5582 from magento-qwerty/MC-29566
Deprecate SID query parameter-related methods
2 parents 546e536 + 4f9be0e commit a0178bf

File tree

23 files changed

+134
-177
lines changed

23 files changed

+134
-177
lines changed

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* Work with catalog(store, website) urls
17-
*
18-
* @package Magento\Catalog\Model\Template
1917
*/
2018
class Filter extends \Magento\Framework\Filter\Template
2119
{
@@ -30,6 +28,7 @@ class Filter extends \Magento\Framework\Filter\Template
3028
* Whether to allow SID in store directive: NO
3129
*
3230
* @var bool
31+
* @deprecated SID query parameter is not used in URLs anymore.
3332
*/
3433
protected $_useSessionInUrl = false;
3534

@@ -81,10 +80,14 @@ public function setUseAbsoluteLinks($flag)
8180
*
8281
* @param bool $flag
8382
* @return $this
83+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84+
* @deprecated SID query parameter is not used in URLs anymore.
8485
*/
8586
public function setUseSessionInUrl($flag)
8687
{
87-
$this->_useSessionInUrl = $flag;
88+
// phpcs:disable Magento2.Functions.DiscouragedFunction
89+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
90+
8891
return $this;
8992
}
9093

@@ -126,6 +129,7 @@ public function viewDirective($construction)
126129
*/
127130
public function mediaDirective($construction)
128131
{
132+
// phpcs:disable Magento2.Functions.DiscouragedFunction
129133
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
130134
return $this->_storeManager->getStore()
131135
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];

app/code/Magento/Cms/Model/Template/Filter.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@
1010
*/
1111
class Filter extends \Magento\Email\Model\Template\Filter
1212
{
13-
/**
14-
* Whether to allow SID in store directive: AUTO
15-
*
16-
* @var bool
17-
*/
18-
protected $_useSessionInUrl;
19-
20-
/**
21-
* Setter whether SID is allowed in store directive
22-
*
23-
* @param bool $flag
24-
* @return $this
25-
*/
26-
public function setUseSessionInUrl($flag)
27-
{
28-
$this->_useSessionInUrl = (bool)$flag;
29-
return $this;
30-
}
31-
3213
/**
3314
* Retrieve media file URL directive
3415
*

app/code/Magento/Cms/Test/Unit/Model/Template/FilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ public function testMediaDirectiveRelativePath()
119119
* Test using media directive with a URL path including schema.
120120
*
121121
* @covers \Magento\Cms\Model\Template\Filter::mediaDirective
122-
* @expectedException \InvalidArgumentException
123122
*/
124123
public function testMediaDirectiveURL()
125124
{
125+
$this->expectException(\InvalidArgumentException::class);
126+
126127
$baseMediaDir = 'pub/media';
127128
$construction = [
128129
'{{media url="http://wysiwyg/images/image.jpg"}}',

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/ImageTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ public function testValidate()
230230
'name' => 'logo.gif',
231231
];
232232

233+
$this->ioFileSystemMock->expects($this->any())
234+
->method('getPathInfo')
235+
->with($value['name'])
236+
->willReturn([
237+
'filename' => 'logo',
238+
'extension' => 'gif'
239+
]);
240+
233241
$this->attributeMetadataMock->expects($this->once())
234242
->method('getStoreLabel')
235243
->willReturn('File Input Field Label');
@@ -272,6 +280,14 @@ public function testValidateMaxFileSize()
272280
->method('getValue')
273281
->willReturn($maxFileSize);
274282

283+
$this->ioFileSystemMock->expects($this->any())
284+
->method('getPathInfo')
285+
->with($value['name'])
286+
->willReturn([
287+
'filename' => 'logo',
288+
'extension' => 'gif'
289+
]);
290+
275291
$this->attributeMetadataMock->expects($this->once())
276292
->method('getStoreLabel')
277293
->willReturn('File Input Field Label');
@@ -316,6 +332,14 @@ public function testValidateMaxImageWidth()
316332
->method('getValue')
317333
->willReturn($maxImageWidth);
318334

335+
$this->ioFileSystemMock->expects($this->any())
336+
->method('getPathInfo')
337+
->with($value['name'])
338+
->willReturn([
339+
'filename' => 'logo',
340+
'extension' => 'gif'
341+
]);
342+
319343
$this->attributeMetadataMock->expects($this->once())
320344
->method('getStoreLabel')
321345
->willReturn('File Input Field Label');
@@ -360,6 +384,14 @@ public function testValidateMaxImageHeight()
360384
->method('getValue')
361385
->willReturn($maxImageHeight);
362386

387+
$this->ioFileSystemMock->expects($this->any())
388+
->method('getPathInfo')
389+
->with($value['name'])
390+
->willReturn([
391+
'filename' => 'logo',
392+
'extension' => 'gif'
393+
]);
394+
363395
$this->attributeMetadataMock->expects($this->once())
364396
->method('getStoreLabel')
365397
->willReturn('File Input Field Label');

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Filter extends \Magento\Framework\Filter\Template
4545
* Whether to allow SID in store directive: NO
4646
*
4747
* @var bool
48+
* @deprecated SID is not being used as query parameter anymore.
4849
*/
4950
protected $_useSessionInUrl = false;
5051

@@ -264,10 +265,14 @@ public function setUseAbsoluteLinks($flag)
264265
*
265266
* @param bool $flag
266267
* @return $this
268+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
269+
* @deprecated SID query parameter is not used in URLs anymore.
267270
*/
268271
public function setUseSessionInUrl($flag)
269272
{
270-
$this->_useSessionInUrl = $flag;
273+
// phpcs:disable Magento2.Functions.DiscouragedFunction
274+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
275+
271276
return $this;
272277
}
273278

app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,14 @@ public function testProtocolDirectiveWithValidSchema()
475475
}
476476

477477
/**
478-
* @expectedException \Magento\Framework\Exception\MailException
479478
* @throws NoSuchEntityException
480479
*/
481480
public function testProtocolDirectiveWithInvalidSchema()
482481
{
482+
$this->expectException(
483+
\Magento\Framework\Exception\MailException::class
484+
);
485+
483486
$model = $this->getModel();
484487
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
485488
$storeMock->expects($this->once())->method('isCurrentlySecure')->willReturn(true);

app/code/Magento/Newsletter/Test/Unit/Block/Adminhtml/Queue/PreviewTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,17 @@ public function testToHtmlWithId()
178178
);
179179
$this->queueMock->expects($this->once())
180180
->method('load')->willReturnSelf();
181-
$this->queue->expects($this->once())->method('getTemplateId')->willReturn($templateId);
182-
$this->queue->expects($this->once())->method('getNewsletterType')->willReturn($newsletterType);
183-
$this->queue->expects($this->once())->method('getNewsletterText')->willReturn($newsletterText);
184-
$this->queue->expects($this->once())->method('getNewsletterStyles')->willReturn($newsletterStyle);
181+
$this->queueMock->expects($this->once())->method('getTemplateId')->willReturn($templateId);
182+
$this->queueMock->expects($this->once())->method('getNewsletterType')->willReturn($newsletterType);
183+
$this->queueMock->expects($this->once())->method('getNewsletterText')->willReturn($newsletterText);
184+
$this->queueMock->expects($this->once())->method('getNewsletterStyles')->willReturn($newsletterStyle);
185185
$this->templateMock->expects($this->any())
186186
->method('isPlain')
187187
->willReturn(true);
188-
$this->template->expects($this->once())->method('setId')->willReturn($templateId);
189-
$this->template->expects($this->once())->method('setTemplateType')->willReturn($newsletterType);
190-
$this->template->expects($this->once())->method('setTemplateText')->willReturn($newsletterText);
191-
$this->template->expects($this->once())->method('setTemplateStyles')->willReturn($newsletterStyle);
188+
$this->templateMock->expects($this->once())->method('setId')->willReturn($templateId);
189+
$this->templateMock->expects($this->once())->method('setTemplateType')->willReturn($newsletterType);
190+
$this->templateMock->expects($this->once())->method('setTemplateText')->willReturn($newsletterText);
191+
$this->templateMock->expects($this->once())->method('setTemplateStyles')->willReturn($newsletterStyle);
192192
/** @var Store $store */
193193
$this->storeManagerMock->expects($this->once())
194194
->method('getDefaultStoreView')

app/code/Magento/Store/Model/StoreSwitcher/CleanTargetUrl.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
/**
1616
* Remove SID, from_store, store from target url.
17+
*
18+
* Used in store-switching process in HTML frontend.
1719
*/
1820
class CleanTargetUrl implements StoreSwitcherInterface
1921
{
@@ -22,42 +24,27 @@ class CleanTargetUrl implements StoreSwitcherInterface
2224
*/
2325
private $urlHelper;
2426

25-
/**
26-
* @var \Magento\Framework\Session\Generic
27-
*/
28-
private $session;
29-
30-
/**
31-
* @var \Magento\Framework\Session\SidResolverInterface
32-
*/
33-
private $sidResolver;
34-
3527
/**
3628
* @param UrlHelper $urlHelper
37-
* @param \Magento\Framework\Session\Generic $session
38-
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
3929
*/
4030
public function __construct(
41-
UrlHelper $urlHelper,
42-
\Magento\Framework\Session\Generic $session,
43-
\Magento\Framework\Session\SidResolverInterface $sidResolver
31+
UrlHelper $urlHelper
4432
) {
4533
$this->urlHelper = $urlHelper;
46-
$this->session = $session;
47-
$this->sidResolver = $sidResolver;
4834
}
4935

5036
/**
37+
* Generate target URL to switch stores through other mechanism then via URL params.
38+
*
5139
* @param StoreInterface $fromStore store where we came from
5240
* @param StoreInterface $targetStore store where to go to
5341
* @param string $redirectUrl original url requested for redirect after switching
5442
* @return string redirect url
43+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5544
*/
5645
public function switch(StoreInterface $fromStore, StoreInterface $targetStore, string $redirectUrl): string
5746
{
5847
$targetUrl = $redirectUrl;
59-
$sidName = $this->sidResolver->getSessionIdQueryParam($this->session);
60-
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, $sidName);
6148
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, '___from_store');
6249
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, StoreResolverInterface::PARAM_NAME);
6350

app/code/Magento/Theme/Test/Unit/Model/Design/Backend/ImageTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ImageTest extends \PHPUnit\Framework\TestCase
3636
/**
3737
* @inheritdoc
3838
*/
39-
public function setUp()
39+
public function setUp(): void
4040
{
4141
$context = $this->getMockObject(Context::class);
4242
$registry = $this->getMockObject(Registry::class);
@@ -70,7 +70,7 @@ public function setUp()
7070
/**
7171
* @inheritdoc
7272
*/
73-
public function tearDown()
73+
public function tearDown(): void
7474
{
7575
unset($this->imageBackend);
7676
}
@@ -92,12 +92,16 @@ private function getMockObject(string $class, array $methods = []): \PHPUnit\Fra
9292

9393
/**
9494
* Test for beforeSave method with invalid file extension.
95-
*
96-
* @expectedException \Magento\Framework\Exception\LocalizedException
97-
* @expectedExceptionMessage Something is wrong with the file upload settings.
9895
*/
9996
public function testBeforeSaveWithInvalidExtensionFile()
10097
{
98+
$this->expectException(
99+
\Magento\Framework\Exception\LocalizedException::class
100+
);
101+
$this->expectExceptionMessage(
102+
'Something is wrong with the file upload settings.'
103+
);
104+
101105
$invalidFileName = 'fileName.invalidExtension';
102106
$this->imageBackend->setData(
103107
[

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Eav/AttributeTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ public function testCRUD()
6767
/**
6868
* @magentoDataFixture Magento/Catalog/_files/product_attribute.php
6969
*
70-
* @expectedException \Magento\Framework\Exception\LocalizedException
71-
* @expectedExceptionMessage Do not change entity type.
72-
*
7370
* @return void
7471
*/
7572
public function testAttributeSaveWithChangedEntityType(): void
7673
{
74+
$this->expectException(
75+
\Magento\Framework\Exception\LocalizedException::class
76+
);
77+
$this->expectExceptionMessage('Do not change entity type.');
78+
7779
$attribute = $this->attributeRepository->get($this->catalogProductEntityType, 'test_attribute_code_333');
7880
$attribute->setEntityTypeId(1);
7981
$attribute->save();

0 commit comments

Comments
 (0)