コード例 #1
0
 /**
  * @param string $targetPath
  * @param string $originalPath
  * @param int $minifyCalls
  * @param int $setContentCalls
  * @param bool $isEnabled
  * @return void
  * @dataProvider processDataProvider
  */
 public function testProcess($targetPath, $originalPath, $minifyCalls, $setContentCalls, $isEnabled)
 {
     $chainMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain')->disableOriginalConstructor()->getMock();
     $chainMock->expects($this->any())->method('getTargetAssetPath')->willReturn($targetPath);
     $chainMock->expects($this->exactly($setContentCalls))->method('setContent')->with('minified content');
     $chainMock->expects($this->any())->method('getContent')->willReturn('original content');
     $chainMock->expects($this->any())->method('getOrigAssetPath')->willReturn($originalPath);
     $this->adapterMock->expects($this->exactly($minifyCalls))->method('minify')->with('original content')->willReturn('minified content');
     $this->minificationMock->expects($this->any())->method('isEnabled')->willReturnMap([['css', $isEnabled]]);
     $this->minificationMock->expects($this->any())->method('isMinifiedFilename')->willReturnMap([['test.min.css', true], ['test.jpeg', false], ['test.css', false]]);
     $this->minify->process($chainMock);
 }
コード例 #2
0
 /**
  * @param int $mtimeOrig
  * @param int $mtimeMinified
  * @param bool $isMinifyExpected
  * @dataProvider minifyMtimeDataProvider
  */
 public function testMinifyMtime($mtimeOrig, $mtimeMinified, $isMinifyExpected)
 {
     $this->prepareAttemptToMinifyMock(true, false);
     $model = new Minified($this->_asset, $this->_logger, $this->_filesystem, $this->_baseUrl, $this->_adapter, Minified::MTIME);
     $this->_rootDir->expects($this->any())->method('getRelativePath')->will($this->returnValueMap([['/foo/bar/test/library.min.js', 'test/library.min.js'], ['/foo/bar/test/library.js', 'test/library.js']]));
     $this->_rootDir->expects($this->once())->method('isExist')->with('test/library.min.js')->will($this->returnValue(false));
     $this->_rootDir->expects($this->once())->method('stat')->with('test/library.js')->will($this->returnValue(['mtime' => $mtimeOrig]));
     $this->_staticViewDir->expects($this->once())->method('stat')->with($this->anything())->will($this->returnValue(['mtime' => $mtimeMinified]));
     if ($isMinifyExpected) {
         $this->_asset->expects($this->once())->method('getContent')->will($this->returnValue('content'));
         $this->_adapter->expects($this->once())->method('minify')->with('content')->will($this->returnValue('mini'));
         $this->_staticViewDir->expects($this->once())->method('writeFile')->with($this->anything(), 'mini');
     } else {
         $this->_adapter->expects($this->never())->method('minify');
     }
     $this->assertStringMatchesFormat('%s_library.min.js', $model->getFilePath());
 }
コード例 #3
0
    public function testGetMinResolverCode()
    {
        $this->minificationMock->expects($this->once())->method('getExcludes')->with('js')->willReturn(['\\.min\\.']);
        $this->minificationMock->expects($this->once())->method('isEnabled')->with('js')->willReturn(true);
        $this->minifyAdapterMock->expects($this->once())->method('minify')->willReturnArgument(0);
        $expected = <<<code
    if (!require.s.contexts._.__load) {
        require.s.contexts._.__load = require.s.contexts._.load;
        require.s.contexts._.load = function(id, url) {
            if (!url.match(/\\.min\\./)) {
                url = url.replace(/(\\.min)?\\.js\$/, '.min.js');
            }
            return require.s.contexts._.__load.apply(require.s.contexts._, [id, url]);
        }
    }

code;
        $this->assertEquals($expected, $this->object->getMinResolverCode());
    }