Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DebugHintsTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Developer\Model\TemplateEngine\Decorator\DebugHintsFactory;
11 
12 class DebugHintsTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $scopeConfigMock;
18 
22  protected $storeManager;
23 
27  protected $devHelperMock;
28 
32  protected $debugHintsFactory;
33 
37  protected function setUp()
38  {
39  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
40  ->getMockForAbstractClass();
41 
42  $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
43  ->getMockForAbstractClass();
44 
45  $this->devHelperMock = $this->getMockBuilder(\Magento\Developer\Helper\Data::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->debugHintsFactory = $this->getMockBuilder(
50  \Magento\Developer\Model\TemplateEngine\Decorator\DebugHintsFactory::class
51  )
52  ->setMethods(['create'])
53  ->disableOriginalConstructor()
54  ->getMock();
55  }
56 
63  public function testAfterCreateActive(
64  $debugHintsPath,
65  $showBlockHints,
66  $debugHintsWithParam,
67  $debugHintsParameter
68  ) {
69  $this->devHelperMock->expects($this->once())
70  ->method('isDevAllowed')
71  ->willReturn(true);
72 
73  $this->setupConfigFixture($debugHintsPath, true, $showBlockHints);
74 
75  $engine = $this->createMock(\Magento\Framework\View\TemplateEngineInterface::class);
76 
77  $debugHintsDecorator = $this->getMockBuilder(
78  \Magento\Developer\Model\TemplateEngine\Decorator\DebugHints::class
79  )
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  $this->debugHintsFactory->expects($this->once())
84  ->method('create')
85  ->with([
86  'subject' => $engine,
87  'showBlockHints' => $showBlockHints,
88  ])
89  ->willReturn($debugHintsDecorator);
90 
91  $subjectMock = $this->getMockBuilder(\Magento\Framework\View\TemplateEngineFactory::class)
92  ->disableOriginalConstructor()
93  ->getMock();
94 
95  $this->httpMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
96 
97  $debugHints = new DebugHints(
98  $this->scopeConfigMock,
99  $this->storeManager,
100  $this->devHelperMock,
101  $this->debugHintsFactory,
102  $debugHintsPath,
103  $this->httpMock,
104  $debugHintsWithParam,
105  $debugHintsParameter
106  );
107 
108  $this->assertEquals($debugHintsDecorator, $debugHints->afterCreate($subjectMock, $engine));
109  }
110 
115  {
116  return [
117  ['dev/debug/template_hints_storefront', false, false, null],
118  ['dev/debug/template_hints_storefront', true, false, null],
119  ['dev/debug/template_hints_admin', false, false, null],
120  ['dev/debug/template_hints_admin', true, false, null],
121  ];
122  }
123 
131  public function testAfterCreateInactive(
132  $debugHintsPath,
133  $isDevAllowed,
134  $showTemplateHints,
135  $debugHintsWithParam,
136  $debugHintsParameter
137  ) {
138  $this->devHelperMock->expects($this->any())
139  ->method('isDevAllowed')
140  ->willReturn($isDevAllowed);
141 
142  $this->setupConfigFixture($debugHintsPath, $showTemplateHints, true);
143 
144  $engine = $this->createMock(\Magento\Framework\View\TemplateEngineInterface::class);
145 
146  $subjectMock = $this->getMockBuilder(\Magento\Framework\View\TemplateEngineFactory::class)
147  ->disableOriginalConstructor()
148  ->getMock();
149 
150  $this->httpMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
151 
152  $debugHints = new DebugHints(
153  $this->scopeConfigMock,
154  $this->storeManager,
155  $this->devHelperMock,
156  $this->debugHintsFactory,
157  $debugHintsPath,
158  $this->httpMock,
159  $debugHintsWithParam,
160  $debugHintsParameter
161  );
162 
163  $this->assertSame($engine, $debugHints->afterCreate($subjectMock, $engine));
164  }
165 
170  {
171  return [
172  ['dev/debug/template_hints_storefront', false, false, false, null],
173  ['dev/debug/template_hints_storefront', false, true, false, null],
174  ['dev/debug/template_hints_storefront', true, false, false, null],
175  ['dev/debug/template_hints_admin', false, false, false, null],
176  ['dev/debug/template_hints_admin', false, true, false, null],
177  ['dev/debug/template_hints_admin', true, false, false, null],
178  ];
179  }
180 
189  protected function setupConfigFixture($debugHintsPath, $showTemplateHints, $showBlockHints)
190  {
191  $storeCode = 'default';
192  $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
193  $storeMock->expects($this->once())
194  ->method('getCode')
195  ->willReturn($storeCode);
196  $this->storeManager->expects($this->once())
197  ->method('getStore')
198  ->willReturn($storeMock);
199 
200  $this->scopeConfigMock->expects($this->atLeastOnce())
201  ->method('getValue')
202  ->willReturnMap([
203  [
204  $debugHintsPath,
206  $storeCode,
207  $showTemplateHints,
208  ],
209  [
212  $storeCode,
213  $showBlockHints
214  ]
215  ]);
216  }
217 }
testAfterCreateInactive( $debugHintsPath, $isDevAllowed, $showTemplateHints, $debugHintsWithParam, $debugHintsParameter)
$storeCode
Definition: indexer.php:15
setupConfigFixture($debugHintsPath, $showTemplateHints, $showBlockHints)
testAfterCreateActive( $debugHintsPath, $showBlockHints, $debugHintsWithParam, $debugHintsParameter)