Skip to content

Commit 3cc19fe

Browse files
author
Melnikov, Igor(imelnikov)
committed
Merge pull request #472 from magento-extensibility/MAGETWO-50657-static-files-are-not-loaded
[Extensibility] Magetwo 50657 static files are not loaded
2 parents ea652b2 + 02b4c31 commit 3cc19fe

File tree

6 files changed

+268
-25
lines changed

6 files changed

+268
-25
lines changed

app/code/Magento/Deploy/Console/Command/DeployStaticContentCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\Validator\Locale;
1818

1919
/**
20-
* Command for deploy static content
20+
* Deploy static content command
2121
*/
2222
class DeployStaticContentCommand extends Command
2323
{

app/code/Magento/Deploy/Console/Command/SetModeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\App\State;
1818

1919
/**
20-
* Command for change the Magento mode
20+
* Command to set application mode
2121
*/
2222
class SetModeCommand extends Command
2323
{

app/code/Magento/Deploy/Console/Command/ShowModeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Framework\App\State;
1515

1616
/**
17-
* Command for change the Magento mode
17+
* Command to show application mode
1818
*/
1919
class ShowModeCommand extends Command
2020
{

app/code/Magento/Deploy/Model/Filesystem.php

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
*/
66
namespace Magento\Deploy\Model;
77

8+
use Symfony\Component\Console\Output\OutputInterface;
89
use Magento\Framework\App\State;
910
use Magento\Framework\App\DeploymentConfig\Writer;
1011
use Magento\Framework\App\Filesystem\DirectoryList;
1112
use Magento\Framework\Exception\LocalizedException;
12-
use Symfony\Component\Console\Output\OutputInterface;
13+
use Magento\User\Model\ResourceModel\User\Collection as UserCollection;
1314

1415
/**
15-
* Class Filesystem
16+
* Generate static files, compile; clear var/generation, var/di/, var/view_preprocessed and pub/static directories
1617
*
17-
* A class to manage Magento modes
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1819
*/
1920
class Filesystem
2021
{
@@ -37,33 +38,56 @@ class Filesystem
3738
*/
3839
const DEFAULT_THEME = 'Magento/blank';
3940

40-
/** @var \Magento\Framework\App\DeploymentConfig\Writer */
41+
/**
42+
* @var \Magento\Framework\App\DeploymentConfig\Writer
43+
*/
4144
private $writer;
4245

43-
/** @var \Magento\Framework\App\DeploymentConfig\Reader */
46+
/**
47+
* @var \Magento\Framework\App\DeploymentConfig\Reader
48+
*/
4449
private $reader;
4550

46-
/** @var \Magento\Framework\ObjectManagerInterface */
51+
/**
52+
* @var \Magento\Framework\ObjectManagerInterface
53+
*/
4754
private $objectManager;
4855

49-
/** @var \Magento\Framework\Filesystem */
56+
/**
57+
* @var \Magento\Framework\Filesystem
58+
*/
5059
private $filesystem;
5160

52-
/** @var \Magento\Framework\App\Filesystem\DirectoryList */
61+
/**
62+
* @var \Magento\Framework\App\Filesystem\DirectoryList
63+
*/
5364
private $directoryList;
5465

55-
/** @var \Magento\Framework\Filesystem\Driver\File */
66+
/**
67+
* @var \Magento\Framework\Filesystem\Driver\File
68+
*/
5669
private $driverFile;
5770

58-
/** @var \Magento\Store\Model\Config\StoreView */
71+
/**
72+
* @var \Magento\Store\Model\Config\StoreView
73+
*/
5974
private $storeView;
6075

61-
/** @var \Magento\Framework\ShellInterface */
76+
/**
77+
* @var \Magento\Framework\ShellInterface
78+
*/
6279
private $shell;
6380

64-
/** @var string */
81+
/**
82+
* @var string
83+
*/
6584
private $functionCallPath;
6685

86+
/**
87+
* @var UserCollection
88+
*/
89+
private $userCollection;
90+
6791
/**
6892
* @param \Magento\Framework\App\DeploymentConfig\Writer $writer
6993
* @param \Magento\Framework\App\DeploymentConfig\Reader $reader
@@ -104,7 +128,7 @@ public function __construct(
104128
public function regenerateStatic(
105129
OutputInterface $output
106130
) {
107-
// Сlean up /var/generation, /var/di/, /var/view_preprocessed and /pub/static directories
131+
// Сlear var/generation, var/di/, var/view_preprocessed and pub/static directories
108132
$this->cleanupFilesystem(
109133
[
110134
DirectoryList::CACHE,
@@ -129,12 +153,12 @@ public function regenerateStatic(
129153
protected function deployStaticContent(
130154
OutputInterface $output
131155
) {
132-
$output->writeln('Starting static content deployment');
156+
$output->writeln('Starting deployment of static content');
133157
$cmd = $this->functionCallPath . 'setup:static-content:deploy '
134-
. implode(' ', $this->storeView->retrieveLocales());
158+
. implode(' ', $this->getUsedLocales());
135159

136160
/**
137-
* @todo build a solution that does not depend on exec
161+
* @todo eliminate exec
138162
*/
139163
try {
140164
$execOutput = $this->shell->execute($cmd);
@@ -143,11 +167,55 @@ protected function deployStaticContent(
143167
throw $e;
144168
}
145169
$output->writeln($execOutput);
146-
$output->writeln('Static content deployment complete');
170+
$output->writeln('Deployment of static content complete');
147171
}
148172

149173
/**
150-
* Runs code multi-tenant compiler to generate code and DI information
174+
* Get admin user locales
175+
*
176+
* @return []string
177+
*/
178+
private function getAdminUserInterfaceLocales()
179+
{
180+
$locales = [];
181+
foreach ($this->getUserCollection() as $user) {
182+
$locales[] = $user->getInterfaceLocale();
183+
}
184+
return $locales;
185+
}
186+
187+
/**
188+
* Get used store and admin user locales
189+
*
190+
* @return []string
191+
*/
192+
private function getUsedLocales()
193+
{
194+
$usedLocales = array_merge(
195+
$this->storeView->retrieveLocales(),
196+
$this->getAdminUserInterfaceLocales()
197+
);
198+
return array_unique($usedLocales);
199+
}
200+
201+
/**
202+
* Get user collection
203+
*
204+
* @return UserCollection
205+
* @deprecated
206+
*/
207+
private function getUserCollection()
208+
{
209+
if (!($this->userCollection instanceof UserCollection)) {
210+
return \Magento\Framework\App\ObjectManager::getInstance()->get(
211+
UserCollection::class
212+
);
213+
}
214+
return $this->userCollection;
215+
}
216+
217+
/**
218+
* Runs compiler
151219
*
152220
* @param OutputInterface $output
153221
* @return void
@@ -169,7 +237,7 @@ protected function compile(OutputInterface $output)
169237
* exec command is necessary for now to isolate the autoloaders in the compiler from the memory state
170238
* of this process, which would prevent some classes from being generated
171239
*
172-
* @todo build a solution that does not depend on exec
240+
* @todo eliminate exec
173241
*/
174242
try {
175243
$execOutput = $this->shell->execute($cmd);
@@ -222,7 +290,6 @@ public function cleanupFilesystem($directoryCodeList)
222290
* @param int $dirPermissions
223291
* @param int $filePermissions
224292
* @return void
225-
*
226293
* @deprecated
227294
*/
228295
protected function changePermissions($directoryCodeList, $dirPermissions, $filePermissions)
@@ -242,7 +309,6 @@ protected function changePermissions($directoryCodeList, $dirPermissions, $fileP
242309
* Chenge permissions on static resources
243310
*
244311
* @return void
245-
*
246312
* @deprecated
247313
*/
248314
public function lockStaticResources()
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\Model;
7+
8+
class FilesystemTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Store\Model\Config\StoreView
12+
*/
13+
private $storeViewMock;
14+
15+
/**
16+
* @var \Magento\Framework\ShellInterface
17+
*/
18+
private $shellMock;
19+
20+
/**
21+
* @var \Magento\User\Model\ResourceModel\User\Collection
22+
*/
23+
private $userCollectionMock;
24+
25+
/**
26+
* @var \Symfony\Component\Console\Output\OutputInterface
27+
*/
28+
private $outputMock;
29+
30+
/**
31+
* @var \Magento\Framework\Filesystem
32+
*/
33+
private $filesystemMock;
34+
35+
/**
36+
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
37+
*/
38+
private $directoryWriteMock;
39+
40+
/**
41+
* @var \Magento\Framework\ObjectManagerInterface
42+
*/
43+
private $objectManagerMock;
44+
45+
/**
46+
* @var \Magento\Deploy\Model\Filesystem
47+
*/
48+
private $filesystem;
49+
50+
/**
51+
* @var string
52+
*/
53+
private $cmdPrefix;
54+
55+
protected function setUp()
56+
{
57+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
58+
59+
$this->storeViewMock = $this->getMock(
60+
\Magento\Store\Model\Config\StoreView::class,
61+
[],
62+
[],
63+
'',
64+
false
65+
);
66+
$this->shellMock = $this->getMock(
67+
\Magento\Framework\ShellInterface::class,
68+
[],
69+
[],
70+
'',
71+
false
72+
);
73+
$this->userCollectionMock = $this->getMock(
74+
\Magento\User\Model\ResourceModel\User\Collection::class,
75+
[],
76+
[],
77+
'',
78+
false
79+
);
80+
$this->outputMock = $this->getMock(
81+
\Symfony\Component\Console\Output\OutputInterface::class,
82+
[],
83+
[],
84+
'',
85+
false
86+
);
87+
$this->objectManagerMock = $this->getMock(
88+
\Magento\Framework\ObjectManagerInterface::class,
89+
[],
90+
[],
91+
'',
92+
false
93+
);
94+
$this->filesystemMock = $this->getMock(
95+
\Magento\Framework\Filesystem::class,
96+
[],
97+
[],
98+
'',
99+
false
100+
);
101+
$this->directoryWriteMock = $this->getMock(
102+
\Magento\Framework\Filesystem\Directory\WriteInterface::class,
103+
[],
104+
[],
105+
'',
106+
false
107+
);
108+
$this->filesystemMock->expects($this->any())
109+
->method('getDirectoryWrite')
110+
->willReturn($this->directoryWriteMock);
111+
$this->filesystem = $objectManager->getObject(
112+
\Magento\Deploy\Model\Filesystem::class,
113+
[
114+
'storeView' => $this->storeViewMock,
115+
'shell' => $this->shellMock,
116+
'filesystem' => $this->filesystemMock
117+
]
118+
);
119+
120+
$userCollection = new \ReflectionProperty(\Magento\Deploy\Model\Filesystem::class, 'userCollection');
121+
$userCollection->setAccessible(true);
122+
$userCollection->setValue($this->filesystem, $this->userCollectionMock);
123+
124+
$this->cmdPrefix = 'php -f '. BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento ';
125+
}
126+
127+
public function testRegenerateStatic()
128+
{
129+
$storeLocales = ['fr_FR', 'de_DE', 'nl_NL'];
130+
$adminUserInterfaceLocales = ['de_DE', 'en_US'];
131+
$this->storeViewMock->expects($this->once())
132+
->method('retrieveLocales')
133+
->willReturn($storeLocales);
134+
$userMock = $this->getMock(
135+
\Magento\User\Model\User::class,
136+
[],
137+
[],
138+
'',
139+
false
140+
);
141+
$userMock->expects($this->once())
142+
->method('getInterfaceLocale')
143+
->willReturn('en_US');
144+
$this->userCollectionMock->expects($this->once())
145+
->method('getIterator')
146+
->willReturn(new \ArrayIterator([$userMock]));
147+
148+
$usedLocales = array_unique(
149+
array_merge($storeLocales, $adminUserInterfaceLocales)
150+
);
151+
$staticContentDeployCmd = $this->cmdPrefix . 'setup:static-content:deploy '
152+
. implode(' ', $usedLocales);
153+
$setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile';
154+
$this->shellMock->expects($this->at(0))
155+
->method('execute')
156+
->with($staticContentDeployCmd);
157+
$this->shellMock->expects($this->at(1))
158+
->method('execute')
159+
->with($setupDiCompileCmd);
160+
161+
$this->outputMock->expects($this->at(0))
162+
->method('writeln')
163+
->with('Starting deployment of static content');
164+
$this->outputMock->expects($this->at(2))
165+
->method('writeln')
166+
->with('Deployment of static content complete');
167+
$this->outputMock->expects($this->at(3))
168+
->method('writeln')
169+
->with('Starting compilation');
170+
$this->outputMock->expects($this->at(5))
171+
->method('writeln')
172+
->with('Compilation complete');
173+
174+
$this->filesystem->regenerateStatic($this->outputMock);
175+
}
176+
}

0 commit comments

Comments
 (0)