Skip to content

Commit 946c273

Browse files
committed
MAGETWO-66047: Remove usages of unserialize in module Magento/Framework/App/PageCache
1 parent aa27856 commit 946c273

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

lib/internal/Magento/Framework/App/PageCache/Identifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function getValue()
4545
$this->request->get(\Magento\Framework\App\Response\Http::COOKIE_VARY_STRING)
4646
?: $this->context->getVaryString()
4747
];
48-
return md5(serialize($data));
48+
return md5(json_encode($data));
4949
}
5050
}

lib/internal/Magento/Framework/App/Test/Unit/PageCache/IdentifierTest.php

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,29 @@
1313

1414
class IdentifierTest extends \PHPUnit_Framework_TestCase
1515
{
16-
/** Test value for cache vary string */
16+
/**
17+
* Test value for cache vary string
18+
*/
1719
const VARY = '123';
1820

19-
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
21+
/**
22+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
23+
*/
2024
private $objectManager;
2125

22-
/** @var Context */
26+
/**
27+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
28+
*/
2329
private $contextMock;
2430

25-
/** @var HttpRequest */
31+
/**
32+
* @var HttpRequest|\PHPUnit_Framework_MockObject_MockObject
33+
*/
2634
private $requestMock;
2735

28-
/** @var Identifier */
36+
/**
37+
* @var Identifier
38+
*/
2939
private $model;
3040

3141
/**
@@ -48,6 +58,7 @@ protected function setUp()
4858
'context' => $this->contextMock,
4959
]
5060
);
61+
return parent::setUp();
5162
}
5263

5364
public function testSecureDifferentiator()
@@ -115,4 +126,35 @@ public function trueFalseDataProvider()
115126
{
116127
return [[true], [false]];
117128
}
129+
130+
/**
131+
* Test get identifier value
132+
*/
133+
public function testGetValue()
134+
{
135+
$this->requestMock->expects($this->any())
136+
->method('isSecure')
137+
->will($this->returnValue(true));
138+
139+
$this->requestMock->expects($this->any())
140+
->method('getUriString')
141+
->willReturn('http://example.com/path1/');
142+
143+
$this->contextMock->expects($this->any())
144+
->method('getVaryString')
145+
->will($this->returnValue(self::VARY));
146+
147+
$this->assertEquals(
148+
md5(
149+
json_encode(
150+
[
151+
true,
152+
'http://example.com/path1/',
153+
self::VARY
154+
]
155+
)
156+
),
157+
$this->model->getValue()
158+
);
159+
}
118160
}

0 commit comments

Comments
 (0)