|
7 | 7 | namespace Magento\PageCache\Test\Unit\Model\App;
|
8 | 8 |
|
9 | 9 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
| 10 | +use Magento\PageCache\Model\App\PageCachePlugin; |
10 | 11 | use Magento\PageCache\Model\Cache\Type;
|
11 | 12 |
|
12 | 13 | class PageCachePluginTest extends \PHPUnit_Framework_TestCase
|
13 | 14 | {
|
14 |
| - public function testBeforeSave() |
| 15 | + /** @var PageCachePlugin */ |
| 16 | + private $plugin; |
| 17 | + |
| 18 | + /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\PageCache\Cache*/ |
| 19 | + private $subjectMock; |
| 20 | + |
| 21 | + public function setUp() |
15 | 22 | {
|
16 |
| - /** @var \Magento\PageCache\Model\App\PageCachePlugin $plugin */ |
17 |
| - $plugin = (new ObjectManager($this))->getObject('\Magento\PageCache\Model\App\PageCachePlugin'); |
18 |
| - $subjectMock = $this->getMockBuilder('\Magento\Framework\App\PageCache\Cache') |
| 23 | + $this->plugin = (new ObjectManager($this))->getObject('\Magento\PageCache\Model\App\PageCachePlugin'); |
| 24 | + $this->subjectMock = $this->getMockBuilder('\Magento\Framework\App\PageCache\Cache') |
19 | 25 | ->disableOriginalConstructor()
|
20 | 26 | ->getMock();
|
| 27 | + } |
| 28 | + |
| 29 | + public function testBeforeSaveAddTag() |
| 30 | + { |
21 | 31 | $initTags = ['tag', 'otherTag'];
|
22 |
| - $result = $plugin->beforeSave($subjectMock, 'data', 'identifier', $initTags); |
| 32 | + $result = $this->plugin->beforeSave($this->subjectMock, 'data', 'identifier', $initTags); |
23 | 33 | $tags = isset($result[2]) ? $result[2] : null;
|
24 | 34 | $expectedTags = array_merge($initTags, [Type::CACHE_TAG]);
|
25 | 35 | $this->assertNotNull($tags);
|
26 | 36 | foreach ($expectedTags as $expected) {
|
27 | 37 | $this->assertContains($expected, $tags);
|
28 | 38 | }
|
29 | 39 | }
|
| 40 | + |
| 41 | + public function testBeforeSaveCompression() |
| 42 | + { |
| 43 | + $data = 'raw-data'; |
| 44 | + $expected = PageCachePlugin::COMPRESSION_PREFIX . gzcompress($data); |
| 45 | + $result = $this->plugin->beforeSave($this->subjectMock, $data, 'id'); |
| 46 | + $resultData = $result[0]; |
| 47 | + $this->assertSame($resultData, $expected); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @dataProvider afterSaveDataProvider |
| 52 | + * @param string $dataw |
| 53 | + * @param string $initResult |
| 54 | + */ |
| 55 | + public function testAfterSaveDecompression($data, $initResult) |
| 56 | + { |
| 57 | + $this->assertSame($data, $this->plugin->afterLoad($this->subjectMock, $initResult)); |
| 58 | + } |
| 59 | + |
| 60 | + public function afterSaveDataProvider() |
| 61 | + { |
| 62 | + return [ |
| 63 | + 'Compressed cache' => ['raw-data', PageCachePlugin::COMPRESSION_PREFIX . gzcompress('raw-data')], |
| 64 | + 'Non-compressed cache' => ['raw-data', 'raw-data'] |
| 65 | + ]; |
| 66 | + } |
30 | 67 | }
|
0 commit comments