Skip to content

Commit b8c09a7

Browse files
Merge remote-tracking branch 'origin/MDVA-232' into 2.0.5_backlog
2 parents e280e68 + 720be73 commit b8c09a7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/internal/Magento/Framework/View/Page/Config.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ class Config
117117
'robots' => null,
118118
];
119119

120+
/**
121+
* @var \Magento\Framework\App\State
122+
*/
123+
private $areaResolver;
124+
125+
/**
126+
* This getter serves as a workaround to add this dependency to this class without breaking constructor structure.
127+
*
128+
* @return \Magento\Framework\App\State
129+
*
130+
* @deprecated
131+
*/
132+
private function getAreaResolver()
133+
{
134+
if ($this->areaResolver === null) {
135+
$this->areaResolver = \Magento\Framework\App\ObjectManager::getInstance()
136+
->get('Magento\Framework\App\State');
137+
}
138+
return $this->areaResolver;
139+
}
140+
120141
/**
121142
* @param \Magento\Framework\View\Asset\Repository $assetRepo
122143
* @param \Magento\Framework\View\Asset\GroupedCollection $pageAssets
@@ -350,6 +371,9 @@ public function setRobots($robots)
350371
*/
351372
public function getRobots()
352373
{
374+
if ($this->getAreaResolver()->getAreaCode() !== 'frontend') {
375+
return 'NOINDEX,NOFOLLOW';
376+
}
353377
$this->build();
354378
if (empty($this->metadata['robots'])) {
355379
$this->metadata['robots'] = $this->scopeConfig->getValue(

lib/internal/Magento/Framework/View/Test/Unit/Page/ConfigTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
5959
*/
6060
protected $title;
6161

62+
/**
63+
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
64+
*/
65+
protected $areaResolverMock;
66+
6267
public function setUp()
6368
{
6469
$this->assetRepo = $this->getMock('Magento\Framework\View\Asset\Repository', [], [], '', false);
@@ -84,6 +89,11 @@ public function setUp()
8489
'localeResolver' => $locale,
8590
]
8691
);
92+
93+
$this->areaResolverMock = $this->getMock('Magento\Framework\App\State', [], [], '', false);
94+
$areaResolverReflection = (new \ReflectionClass(get_class($this->model)))->getProperty('areaResolver');
95+
$areaResolverReflection->setAccessible(true);
96+
$areaResolverReflection->setValue($this->model, $this->areaResolverMock);
8797
}
8898

8999
public function testSetBuilder()
@@ -202,13 +212,15 @@ public function testKeywordsEmpty()
202212

203213
public function testRobots()
204214
{
215+
$this->areaResolverMock->expects($this->once())->method('getAreaCode')->willReturn('frontend');
205216
$robots = 'test_robots';
206217
$this->model->setRobots($robots);
207218
$this->assertEquals($robots, $this->model->getRobots());
208219
}
209220

210221
public function testRobotsEmpty()
211222
{
223+
$this->areaResolverMock->expects($this->once())->method('getAreaCode')->willReturn('frontend');
212224
$expectedData = 'default_robots';
213225
$this->scopeConfig->expects($this->once())->method('getValue')->with(
214226
'design/search_engine_robots/default_robots',
@@ -218,6 +230,14 @@ public function testRobotsEmpty()
218230
$this->assertEquals($expectedData, $this->model->getRobots());
219231
}
220232

233+
public function testRobotsAdminhtml()
234+
{
235+
$this->areaResolverMock->expects($this->once())->method('getAreaCode')->willReturn('adminhtml');
236+
$robots = 'test_robots';
237+
$this->model->setRobots($robots);
238+
$this->assertEquals('NOINDEX,NOFOLLOW', $this->model->getRobots());
239+
}
240+
221241
public function testGetAssetCollection()
222242
{
223243
$this->assertInstanceOf('Magento\Framework\View\Asset\GroupedCollection', $this->model->getAssetCollection());

0 commit comments

Comments
 (0)