Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateFileTest.php
Go to the documentation of this file.
1 <?php
8 
17 
18 class TemplateFileTest extends \PHPUnit\Framework\TestCase
19 {
23  protected $resolver;
24 
28  protected $minifier;
29 
33  protected $state;
34 
38  protected $object;
39 
43  private $deploymentConfigMock;
44 
48  protected $assetConfig;
49 
50  protected function setUp()
51  {
52  $this->resolver = $this->getMockForAbstractClass(ResolverInterface::class);
53  $this->minifier = $this->getMockForAbstractClass(MinifierInterface::class);
54  $this->state = $this->createMock(State::class);
55  $this->assetConfig = $this->getMockForAbstractClass(ConfigInterface::class);
56  $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
57  $this->object = new TemplateFile(
58  $this->resolver,
59  $this->minifier,
60  $this->state,
61  $this->assetConfig,
62  $this->deploymentConfigMock
63  );
64  }
65 
70  {
71  $this->assetConfig
72  ->expects($this->once())
73  ->method('isMinifyHtml')
74  ->willReturn(true);
75 
76  $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
77  $expected = 'some/file.ext';
78 
79  $this->state->expects($this->once())
80  ->method('getMode')
81  ->willReturn(State::MODE_DEVELOPER);
82  $this->resolver->expects($this->once())
83  ->method('resolve')
84  ->with(RulePool::TYPE_TEMPLATE_FILE, 'file.ext', 'frontend', $theme, null, 'Magento_Module')
85  ->willReturn($expected);
86 
87  $actual = $this->object->getFile('frontend', $theme, 'file.ext', 'Magento_Module');
88  $this->assertSame($expected, $actual);
89  }
90 
99  public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $forceMinification, $method)
100  {
101  $this->assetConfig
102  ->expects($this->once())
103  ->method('isMinifyHtml')
104  ->willReturn(true);
105 
106  $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
107  $expected = 'some/file.ext';
108  $expectedMinified = '/path/to/minified/some/file.ext';
109 
110  $this->deploymentConfigMock->expects($this->any())
111  ->method('getConfigData')
112  ->willReturnMap([
115  ]);
116  $this->state->expects($this->once())
117  ->method('getMode')
118  ->willReturn($mode);
119  $this->resolver->expects($this->once())
120  ->method('resolve')
121  ->with(RulePool::TYPE_TEMPLATE_FILE, 'file.ext', 'frontend', $theme, null, 'Magento_Module')
122  ->willReturn($expected);
123  $this->minifier->expects($this->once())
124  ->method($method)
125  ->with($expected)
126  ->willReturn($expectedMinified);
127 
128  $actual = $this->object->getFile('frontend', $theme, 'file.ext', 'Magento_Module');
129  $this->assertSame($expectedMinified, $actual);
130  }
131 
133  {
134  $this->assetConfig
135  ->expects($this->once())
136  ->method('isMinifyHtml')
137  ->willReturn(false);
138 
139  $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
140  $expected = 'some/file.ext';
141 
142  $this->resolver->expects($this->once())
143  ->method('resolve')
144  ->with(RulePool::TYPE_TEMPLATE_FILE, 'file.ext', 'frontend', $theme, null, 'Magento_Module')
145  ->willReturn($expected);
146 
147  $this->state->expects($this->never())
148  ->method('getMode');
149 
150  $actual = $this->object->getFile('frontend', $theme, 'file.ext', 'Magento_Module');
151  $this->assertSame($expected, $actual);
152  }
153 
159  public function getMinifiedDataProvider()
160  {
161  return [
162  'default with on demand' => [State::MODE_DEFAULT, 1, 1, 'getMinified'],
163  'default without on demand' => [State::MODE_DEFAULT, 0, 0, 'getMinified'],
164  'production with on demand' => [State::MODE_PRODUCTION, 1, 0, 'getMinified'],
165  'production without on demand' => [State::MODE_PRODUCTION, 0, 0, 'getPathToMinified'],
166  'production without on demand with minified' => [State::MODE_PRODUCTION, 0, 1, 'getMinified'],
167  ];
168  }
169 }
testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $forceMinification, $method)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
$method
Definition: info.phtml:13
$theme