Skip to content

Commit

Permalink
Merge pull request #402 from magento-frontend/bugs-pr-2.0
Browse files Browse the repository at this point in the history
Frontend Bugs - 2.0.11
- MAGETWO-57509 [Backport] - [GitHub] Javascript Bundling produces huge 13MB js files #4506 - for 2.0
- MAGETWO-56076 [Backport] Versioning of static files (CSS, JS, Fonts, Images, etc.) doesn't enabled by default - for 2.0
  • Loading branch information
slavvka authored Sep 20, 2016
2 parents 37c230b + c739a5d commit 89c1723
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 95 deletions.
21 changes: 7 additions & 14 deletions app/code/Magento/Deploy/Model/DeployManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public function deploy()
{
if ($this->idDryRun) {
$this->output->writeln('Dry run. Nothing will be recorded to the target directory.');
} else {
$version = (new \DateTime())->getTimestamp();
$this->versionStorage->save($version);
}

/** @var DeployStrategyProvider $strategyProvider */
Expand All @@ -133,7 +136,10 @@ public function deploy()
}

$this->minifyTemplates();
$this->saveDeployedVersion();

if (!$this->idDryRun) {
$this->output->writeln("New version of deployed files: {$version}");
}

return $result;
}
Expand Down Expand Up @@ -197,17 +203,4 @@ private function getProcessesAmount()
{
return isset($this->options[Options::JOBS_AMOUNT]) ? (int)$this->options[Options::JOBS_AMOUNT] : 0;
}

/**
* Save version of deployed files
* @return void
*/
private function saveDeployedVersion()
{
if (!$this->idDryRun) {
$version = (new \DateTime())->getTimestamp();
$this->output->writeln("New version of deployed files: {$version}");
$this->versionStorage->save($version);
}
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Theme/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ Disallow: /*SID=
</allowed_resources>
</media_storage_configuration>
</system>
<dev>
<static>
<sign>1</sign>
</static>
</dev>
</default>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testSaveFilePlaceholder($model)
public function testGetUrlPlaceholder($model)
{
$this->assertStringMatchesFormat(
'http://localhost/pub/static/frontend/%s/Magento_Catalog/images/product/placeholder/image.jpg',
'http://localhost/pub/static/%s/frontend/%s/Magento_Catalog/images/product/placeholder/image.jpg',
$model->getUrl()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testGetConfig()
public function testGetConfigCssUrls()
{
$config = $this->_model->getConfig();
$publicPathPattern = 'http://localhost/pub/static/adminhtml/Magento/backend/en_US/mage/%s';
$publicPathPattern = 'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/mage/%s';
$this->assertStringMatchesFormat($publicPathPattern, $config->getPopupCss());
$this->assertStringMatchesFormat($publicPathPattern, $config->getContentCss());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testGetFilesCollection()
$this->assertInstanceOf('Magento\Framework\DataObject', $item);
$this->assertStringEndsWith('/1.swf', $item->getUrl());
$this->assertStringMatchesFormat(
'http://%s/static/adminhtml/%s/%s/Magento_Cms/images/placeholder_thumbnail.jpg',
'http://%s/static/%s/adminhtml/%s/%s/Magento_Cms/images/placeholder_thumbnail.jpg',
$item->getThumbUrl()
);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public function cssDirectiveDataProvider()
* @magentoComponentsDir Magento/Email/Model/_files/design
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
* @magentoConfigFixture default_store dev/static/sign 0
* @dataProvider inlinecssDirectiveDataProvider
*
* @param string $templateText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testGetProcessedTemplate()
->getArea(Area::AREA_FRONTEND)
->load();

$expectedViewUrl = 'static/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico';
$expectedViewUrl = '/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico';
$this->model->setDesignConfig([
'area' => 'frontend',
'store' => $this->objectManager->get('Magento\Store\Model\StoreManagerInterface')
Expand Down Expand Up @@ -578,7 +578,6 @@ public function testGetProcessedTemplateSubject()
->getArea(Area::AREA_FRONTEND)
->load();

$expectedViewUrl = 'static/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico';
$this->model->setTemplateSubject('{{view url="Magento_Theme::favicon.ico"}}');
$this->model->setDesignConfig([
'area' => 'frontend',
Expand All @@ -588,10 +587,16 @@ public function testGetProcessedTemplateSubject()
]);

$this->setNotDefaultThemeForFixtureStore();
$this->assertStringEndsNotWith($expectedViewUrl, $this->model->getProcessedTemplateSubject([]));
$this->assertStringMatchesFormat(
'%s/frontend/Magento/luma/en_US/Magento_Theme/favicon.ico',
$this->model->getProcessedTemplateSubject([])
);

$this->setDefaultThemeForFixtureStore();
$this->assertStringEndsWith($expectedViewUrl, $this->model->getProcessedTemplateSubject([]));
$this->assertStringMatchesFormat(
'%s/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico',
$this->model->getProcessedTemplateSubject([])
);
}

/**
Expand All @@ -605,7 +610,7 @@ public function testGetDefaultEmailLogo()
->load();

$this->assertStringEndsWith(
'static/frontend/Magento/luma/en_US/Magento_Email/logo_email.png',
'/frontend/Magento/luma/en_US/Magento_Email/logo_email.png',
$this->model->getDefaultEmailLogo()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ public function testGetUrl()
public function testGetViewFileUrl()
{
$actualResult = $this->_block->getViewFileUrl('css/styles.css');
$this->assertStringMatchesFormat('http://localhost/pub/static/frontend/%s/en_US/css/styles.css', $actualResult);
$this->assertStringMatchesFormat(
'http://localhost/pub/static/%s/frontend/%s/en_US/css/styles.css',
$actualResult
);
}

public function testGetModuleName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testListActionDesign($productId, $expectedDesign)
$this->getRequest()->setParam('id', $productId);
$this->dispatch('review/product/listAction');
$result = $this->getResponse()->getBody();
$this->assertContains("static/frontend/{$expectedDesign}/en_US/Magento_Theme/favicon.ico", $result);
$this->assertContains("/frontend/{$expectedDesign}/en_US/Magento_Theme/favicon.ico", $result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\Variable\Model\Variable\Config'
\Magento\Variable\Model\Variable\Config::class
);
}

public function testGetWysiwygJsPluginSrc()
{
$src = $this->_model->getWysiwygJsPluginSrc();
$this->assertStringStartsWith('http://localhost/pub/static/adminhtml/Magento/backend/en_US/mage/adminhtml/',
$src);
$this->assertStringEndsWith('editor_plugin.js', $src);
$this->assertStringMatchesFormat(
'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/mage/adminhtml/%s/editor_plugin.js',
$src
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public function testGetPluginSettings()
$this->assertArrayHasKey('widget_window_url', $settings);

$jsFilename = $settings['widget_plugin_src'];
$this->assertStringStartsWith('http://localhost/pub/static/adminhtml/Magento/backend/en_US/', $jsFilename);
$this->assertStringEndsWith('editor_plugin.js', $jsFilename);
$this->assertStringMatchesFormat(
'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/%s/editor_plugin.js',
$jsFilename
);

$this->assertInternalType('array', $settings['widget_placeholders']);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Config\Test\Unit;

class ViewFactoryTest extends \PHPUnit_Framework_TestCase
{
const AREA = 'frontend';

/**
* @var \Magento\Framework\Config\ViewFactory
*/
protected $model;

/**
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $objectManager;

/**
* @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $theme;

/**
* @var \Magento\Framework\Config\View|\PHPUnit_Framework_MockObject_MockObject
*/
protected $view;

protected function setUp()
{
$this->objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class);
$this->model = new \Magento\Framework\Config\ViewFactory($this->objectManager);
$this->theme = $this->getMock(\Magento\Framework\View\Design\ThemeInterface::class);
$this->view = $this->getMock(\Magento\Framework\Config\View::class, [], [], '', false);
}

public function testCreate()
{
$this->objectManager->expects($this->once())
->method('create')
->with(\Magento\Framework\Config\View::class, [])
->willReturn($this->view);
$this->assertEquals($this->view, $this->model->create());
}

public function testCreateWithArguments()
{
/** @var \Magento\Theme\Model\View\Design|\PHPUnit_Framework_MockObject_MockObject $design */
$design = $this->getMock(\Magento\Theme\Model\View\Design::class, [], [], '', false);
$design->expects($this->once())
->method('setDesignTheme')
->with($this->theme, self::AREA);

/** @var \Magento\Framework\Config\FileResolver|\PHPUnit_Framework_MockObject_MockObject $fileResolver */
$fileResolver = $this->getMock(\Magento\Framework\Config\FileResolver::class, [], [], '', false);

$valueMap = [
[\Magento\Theme\Model\View\Design::class, [], $design],
[\Magento\Framework\Config\FileResolver::class, ['designInterface' => $design], $fileResolver],
[\Magento\Framework\Config\View::class, ['fileResolver' => $fileResolver], $this->view],
];
$this->objectManager->expects($this->exactly(3))
->method('create')
->willReturnMap($valueMap);

$this->assertEquals($this->view, $this->model->create($this->getArguments()));
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage wrong theme doesn't implement ThemeInterface
*/
public function testCreateException()
{
$this->model->create([
'themeModel' => 'wrong theme',
'area' => self::AREA
]);
}

/**
* @return array
*/
protected function getArguments()
{
return [
'themeModel' => $this->theme,
'area' => self::AREA
];
}
}
30 changes: 28 additions & 2 deletions lib/internal/Magento/Framework/Config/ViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,38 @@ public function __construct(ObjectManagerInterface $objectManager)
}

/**
* Create new view object
*
* @param array $arguments
* @return \Magento\Framework\Config\View
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function create()
public function create(array $arguments = [])
{
$viewConfigArguments = [];

if (isset($arguments['themeModel']) && isset($arguments['area'])) {
if (!($arguments['themeModel'] instanceof \Magento\Framework\View\Design\ThemeInterface)) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('%1 doesn\'t implement ThemeInterface', [$arguments['themeModel']])
);
}
/** @var \Magento\Theme\Model\View\Design $design */
$design = $this->objectManager->create(\Magento\Theme\Model\View\Design::class);
$design->setDesignTheme($arguments['themeModel'], $arguments['area']);
/** @var \Magento\Framework\Config\FileResolver $fileResolver */
$fileResolver = $this->objectManager->create(
\Magento\Framework\Config\FileResolver::class,
[
'designInterface' => $design,
]
);
$viewConfigArguments['fileResolver'] = $fileResolver;
}

return $this->objectManager->create(
'Magento\Framework\Config\View'
\Magento\Framework\Config\View::class,
$viewConfigArguments
);
}
}
8 changes: 2 additions & 6 deletions lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Manager

/** @var array */
public static $availableTypes = [self::ASSET_TYPE_JS, self::ASSET_TYPE_HTML];

/**
* @var Asset\Minification
*/
Expand Down Expand Up @@ -129,7 +130,7 @@ protected function isExcludedFile($filePath, $asset)
/** @var $asset LocalInterface */
$filePathInfo = $this->splitPath($filePath);
if ($filePathInfo && $this->compareModules($filePathInfo, $asset)) {
return $asset->getSourceFile() == $filePathInfo['excludedPath'];
return $asset->getFilePath() == $filePathInfo['excludedPath'];
}
return false;
}
Expand Down Expand Up @@ -239,14 +240,9 @@ protected function isValidType(LocalInterface $asset)
return false;
}

if ($type == self::ASSET_TYPE_HTML) {
return $asset->getModule() !== '';
}

return true;
}


/**
* Flush bundle
*
Expand Down
23 changes: 16 additions & 7 deletions lib/internal/Magento/Framework/View/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,25 @@ public function __construct(
public function getViewConfig(array $params = [])
{
$this->assetRepo->updateDesignParams($params);
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
$currentTheme = $params['themeModel'];
$key = $currentTheme->getCode();
if (isset($this->viewConfigs[$key])) {
return $this->viewConfigs[$key];
$viewConfigParams = [];

if (isset($params['themeModel'])) {
/** @var \Magento\Framework\View\Design\ThemeInterface $currentTheme */
$currentTheme = $params['themeModel'];
$key = $currentTheme->getCode();
if (isset($this->viewConfigs[$key])) {
return $this->viewConfigs[$key];
}
$viewConfigParams['themeModel'] = $currentTheme;
}
$viewConfigParams['area'] = (isset($params['area'])) ? $params['area'] : null;

$config = $this->viewConfigFactory->create();
/** @var \Magento\Framework\Config\View $config */
$config = $this->viewConfigFactory->create($viewConfigParams);

$this->viewConfigs[$key] = $config;
if (isset($key)) {
$this->viewConfigs[$key] = $config;
}
return $config;
}
}
Loading

0 comments on commit 89c1723

Please sign in to comment.