Skip to content

Commit

Permalink
Merge pull request #559 from magento-tango/MAGETWO-52212
Browse files Browse the repository at this point in the history
[Tango] Bug fixes
  • Loading branch information
Bomko, Alex(abomko) committed Apr 24, 2016
2 parents 9581647 + ced7d08 commit e60afa2
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@ class AssertProductAttributeIsRequired extends AbstractConstraint
* @param CatalogProductEdit $catalogProductEdit
* @param CatalogProductAttribute $attribute
* @param InjectableFixture $product
* @param string $sectionName
* @return void
*/
public function processAssert(
CatalogProductIndex $catalogProductIndex,
CatalogProductEdit $catalogProductEdit,
CatalogProductAttribute $attribute,
InjectableFixture $product
InjectableFixture $product,
$sectionName
) {
$catalogProductIndex->open()->getProductGrid()->searchAndOpen(['sku' => $product->getSku()]);
$productForm = $catalogProductEdit->getProductForm();
if (!$productForm->checkAttributeLabel($attribute)) {
$productForm->openSection('attributes');
$productForm->openSection($sectionName);
}
$productForm->getAttributeElement($attribute)->setValue('');
$catalogProductEdit->getFormPageActions()->save();
$failedFields = $productForm->getRequireNoticeFields($product);
$actualMessage = $failedFields['attributes'][$attribute->getFrontendLabel()];
$validationErrors = $productForm->getSection($sectionName)->getValidationErrors();
$actualMessage = isset($validationErrors[$attribute->getFrontendLabel()])
? $validationErrors[$attribute->getFrontendLabel()]
: '';

\PHPUnit_Framework_Assert::assertEquals(
self::REQUIRE_MESSAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<data name="attribute/data/is_required" xsi:type="string">Yes</data>
<data name="attribute/data/attribute_code" xsi:type="string">attr_text_%isolation%</data>
<data name="attribute/data/default_value_text" xsi:type="string">default_value_text%isolation%</data>
<data name="sectionName" xsi:type="string">attributes</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertProductAttributeIsRequired" />
</variation>
<variation name="CreateProductAttributeEntityFromProductPageTestVariation4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<data name="productAttribute/data/is_searchable" xsi:type="string">Yes</data>
<data name="productAttribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data>
<data name="productAttribute/data/is_comparable" xsi:type="string">Yes</data>
<data name="sectionName" xsi:type="string">product-details</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertProductAttributeInGrid" />
<constraint name="Magento\Catalog\Test\Constraint\AssertAttributeForm" />
<constraint name="Magento\Catalog\Test\Constraint\AssertAddedProductAttributeOnProductForm" />
Expand Down Expand Up @@ -130,6 +131,7 @@
<data name="assertProduct/data/name" xsi:type="string">Product name</data>
<data name="assertProduct/data/sku" xsi:type="string">product-sku</data>
<data name="assertProduct/data/price" xsi:type="string">35</data>
<data name="sectionName" xsi:type="string">product-details</data>
<constraint name="Magento\Catalog\Test\Constraint\AssertProductAttributeInGrid" />
<constraint name="Magento\Catalog\Test\Constraint\AssertAttributeForm" />
<constraint name="Magento\Catalog\Test\Constraint\AssertAddedProductAttributeOnProductForm" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ChosenOption extends SimpleElement
*
* @var string
*/
protected $selectBlock = "//ancestor::body//div[contains(@style,'display: block')]//*[contains(@id,'responseCntoptions')]";
protected $selectBlock = "//ancestor::body//aside[contains(@class,'_show')]//*[contains(@id,'responseCntoptions')]";
// @codingStandardsIgnoreEnd

/**
Expand Down
4 changes: 0 additions & 4 deletions lib/internal/Magento/Framework/View/Asset/Bundle/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ protected function isValidType(LocalInterface $asset)
return false;
}

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

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(ResolverInterface $fallback, AssetMinification $mini
$this->fallback = $fallback;
$this->minification = $minification;
}

/**
* Get path of file after using fallback rules
*
Expand All @@ -51,10 +52,68 @@ public function __construct(ResolverInterface $fallback, AssetMinification $mini
*/
public function resolve($type, $file, $area = null, ThemeInterface $theme = null, $locale = null, $module = null)
{
$fileExtension = pathinfo($file, PATHINFO_EXTENSION);

if ($fileExtension === 'js') {
return $this->resolveJsMinification($type, $file, $area, $theme, $locale, $module);
}

// Leave BC way of resolving
$path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module);

if (!$path && $file != ($newFile = $this->minification->removeMinifiedSign($file))) {
$path = $this->fallback->resolve($type, $newFile, $area, $theme, $locale, $module);
}

return $path;
}

/**
* Get path of file after using fallback rules
*
* @param string $type
* @param string $file
* @param string|null $area
* @param ThemeInterface|null $theme
* @param string|null $locale
* @param string|null $module
* @return string|false
*/
private function resolveJsMinification(
$type,
$file,
$area = null,
ThemeInterface $theme = null,
$locale = null,
$module = null
) {
$path = $this->fallback->resolve($type, $file, $area, $theme, $locale, $module);

/**
* Minified version as priority one
*/
if ($path && $this->minification->isMinifiedFilename($path)) {
return $path;
}

/**
* If minification is disabled - return already found path
*/
if (!$this->minification->isEnabled('js')) {
return $path;
}

/**
* Try to find minified version of file,
* or return already found path
*/
return $this->fallback->resolve(
$type,
$this->minification->addMinifiedSign($file),
$area,
$theme,
$locale,
$module
) ?: $path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ public function testAddAssetWithInvalidType()
$this->assertFalse($this->manager->addAsset($this->asset));
}

public function testAddAssetWithHtmlTypeAndWithoutModule()
{
$this->asset->expects($this->once())
->method('getContentType')
->willReturn('html');
$this->asset->expects($this->once())
->method('getModule')
->willReturn('');

$this->assertFalse($this->manager->addAsset($this->asset));
}

public function testAddAssetWithExcludedFile()
{
$dirRead = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MinificationTest extends \PHPUnit_Framework_TestCase
* @var \Magento\Framework\View\Asset\Minification|\PHPUnit_Framework_MockObject_MockObject
*/
protected $assetMinificationMock;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -98,4 +99,82 @@ public function resolveDataProvider()
[false, 'file.min.css', 'file.min.css', false, false, 'found.css']
];
}

public function testResolveJs()
{
$this->resolverMock
->expects($this->once())
->method('resolve')
->willReturn('/var/test.min.js');
$this->assetMinificationMock->expects($this->once())
->method('isMinifiedFilename')
->willReturn(true);

$this->assertEquals('/var/test.min.js', $this->minification->resolve('', 'test.min.js'));
}

public function testResolveJsWithDisabledMinification()
{
$this->resolverMock
->expects($this->once())
->method('resolve')
->willReturn('/var/test.js');
$this->assetMinificationMock->expects($this->once())
->method('isMinifiedFilename')
->willReturn(false);

$this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js'));
}

public function testResolveJsToFindMinifiedVersion()
{
$this->resolverMock
->expects($this->exactly(2))
->method('resolve')
->willReturnMap(
[
['', 'test.js', null, null, null, null, '/var/test.js'],
['', 'test.min.js', null, null, null, null, '/var/test.min.js']
]
);
$this->assetMinificationMock->expects($this->once())
->method('isMinifiedFilename')
->willReturn(false);
$this->assetMinificationMock->expects($this->once())
->method('isEnabled')
->with('js')
->willReturn(true);
$this->assetMinificationMock->expects($this->once())
->method('addMinifiedSign')
->with('test.js')
->willReturn('test.min.js');

$this->assertEquals('/var/test.min.js', $this->minification->resolve('', 'test.js'));
}

public function testResolveJsToNotFindMinifiedVersion()
{
$this->resolverMock
->expects($this->exactly(2))
->method('resolve')
->willReturnMap(
[
['', 'test.js', null, null, null, null, '/var/test.js'],
['', 'test.min.js', null, null, null, null, false]
]
);
$this->assetMinificationMock->expects($this->once())
->method('isMinifiedFilename')
->willReturn(false);
$this->assetMinificationMock->expects($this->once())
->method('isEnabled')
->with('js')
->willReturn(true);
$this->assetMinificationMock->expects($this->once())
->method('addMinifiedSign')
->with('test.js')
->willReturn('test.min.js');

$this->assertEquals('/var/test.js', $this->minification->resolve('', 'test.js'));
}
}

0 comments on commit e60afa2

Please sign in to comment.