Skip to content

Commit 12298c2

Browse files
author
Karpenko, Oleksandr
committed
MAGETWO-59003: Js file version regenerated in browser on every page reload in develop mode
1 parent 1721d83 commit 12298c2

File tree

1 file changed

+106
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/App/View/Deployment

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\App\View\Deployment;
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\App\State;
11+
use Magento\Framework\App\View\Deployment\Version\Storage\File;
12+
use Magento\Framework\Filesystem\Directory\WriteInterface;
13+
14+
class VersionTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var File
18+
*/
19+
private $fileStorage;
20+
21+
/**
22+
* @var WriteInterface
23+
*/
24+
private $directoryWrite;
25+
26+
/**
27+
* @var string
28+
*/
29+
private $fileName = 'deployed_version.txt';
30+
31+
public function setUp()
32+
{
33+
$this->fileStorage = ObjectManager::getInstance()->create(
34+
File::class,
35+
[
36+
'directoryCode' => DirectoryList::STATIC_VIEW,
37+
'fileName' => $this->fileName
38+
]
39+
);
40+
/** @var \Magento\TestFramework\App\Filesystem $filesystem */
41+
$filesystem = ObjectManager::getInstance()->get(\Magento\TestFramework\App\Filesystem::class);
42+
$this->directoryWrite = $filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
43+
$this->removeDeployVersionFile();
44+
}
45+
46+
/**
47+
* @param string $mode
48+
* @return Version
49+
*/
50+
public function getVersionModel($mode)
51+
{
52+
$appState = ObjectManager::getInstance()->create(
53+
State::class,
54+
[
55+
'mode' => $mode
56+
]
57+
);
58+
return ObjectManager::getInstance()->create(
59+
Version::class,
60+
[
61+
'appState' => $appState
62+
]
63+
);
64+
}
65+
66+
protected function tearDown()
67+
{
68+
$this->removeDeployVersionFile();
69+
}
70+
71+
private function removeDeployVersionFile()
72+
{
73+
if ($this->directoryWrite->isExist($this->fileName)) {
74+
$this->directoryWrite->delete($this->fileName);
75+
}
76+
}
77+
78+
/**
79+
* @expectedException \UnexpectedValueException
80+
*/
81+
public function testGetValueInProductionModeWithoutVersion()
82+
{
83+
$this->assertFalse($this->directoryWrite->isExist($this->fileName));
84+
$this->getVersionModel(State::MODE_PRODUCTION)->getValue();
85+
}
86+
87+
88+
public function testGetValueInDeveloperMode()
89+
{
90+
$this->assertFalse($this->directoryWrite->isExist($this->fileName));
91+
$this->getVersionModel(State::MODE_DEVELOPER)->getValue();
92+
$this->assertTrue($this->directoryWrite->isExist($this->fileName));
93+
}
94+
95+
/**
96+
* Assert that version is not regenerated on each request in developer mode
97+
*/
98+
public function testGetValue()
99+
{
100+
$this->assertFalse($this->directoryWrite->isExist($this->fileName));
101+
$versionModel = $this->getVersionModel(State::MODE_DEVELOPER);
102+
$version = $versionModel->getValue();
103+
$this->assertTrue($this->directoryWrite->isExist($this->fileName));
104+
$this->assertEquals($version, $versionModel->getValue());
105+
}
106+
}

0 commit comments

Comments
 (0)