-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-47607: [Github] Sitemap generation in wrong folder when vhost…
… is connected to pub folder
- Loading branch information
Sergey Semenov
committed
Jun 12, 2017
1 parent
434c2d4
commit 6edb0da
Showing
8 changed files
with
373 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Robots\Model\Config; | ||
|
||
use Magento\Framework\App\Cache\TypeListInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Config\Value as ConfigValue; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
use Magento\Framework\DataObject\IdentityInterface; | ||
use Magento\Framework\Model\Context; | ||
use Magento\Framework\Model\ResourceModel\AbstractResource; | ||
use Magento\Framework\Registry; | ||
use Magento\Store\Model\StoreResolver; | ||
|
||
/** | ||
* Backend model for design/search_engine_robots/custom_instructions configuration value. | ||
* Required to implement Page Cache functionality. | ||
*/ | ||
class Value extends ConfigValue implements IdentityInterface | ||
{ | ||
/** | ||
* Cache tag for robots.txt cached data | ||
*/ | ||
const CACHE_TAG = 'robots'; | ||
|
||
/** | ||
* Model cache tag for clear cache in after save and after delete | ||
* | ||
* @var string | ||
*/ | ||
protected $_cacheTag = true; | ||
|
||
/** | ||
* @var StoreResolver | ||
*/ | ||
private $storeResolver; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Registry $registry | ||
* @param ScopeConfigInterface $config | ||
* @param TypeListInterface $cacheTypeList | ||
* @param StoreResolver $storeResolver | ||
* @param AbstractResource|null $resource | ||
* @param AbstractDb|null $resourceCollection | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $registry, | ||
ScopeConfigInterface $config, | ||
TypeListInterface $cacheTypeList, | ||
StoreResolver $storeResolver, | ||
AbstractResource $resource = null, | ||
AbstractDb $resourceCollection = null, | ||
array $data = [] | ||
) { | ||
$this->storeResolver = $storeResolver; | ||
|
||
parent::__construct( | ||
$context, | ||
$registry, | ||
$config, | ||
$cacheTypeList, | ||
$resource, | ||
$resourceCollection, | ||
$data | ||
); | ||
} | ||
|
||
/** | ||
* Get unique page cache identities | ||
* | ||
* @return array | ||
*/ | ||
public function getIdentities() | ||
{ | ||
return [ | ||
self::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Robots\Test\Unit\Block; | ||
|
||
class DataTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Robots\Block\Data | ||
*/ | ||
private $block; | ||
|
||
/** | ||
* @var \Magento\Framework\View\Element\Context|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var \Magento\Robots\Model\Robots|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $robots; | ||
|
||
/** | ||
* @var \Magento\Store\Model\StoreResolver|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeResolver; | ||
|
||
/** | ||
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $eventManagerMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->context = $this->getMockBuilder(\Magento\Framework\View\Element\Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->context->expects($this->any()) | ||
->method('getEventManager') | ||
->willReturn($this->eventManagerMock); | ||
|
||
$this->robots = $this->getMockBuilder(\Magento\Robots\Model\Robots::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->storeResolver = $this->getMockBuilder(\Magento\Store\Model\StoreResolver::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->block = new \Magento\Robots\Block\Data( | ||
$this->context, | ||
$this->robots, | ||
$this->storeResolver | ||
); | ||
} | ||
|
||
/** | ||
* Check that toHtml() method returns specified text data | ||
*/ | ||
public function testToHtml() | ||
{ | ||
$expected = 'test'; | ||
|
||
$this->initEventManagerMock($expected); | ||
|
||
$this->robots->expects($this->once()) | ||
->method('getData') | ||
->willReturn($expected); | ||
|
||
$this->assertEquals($expected, $this->block->toHtml()); | ||
} | ||
|
||
/** | ||
* Check that getIdentities() method returns specified cache tag | ||
*/ | ||
public function testGetIdentities() | ||
{ | ||
$storeId = 1; | ||
|
||
$this->storeResolver->expects($this->once()) | ||
->method('getCurrentStoreId') | ||
->willReturn($storeId); | ||
|
||
$expected = [ | ||
\Magento\Robots\Model\Config\Value::CACHE_TAG . '_' . $storeId, | ||
]; | ||
$this->assertEquals($expected, $this->block->getIdentities()); | ||
} | ||
|
||
/** | ||
* Initialize mock object of Event Manager | ||
* | ||
* @param string $data | ||
* @return void | ||
*/ | ||
protected function initEventManagerMock($data) | ||
{ | ||
$this->eventManagerMock->expects($this->any()) | ||
->method('dispatch') | ||
->willReturnMap([ | ||
[ | ||
'view_block_abstract_to_html_before', | ||
[ | ||
'block' => $this->block, | ||
], | ||
], | ||
[ | ||
'view_block_abstract_to_html_after', | ||
[ | ||
'block' => $this->block, | ||
'transport' => new \Magento\Framework\DataObject(['html' => $data]), | ||
], | ||
], | ||
]); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
app/code/Magento/Robots/Test/Unit/Model/Config/ValueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Robots\Test\Unit\Model\Config; | ||
|
||
class ValueTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Robots\Model\Config\Value | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Cache\TypeListInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $typeList; | ||
|
||
/** | ||
* @var \Magento\Store\Model\StoreResolver|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeResolver; | ||
|
||
protected function setUp() | ||
{ | ||
$this->context = $this->getMockBuilder(\Magento\Framework\Model\Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->registry = $this->getMockBuilder(\Magento\Framework\Registry::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->typeList = $this->getMockBuilder(\Magento\Framework\App\Cache\TypeListInterface::class) | ||
->getMockForAbstractClass(); | ||
|
||
$this->storeResolver = $this->getMockBuilder(\Magento\Store\Model\StoreResolver::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new \Magento\Robots\Model\Config\Value( | ||
$this->context, | ||
$this->registry, | ||
$this->scopeConfig, | ||
$this->typeList, | ||
$this->storeResolver | ||
); | ||
} | ||
|
||
/** | ||
* Check that getIdentities() method returns specified cache tag | ||
*/ | ||
public function testGetIdentities() | ||
{ | ||
$storeId = 1; | ||
|
||
$this->storeResolver->expects($this->once()) | ||
->method('getCurrentStoreId') | ||
->willReturn($storeId); | ||
|
||
$expected = [ | ||
\Magento\Robots\Model\Config\Value::CACHE_TAG . '_' . $storeId, | ||
]; | ||
$this->assertEquals($expected, $this->model->getIdentities()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.