Skip to content

Commit 2ce68ef

Browse files
committed
Merge branch 'MAGETWO-34276' of github.corp.ebay.com:magento-troll/magento2ce into MAGETWO-38540
2 parents d1e489b + ac4934f commit 2ce68ef

File tree

17 files changed

+645
-128
lines changed

17 files changed

+645
-128
lines changed

app/code/Magento/Backend/Block/Template/Context.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Context extends \Magento\Framework\View\Element\Template\Context
6767
* @param \Magento\Framework\App\State $appState
6868
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6969
* @param \Magento\Framework\View\Page\Config $pageConfig
70+
* @param \Magento\Framework\View\Element\Template\File\Resolver $resolver
71+
* @param \Magento\Framework\View\Element\Template\File\Validator $validator
7072
* @param \Magento\Framework\AuthorizationInterface $authorization
7173
* @param \Magento\Backend\Model\Session $backendSession
7274
* @param \Magento\Framework\Math\Random $mathRandom
@@ -99,6 +101,8 @@ public function __construct(
99101
\Magento\Framework\App\State $appState,
100102
\Magento\Store\Model\StoreManagerInterface $storeManager,
101103
\Magento\Framework\View\Page\Config $pageConfig,
104+
\Magento\Framework\View\Element\Template\File\Resolver $resolver,
105+
\Magento\Framework\View\Element\Template\File\Validator $validator,
102106
\Magento\Framework\AuthorizationInterface $authorization,
103107
\Magento\Backend\Model\Session $backendSession,
104108
\Magento\Framework\Math\Random $mathRandom,
@@ -133,7 +137,9 @@ public function __construct(
133137
$enginePool,
134138
$appState,
135139
$storeManager,
136-
$pageConfig
140+
$pageConfig,
141+
$resolver,
142+
$validator
137143
);
138144
}
139145

app/code/Magento/Backend/Block/Widget/Context.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ class Context extends \Magento\Backend\Block\Template\Context
4949
* @param \Magento\Framework\View\TemplateEnginePool $enginePool
5050
* @param \Magento\Framework\App\State $appState
5151
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
52+
* @param \Magento\Framework\View\Page\Config $pageConfig
53+
* @param \Magento\Framework\View\Element\Template\File\Resolver $resolver
54+
* @param \Magento\Framework\View\Element\Template\File\Validator $validator
5255
* @param \Magento\Framework\AuthorizationInterface $authorization
5356
* @param \Magento\Backend\Model\Session $backendSession
5457
* @param \Magento\Framework\Math\Random $mathRandom
5558
* @param \Magento\Framework\Data\Form\FormKey $formKey
5659
* @param \Magento\Framework\Code\NameBuilder $nameBuilder
5760
* @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
5861
* @param Button\ToolbarInterface $toolbar
59-
* @param \Magento\Framework\View\Page\Config $pageConfig
6062
*
6163
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6264
*/
@@ -84,6 +86,8 @@ public function __construct(
8486
\Magento\Framework\App\State $appState,
8587
\Magento\Store\Model\StoreManagerInterface $storeManager,
8688
\Magento\Framework\View\Page\Config $pageConfig,
89+
\Magento\Framework\View\Element\Template\File\Resolver $resolver,
90+
\Magento\Framework\View\Element\Template\File\Validator $validator,
8791
\Magento\Framework\AuthorizationInterface $authorization,
8892
\Magento\Backend\Model\Session $backendSession,
8993
\Magento\Framework\Math\Random $mathRandom,
@@ -116,6 +120,8 @@ public function __construct(
116120
$appState,
117121
$storeManager,
118122
$pageConfig,
123+
$resolver,
124+
$validator,
119125
$authorization,
120126
$backendSession,
121127
$mathRandom,

app/code/Magento/Catalog/Block/Product/Context.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class Context extends \Magento\Framework\View\Element\Template\Context
9494
* @param \Magento\Framework\View\TemplateEnginePool $enginePool
9595
* @param \Magento\Framework\App\State $appState
9696
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
97+
* @param \Magento\Framework\View\Page\Config $pageConfig
98+
* @param \Magento\Framework\View\Element\Template\File\Resolver $resolver
99+
* @param \Magento\Framework\View\Element\Template\File\Validator $validator
97100
* @param \Magento\Catalog\Model\Config $catalogConfig
98101
* @param \Magento\Framework\Registry $registry
99102
* @param \Magento\Tax\Helper\Data $taxHelper
@@ -105,7 +108,6 @@ class Context extends \Magento\Framework\View\Element\Template\Context
105108
* @param \Magento\Catalog\Helper\Image $imageHelper
106109
* @param ReviewRendererInterface $reviewRenderer
107110
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
108-
* @param \Magento\Framework\View\Page\Config $pageConfig
109111
*
110112
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
111113
*/
@@ -133,6 +135,8 @@ public function __construct(
133135
\Magento\Framework\App\State $appState,
134136
\Magento\Store\Model\StoreManagerInterface $storeManager,
135137
\Magento\Framework\View\Page\Config $pageConfig,
138+
\Magento\Framework\View\Element\Template\File\Resolver $resolver,
139+
\Magento\Framework\View\Element\Template\File\Validator $validator,
136140
\Magento\Catalog\Model\Config $catalogConfig,
137141
\Magento\Framework\Registry $registry,
138142
\Magento\Tax\Helper\Data $taxHelper,
@@ -179,7 +183,9 @@ public function __construct(
179183
$enginePool,
180184
$appState,
181185
$storeManager,
182-
$pageConfig
186+
$pageConfig,
187+
$resolver,
188+
$validator
183189
);
184190
}
185191

app/code/Magento/Cms/Test/Unit/Block/Adminhtml/Block/Edit/FormTest.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ class FormTest extends \PHPUnit_Framework_TestCase
9090
*/
9191
protected $appState;
9292

93-
/**
94-
* @var \PHPUnit_Framework_MockObject_MockObject
95-
*/
96-
protected $viewFileSystem;
97-
9893
/**
9994
* @var \PHPUnit_Framework_MockObject_MockObject
10095
*/
@@ -130,6 +125,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
130125
*/
131126
protected $block;
132127

128+
/**
129+
* @var \Magento\Framework\View\Element\Template\File\Resolver|\PHPUnit_Framework_MockObject_MockObject
130+
*/
131+
protected $_resolver;
132+
133+
/**
134+
* @var \Magento\Framework\View\Element\Template\File\Validator|\PHPUnit_Framework_MockObject_MockObject
135+
*/
136+
protected $_validator;
137+
133138
/**
134139
* Sets up the fixture, for example, open a network connection.
135140
* This method is called before a test is executed.
@@ -138,6 +143,22 @@ class FormTest extends \PHPUnit_Framework_TestCase
138143
*/
139144
public function setUp()
140145
{
146+
$this->_resolver = $this->getMock(
147+
'Magento\Framework\View\Element\Template\File\Resolver',
148+
[],
149+
[],
150+
'',
151+
false
152+
);
153+
154+
$this->_validator = $this->getMock(
155+
'Magento\Framework\View\Element\Template\File\Validator',
156+
[],
157+
[],
158+
'',
159+
false
160+
);
161+
141162
$this->model = $this->getMock('Magento\Cms\Model\Block', ['getBlockId', 'setStoreId'], [], '', false);
142163

143164
$this->registry = $this->getMock('Magento\Framework\Registry', [], [], '', false);
@@ -158,7 +179,6 @@ public function setUp()
158179
$this->scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
159180
$this->urlBuilder = $this->getMock('Magento\Framework\UrlInterface', [], [], '', false);
160181
$this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false);
161-
$this->viewFileSystem = $this->getMock('Magento\Framework\View\FileSystem', [], [], '', false);
162182
$this->logger = $this->getMock('Psr\Log\LoggerInterface', [], [], '', false);
163183
$this->rootDirectory = $this->getMock(
164184
'Magento\Framework\Filesystem\Directory\ReadInterface',
@@ -193,10 +213,11 @@ public function setUp()
193213
$this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
194214
$this->context->expects($this->once())->method('getUrlBuilder')->willReturn($this->urlBuilder);
195215
$this->context->expects($this->once())->method('getAppState')->willReturn($this->appState);
196-
$this->context->expects($this->once())->method('getViewFileSystem')->willReturn($this->viewFileSystem);
197216
$this->context->expects($this->once())->method('getFilesystem')->willReturn($this->fileSystem);
198217
$this->context->expects($this->once())->method('getLogger')->willReturn($this->logger);
199218
$this->context->expects($this->once())->method('getLayout')->willReturn($this->layout);
219+
$this->context->expects($this->once())->method('getResolver')->willReturn($this->_resolver);
220+
$this->context->expects($this->once())->method('getValidator')->willReturn($this->_validator);
200221

201222
/** @var \Magento\Cms\Block\Adminhtml\Block\Edit\Form $block */
202223
$this->block = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function getGridUrl()
204204
*/
205205
public function getGridParentHtml()
206206
{
207-
$templateName = $this->_viewFileSystem->getTemplateFileName($this->_parentTemplate, ['_relative' => true]);
207+
$templateName = $this->resolver->getTemplateFileName($this->_parentTemplate, ['_relative' => true]);
208208
return $this->fetchView($templateName);
209209
}
210210

app/code/Magento/PageCache/Model/Observer/ProcessLayoutRenderElement.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ class ProcessLayoutRenderElement
1616
protected $_config;
1717

1818
/**
19+
* Is varnish enabled flag
20+
*
21+
* @var bool
22+
*/
23+
protected $isVarnishEnabled;
24+
25+
/**
26+
* Is full page cache enabled flag
27+
*
28+
* @var bool
29+
*/
30+
protected $isFullPageCacheEnabled;
31+
32+
/**
33+
* Class constructor
34+
*
1935
* @param \Magento\PageCache\Model\Config $config
2036
*/
2137
public function __construct(\Magento\PageCache\Model\Config $config)
@@ -44,6 +60,32 @@ protected function _wrapEsi(
4460
return sprintf('<esi:include src="%s" />', $url);
4561
}
4662

63+
/**
64+
* Is full page cache enabled
65+
*
66+
* @return bool
67+
*/
68+
protected function isFullPageCacheEnabled()
69+
{
70+
if ($this->isFullPageCacheEnabled === null) {
71+
$this->isFullPageCacheEnabled = $this->_config->isEnabled();
72+
}
73+
return $this->isFullPageCacheEnabled;
74+
}
75+
76+
/**
77+
* Is varnish cache engine enabled
78+
*
79+
* @return bool
80+
*/
81+
protected function isVarnishEnabled()
82+
{
83+
if ($this->isVarnishEnabled === null) {
84+
$this->isVarnishEnabled = ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH);
85+
}
86+
return $this->isVarnishEnabled;
87+
}
88+
4789
/**
4890
* Add comment cache containers to private blocks
4991
* Blocks are wrapped only if page is cacheable
@@ -56,15 +98,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5698
$event = $observer->getEvent();
5799
/** @var \Magento\Framework\View\Layout $layout */
58100
$layout = $event->getLayout();
59-
if ($layout->isCacheable() && $this->_config->isEnabled()) {
101+
if ($this->isFullPageCacheEnabled() && $layout->isCacheable()) {
60102
$name = $event->getElementName();
103+
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
61104
$block = $layout->getBlock($name);
62105
$transport = $event->getTransport();
63106
if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) {
64107
$blockTtl = $block->getTtl();
65-
$varnishIsEnabledFlag = ($this->_config->getType() == \Magento\PageCache\Model\Config::VARNISH);
66108
$output = $transport->getData('output');
67-
if ($varnishIsEnabledFlag && isset($blockTtl)) {
109+
if (isset($blockTtl) && $this->isVarnishEnabled()) {
68110
$output = $this->_wrapEsi($block, $layout);
69111
} elseif ($block->isScopePrivate()) {
70112
$output = sprintf(

app/code/Magento/PageCache/Test/Unit/Model/Observer/ProcessLayoutRenderElementTest.php

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,29 @@ public function testExecute(
9999
$this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
100100

101101
if ($cacheState) {
102-
$eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
103-
$eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
104-
$this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
105-
106-
$this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
107-
$this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
108-
$this->_layoutMock->expects(
109-
$this->once()
110-
)->method(
111-
'getBlock'
112-
)->will(
113-
$this->returnValue($this->_blockMock)
114-
);
102+
$eventMock->expects($this->once())
103+
->method('getElementName')
104+
->will($this->returnValue('blockName'));
105+
106+
$eventMock->expects($this->once())
107+
->method('getTransport')
108+
->will($this->returnValue($this->_transport));
109+
110+
$this->_layoutMock->expects($this->once())
111+
->method('isCacheable')
112+
->will($this->returnValue(true));
113+
114+
$this->_layoutMock->expects($this->any())
115+
->method('getUpdate')
116+
->will($this->returnSelf());
117+
118+
$this->_layoutMock->expects($this->any())
119+
->method('getHandles')
120+
->will($this->returnValue([]));
121+
122+
$this->_layoutMock->expects($this->once())
123+
->method('getBlock')
124+
->will($this->returnValue($this->_blockMock));
115125

116126
if ($varnishIsEnabled) {
117127
$this->_blockMock->expects($this->once())
@@ -123,20 +133,12 @@ public function testExecute(
123133
->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
124134
}
125135
if ($scopeIsPrivate) {
126-
$this->_blockMock->expects(
127-
$this->once()
128-
)->method(
129-
'getNameInLayout'
130-
)->will(
131-
$this->returnValue('testBlockName')
132-
);
133-
$this->_blockMock->expects(
134-
$this->once()
135-
)->method(
136-
'isScopePrivate'
137-
)->will(
138-
$this->returnValue($scopeIsPrivate)
139-
);
136+
$this->_blockMock->expects($this->once())
137+
->method('getNameInLayout')
138+
->will($this->returnValue('testBlockName'));
139+
$this->_blockMock->expects($this->once())
140+
->method('isScopePrivate')
141+
->will($this->returnValue($scopeIsPrivate));
140142
}
141143
$this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
142144
}

app/code/Magento/Store/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>
2424
</arguments>
2525
</type>
26+
<type name="Magento\Framework\View\Element\Template\File\Validator">
27+
<arguments>
28+
<argument name="scope" xsi:type="string">store</argument>
29+
</arguments>
30+
</type>
2631
<type name="Magento\Store\Model\Config\Reader\Website">
2732
<arguments>
2833
<argument name="scopePool" xsi:type="object">Magento\Framework\App\Config\ScopePool\Proxy</argument>

0 commit comments

Comments
 (0)