/**
  * @param $groupOne
  * @param $groupTwo
  * @param $expectedResult
  * @dataProvider dataProviderRenderAssets
  */
 public function testRenderAssets($groupOne, $groupTwo, $expectedResult)
 {
     $assetUrl = 'url';
     $assetNoRoutUrl = 'no_route_url';
     $exception = new \Magento\Framework\Exception('my message');
     $assetMockOne = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMockOne->expects($this->exactly(2))->method('getUrl')->willReturn($assetUrl);
     $groupAssetsOne = [$assetMockOne, $assetMockOne];
     $groupMockOne = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock();
     $groupMockOne->expects($this->once())->method('getAll')->willReturn($groupAssetsOne);
     $groupMockOne->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupOne['type']], ['attributes', $groupOne['attributes']], ['ie_condition', $groupOne['condition']]]);
     $assetMockTwo = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMockTwo->expects($this->once())->method('getUrl')->willThrowException($exception);
     $groupAssetsTwo = [$assetMockTwo];
     $groupMockTwo = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock();
     $groupMockTwo->expects($this->once())->method('getAll')->willReturn($groupAssetsTwo);
     $groupMockTwo->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupTwo['type']], ['attributes', $groupTwo['attributes']], ['ie_condition', $groupTwo['condition']]]);
     $this->pageConfigMock->expects($this->once())->method('getAssetCollection')->willReturn($this->assetsCollection);
     $this->assetsCollection->expects($this->once())->method('getGroups')->willReturn([$groupMockOne, $groupMockTwo]);
     $this->assetMinifyServiceMock->expects($this->exactly(2))->method('getAssets')->willReturnArgument(0);
     $this->assetMergeServiceMock->expects($this->exactly(1))->method('getMergedAssets')->willReturnArgument(0);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($assetNoRoutUrl);
     $this->assertEquals($expectedResult, $this->renderer->renderAssets($this->renderer->getAvailableResultGroups()));
 }
 /**
  * @param string $mode
  * @param string $requestedPath
  * @param string $requestedModule
  * @param bool $moduleExists
  * @param string $expectedFile
  * @param array $expectedParams
  *
  * @dataProvider launchDataProvider
  */
 public function testLaunch($mode, $requestedPath, $requestedModule, $moduleExists, $expectedFile, array $expectedParams)
 {
     $this->state->expects($this->once())->method('getMode')->will($this->returnValue($mode));
     $this->state->expects($this->once())->method('setAreaCode')->with('area');
     $this->configLoader->expects($this->once())->method('load')->with('area')->will($this->returnValue(['config']));
     $this->objectManager->expects($this->once())->method('configure')->with(['config']);
     $this->request->expects($this->once())->method('get')->with('resource')->will($this->returnValue($requestedPath));
     $this->moduleList->expects($this->any())->method('has')->with($requestedModule)->will($this->returnValue($moduleExists));
     $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $asset->expects($this->once())->method('getSourceFile')->will($this->returnValue('resource/file.css'));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($expectedFile, $expectedParams)->will($this->returnValue($asset));
     $this->publisher->expects($this->once())->method('publish')->with($asset);
     $this->response->expects($this->once())->method('setFilePath')->with('resource/file.css');
     $this->minifyService->expects($this->once())->method('getAssets')->willReturnArgument(0);
     $this->object->launch();
 }
Beispiel #3
0
 /**
  * @param $contentType
  * @param $attributes
  * @param $ieCondition
  * @param $expectedResult
  * @dataProvider dataProviderRenderAsset
  */
 public function testRenderAsset($contentType, $attributes, $ieCondition, $expectedResult)
 {
     $assetUrl = 'url';
     $assetNoRoutUrl = 'no_route_url';
     $exception = new \Magento\Framework\Exception('my message');
     $assetMock1 = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMock1->expects($this->once())->method('getUrl')->willReturn($assetUrl);
     $assetMock2 = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMock2->expects($this->once())->method('getUrl')->willThrowException($exception);
     $groupAssets = [$assetMock1, $assetMock2];
     $this->pageConfigMock->expects($this->once())->method('getAssetCollection')->willReturn($this->assetsCollection);
     $this->assetsCollection->expects($this->once())->method('getGroups')->willReturn([$this->propertyGroupMock]);
     $this->propertyGroupMock->expects($this->once())->method('getAll')->willReturn($groupAssets);
     $this->propertyGroupMock->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $contentType], ['attributes', $attributes], ['ie_condition', $ieCondition]]);
     $this->assetMinifyServiceMock->expects($this->once())->method('getAssets')->with($groupAssets)->willReturn($groupAssets);
     $this->assetMergeServiceMock->expects($this->once())->method('getMergedAssets')->with($groupAssets, $contentType)->willReturnArgument(0);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($assetNoRoutUrl);
     $this->assertEquals($expectedResult, $this->renderer->renderAssets());
 }