123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\View\Test\Unit\Asset;
- use Magento\Framework\App\State;
- use Magento\Framework\View\Asset\Minification;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Unit test for Magento\Framework\View\Asset\Minification
- */
- class MinificationTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\View\Asset\Minification
- */
- protected $minification;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $scopeConfigMock;
- /**
- * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $appStateMock;
- /**
- * {@inheritDoc}
- */
- protected function setUp()
- {
- $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->minification = new Minification(
- $this->scopeConfigMock,
- $this->appStateMock
- );
- }
- /**
- * @return void
- */
- public function testIsEnabled()
- {
- }
- /**
- * @param bool $configFlag
- * @param string $appMode
- * @param bool $result
- * @dataProvider isEnabledDataProvider
- * @return void
- */
- public function testIsAssetMinification($configFlag, $appMode, $result)
- {
- $contentType = 'content type';
- $this->scopeConfigMock
- ->expects($this->any())
- ->method('isSetFlag')
- ->with(
- sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $contentType),
- ScopeInterface::SCOPE_STORE
- )
- ->willReturn($configFlag);
- $this->appStateMock
- ->expects($this->any())
- ->method('getMode')
- ->willReturn($appMode);
- $this->assertEquals($result, $this->minification->isEnabled($contentType));
- }
- /**
- * @return array
- */
- public function isEnabledDataProvider()
- {
- return [
- [false, State::MODE_DEFAULT, false],
- [false, State::MODE_PRODUCTION, false],
- [false, State::MODE_DEVELOPER, false],
- [true, State::MODE_DEFAULT, true],
- [true, State::MODE_PRODUCTION, true],
- [true, State::MODE_DEVELOPER, false]
- ];
- }
- /**
- * @param string $filename
- * @param bool $isEnabled
- * @param string $expected
- * @dataProvider addMinifiedSignDataProvider
- */
- public function testAddMinifiedSign($filename, $isEnabled, $expected)
- {
- $this->scopeConfigMock
- ->expects($this->any())
- ->method('isSetFlag')
- ->willReturn($isEnabled);
- $this->appStateMock
- ->expects($this->any())
- ->method('getMode')
- ->willReturn(State::MODE_DEFAULT);
- $this->assertEquals(
- $expected,
- $this->minification->addMinifiedSign($filename)
- );
- }
- /**
- * @return array
- */
- public function addMinifiedSignDataProvider()
- {
- return [
- ['test.css', true, 'test.min.css'],
- ['test.css', false, 'test.css'],
- ['test.min.css', true, 'test.min.css']
- ];
- }
- /**
- * @param string $filename
- * @param bool $isEnabled
- * @param string $expected
- * @dataProvider removeMinifiedSignDataProvider
- */
- public function testRemoveMinifiedSign($filename, $isEnabled, $expected)
- {
- $this->scopeConfigMock
- ->expects($this->any())
- ->method('isSetFlag')
- ->willReturn($isEnabled);
- $this->appStateMock
- ->expects($this->any())
- ->method('getMode')
- ->willReturn(State::MODE_DEFAULT);
- $this->assertEquals(
- $expected,
- $this->minification->removeMinifiedSign($filename)
- );
- }
- /**
- * @return array
- */
- public function removeMinifiedSignDataProvider()
- {
- return [
- ['test.css', true, 'test.css'],
- ['test.min.css', true, 'test.css'],
- ['test.min.css', false, 'test.min.css']
- ];
- }
- /**
- * @param string $filename
- * @param bool $result
- * @return void
- * @dataProvider isMinifiedFilenameDataProvider
- */
- public function testIsMinifiedFilename($filename, $result)
- {
- $this->assertEquals(
- $result,
- $this->minification->isMinifiedFilename($filename)
- );
- }
- /**
- * @return array
- */
- public function isMinifiedFilenameDataProvider()
- {
- return [
- ['test.min.css', true],
- ['test.mincss', false],
- ['testmin.css', false],
- ['test.css', false],
- ['test.min', false]
- ];
- }
- /**
- * Test dev/js/minify_exclude system value as array
- *
- * @return void
- */
- public function testGetExcludes()
- {
- $this->scopeConfigMock
- ->expects($this->once())
- ->method('getValue')
- ->with('dev/js/minify_exclude')
- ->willReturn([
- 'tiny_mce' => '/tiny_mce/',
- 'some_other_unique_name' => '/tiny_mce2/'
- ]);
- $expected = ['/tiny_mce/', '/tiny_mce2/'];
- $this->assertEquals($expected, $this->minification->getExcludes('js'));
- /** check cache: */
- $this->assertEquals($expected, $this->minification->getExcludes('js'));
- }
- /**
- * Test dev/js/minify_exclude system value backward compatibility when value was a string
- *
- * @param string $value
- * @param array $expectedValue
- * @return void
- *
- * @dataProvider getExcludesTinyMceAsStringDataProvider
- */
- public function testGetExcludesTinyMceAsString(string $value, array $expectedValue)
- {
- $this->scopeConfigMock
- ->expects($this->once())
- ->method('getValue')
- ->with('dev/js/minify_exclude')
- ->willReturn($value);
- $this->assertEquals($expectedValue, $this->minification->getExcludes('js'));
- /** check cache: */
- $this->assertEquals($expectedValue, $this->minification->getExcludes('js'));
- }
- /**
- * @return array
- */
- public function getExcludesTinyMceAsStringDataProvider()
- {
- return [
- ["/tiny_mce/ \n /tiny_mce2/", ['/tiny_mce/', '/tiny_mce2/']],
- ['/tiny_mce/', ['/tiny_mce/']],
- [' /tiny_mce/', ['/tiny_mce/']],
- ];
- }
- }
|