Skip to content

Commit

Permalink
MAGETWO-56989: Deployment process can't be executed on separate machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergii Kovalenko committed Oct 21, 2016
1 parent 8d0dc6f commit a978a4c
Show file tree
Hide file tree
Showing 165 changed files with 6,378 additions and 1,463 deletions.
53 changes: 31 additions & 22 deletions app/code/Magento/Backend/App/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,66 @@

namespace Magento\Backend\App;

use Magento\Config\App\Config\Type\System;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
* Backend config accessor
* Backend config accessor.
*/
class Config implements ConfigInterface
{
/**
* @var \Magento\Framework\App\Config\ScopePool
* @var \Magento\Framework\App\Config
*/
protected $_scopePool;
protected $appConfig;

/**
* @param \Magento\Framework\App\Config\ScopePool $scopePool
* @var array
*/
public function __construct(\Magento\Framework\App\Config\ScopePool $scopePool)
private $data;

/**
* @param \Magento\Framework\App\Config $appConfig
* @return void
*/
public function __construct(\Magento\Framework\App\Config $appConfig)
{
$this->_scopePool = $scopePool;
$this->appConfig = $appConfig;
}

/**
* Retrieve config value by path and scope
*
* @param string $path
* @return mixed
* @inheritdoc
*/
public function getValue($path)
{
return $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
if (isset($this->data[$path])) {
return $this->data[$path];
}

$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
if ($path) {
$configPath .= '/' . $path;
}
return $this->appConfig->get(System::CONFIG_TYPE, $configPath);
}

/**
* Set config value in the corresponding config scope
*
* @param string $path
* @param mixed $value
* @return void
* @inheritdoc
*/
public function setValue($path, $value)
{
$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->setValue($path, $value);
$this->data[$path] = $value;
}

/**
* Retrieve config flag
*
* @param string $path
* @return bool
* @inheritdoc
*/
public function isSetFlag($path)
{
return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
if ($path) {
$configPath .= '/' . $path;
}
return (bool) $this->appConfig->get(System::CONFIG_TYPE, $configPath);
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Backend/App/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface ConfigInterface
/**
* Retrieve config value by path
*
* Path should looks like keys imploded by "/". For example scopes/stores/admin
*
* @param string $path
* @return mixed
* @api
Expand All @@ -24,6 +26,7 @@ public function getValue($path);
/**
* Set config value
*
* @deprecated
* @param string $path
* @param mixed $value
* @return void
Expand All @@ -34,6 +37,8 @@ public function setValue($path, $value);
/**
* Retrieve config flag
*
* Path should looks like keys imploded by "/". For example scopes/stores/admin
*
* @param string $path
* @return bool
* @api
Expand Down
94 changes: 31 additions & 63 deletions app/code/Magento/Backend/Test/Unit/App/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

use Magento\Backend\App\Config;

/**
* Test reading by path and reading flag from config
*
* @see \Magento\Backend\App\Config
* @package Magento\Backend\Test\Unit\App
*/
class ConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\App\Config\ScopePool|\PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $sectionPool;
protected $appConfig;

/**
* @var Config
Expand All @@ -21,102 +27,64 @@ class ConfigTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->sectionPool = $this->getMock(
\Magento\Framework\App\Config\ScopePool::class,
['getScope', 'clean'],
$this->appConfig = $this->getMock(
\Magento\Framework\App\Config::class,
['get'],
[],
'',
false
);
$this->model = new \Magento\Backend\App\Config($this->sectionPool);
$this->model = new \Magento\Backend\App\Config($this->appConfig);
}

public function testGetValue()
{
$expectedValue = 'some value';
$path = 'some path';
$configData = $this->getConfigDataMock('getValue');
$configData->expects(
$this->once()
)->method(
'getValue'
)->with(
$this->equalTo($path)
)->will(
$this->returnValue($expectedValue)
);
$this->sectionPool->expects(
$this->appConfig->expects(
$this->once()
)->method(
'getScope'
'get'
)->with(
$this->equalTo('default'),
$this->equalTo('system'),
$this->equalTo('default/' . $path),
$this->isNull()
)->will(
$this->returnValue($configData)
$this->returnValue($expectedValue)
);
$this->assertEquals($expectedValue, $this->model->getValue($path));
}

public function testSetValue()
{
$value = 'some value';
$path = 'some path';
$configData = $this->getConfigDataMock('setValue');
$configData->expects($this->once())->method('setValue')->with($this->equalTo($path), $this->equalTo($value));
$this->sectionPool->expects(
$this->once()
)->method(
'getScope'
)->with(
$this->equalTo('default'),
$this->isNull()
)->will(
$this->returnValue($configData)
);
$this->model->setValue($path, $value);
}

/**
* @param string $configPath
* @param mixed $configValue
* @param bool $expectedResult
* @dataProvider isSetFlagDataProvider
*/
public function testIsSetFlag($configValue, $expectedResult)
public function testIsSetFlag($configPath, $configValue, $expectedResult)
{
$path = 'some path';
$configData = $this->getConfigDataMock('getValue');
$configData->expects(
$this->once()
$this->appConfig->expects(
$this->any()
)->method(
'getValue'
'get'
)->with(
$this->equalTo($path)
$this->equalTo('system'),
$this->equalTo('default/' . $configPath)
)->will(
$this->returnValue($configValue)
);
$this->sectionPool->expects(
$this->once()
)->method(
'getScope'
)->with(
$this->equalTo('default'),
$this->isNull()
)->will(
$this->returnValue($configData)
);
$this->assertEquals($expectedResult, $this->model->isSetFlag($path));
$this->assertEquals($expectedResult, $this->model->isSetFlag($configPath));
}

public function isSetFlagDataProvider()
{
return [
[0, false],
[true, true],
['0', false],
['', false],
['some string', true],
[1, true]
['a', 0, false],
['b', true, true],
['c', '0', false],
['d', '', false],
['e', 'some string', true],
['f', 1, true]
];
}

Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Catalog/Model/Template/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
namespace Magento\Catalog\Model\Template;

/**
* Work with catalog(store, website) urls
*
* @package Magento\Catalog\Model\Template
*/
class Filter extends \Magento\Framework\Filter\Template
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
use Magento\UrlRewrite\Model\UrlPersistInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

/**
* Plugin which is listening store resource model and on save or on delete replace catalog url rewrites
*
* @see \Magento\Store\Model\ResourceModel\Store
* @package Magento\CatalogUrlRewrite\Model\Category\Plugin\Store
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class View
{
/** @var UrlPersistInterface */
Expand All @@ -30,6 +37,11 @@ class View
/** @var ProductUrlRewriteGenerator */
protected $productUrlRewriteGenerator;

/**
* @var AbstractModel
*/
private $origStore;

/**
* @param UrlPersistInterface $urlPersist
* @param CategoryFactory $categoryFactory
Expand All @@ -55,31 +67,43 @@ public function __construct(
* Perform updating url for categories and products assigned to the store view
*
* @param \Magento\Store\Model\ResourceModel\Store $subject
* @param \Magento\Store\Model\ResourceModel\Store $result
* @param AbstractModel $store
* @return \Magento\Store\Model\ResourceModel\Store
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(
public function beforeSave(
\Magento\Store\Model\ResourceModel\Store $subject,
\Magento\Store\Model\ResourceModel\Store $result,
AbstractModel $store
) {
if ($store->isObjectNew() || $store->dataHasChangedFor('group_id')) {
if (!$store->isObjectNew()) {
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $store->getId()]);
}
$this->origStore = $store;
}

$this->urlPersist->replace(
$this->generateCategoryUrls($store->getRootCategoryId(), $store->getId())
);
/**
* Regenerate urls on store after save
*
* @param \Magento\Store\Model\ResourceModel\Store $object
* @param \Magento\Store\Model\ResourceModel\Store $store
* @return \Magento\Store\Model\ResourceModel\Store
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterSave(
\Magento\Store\Model\ResourceModel\Store $object,
\Magento\Store\Model\ResourceModel\Store $store
) {
if ($this->origStore->isObjectNew() || $this->origStore->dataHasChangedFor('group_id')) {
if (!$this->origStore->isObjectNew()) {
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $this->origStore->getId()]);
}

$this->urlPersist->replace(
$this->generateProductUrls($store->getWebsiteId(), $store->getOrigData('website_id'), $store->getId())
$this->generateProductUrls(
$this->origStore->getWebsiteId(),
$this->origStore->getOrigData('website_id'),
$this->origStore->getId()
)
);
}

return $result;
return $store;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Cms/Test/Unit/Model/Template/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Cms\Test\Unit\Model\Template;

/**
* Work with catalog(store, website) urls
*
* @covers \Magento\Cms\Model\Template\Filter
*/
class FilterTest extends \PHPUnit_Framework_TestCase
Expand Down
Loading

0 comments on commit a978a4c

Please sign in to comment.