Skip to content

Commit cc86ae0

Browse files
author
Dale Sikkema
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-34168-init-param-always-use
2 parents 9b94ef7 + af0a10d commit cc86ae0

File tree

268 files changed

+8699
-3607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+8699
-3607
lines changed

app/code/Magento/AdminNotification/Model/Feed.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\AdminNotification\Model;
77

8+
use Magento\Framework\Config\ConfigOptionsList;
9+
810
/**
911
* AdminNotification Feed model
1012
*
@@ -135,7 +137,7 @@ public function checkUpdate()
135137

136138
$feedXml = $this->getFeedData();
137139

138-
$installDate = strtotime($this->_deploymentConfig->get('install/date'));
140+
$installDate = strtotime($this->_deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE));
139141

140142
if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
141143
foreach ($feedXml->channel->item as $item) {

app/code/Magento/AdminNotification/Test/Unit/Model/FeedTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\AdminNotification\Test\Unit\Model;
88

99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
use Magento\Framework\Config\ConfigOptionsList;
1011

1112
/**
1213
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -140,7 +141,8 @@ public function testCheckUpdate($callInbox, $curlRequest)
140141
$this->backendConfig->expects($this->at(1))->method('getValue')
141142
->will($this->returnValue('http://feed.magento.com'));
142143
$this->deploymentConfig->expects($this->once())->method('get')
143-
->with('install/date')->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
144+
->with(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE)
145+
->will($this->returnValue('Sat, 6 Sep 2014 16:46:11 UTC'));
144146
if ($callInbox) {
145147
$this->inboxFactory->expects($this->once())->method('create')
146148
->will(($this->returnValue($this->inboxModel)));

app/code/Magento/Backend/App/Area/FrontNameResolver.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magento\Backend\App\Area;
99

10+
use Magento\Backend\Setup\ConfigOptionsList;
1011
use Magento\Framework\App\DeploymentConfig;
1112

1213
class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolverInterface
@@ -15,8 +16,6 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
1516

1617
const XML_PATH_CUSTOM_ADMIN_PATH = 'admin/url/custom_path';
1718

18-
const PARAM_BACKEND_FRONT_NAME = 'backend/frontName';
19-
2019
/**
2120
* Backend area code
2221
*/
@@ -46,7 +45,7 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
4645
public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig)
4746
{
4847
$this->config = $config;
49-
$this->defaultFrontName = $deploymentConfig->get(self::PARAM_BACKEND_FRONT_NAME);
48+
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
5049
}
5150

5251
/**

app/code/Magento/Backend/Helper/Dashboard/Data.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Backend\Helper\Dashboard;
77

88
use Magento\Framework\App\DeploymentConfig;
9+
use Magento\Framework\Config\ConfigOptionsList;
910

1011
/**
1112
* Data helper for dashboard
@@ -22,11 +23,6 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
2223
*/
2324
protected $_installDate;
2425

25-
/**
26-
* Configuration key to installation date
27-
*/
28-
const INSTALL_DATE = 'install/date';
29-
3026
/**
3127
* @var \Magento\Store\Model\StoreManagerInterface
3228
*/
@@ -45,7 +41,7 @@ public function __construct(
4541
parent::__construct(
4642
$context
4743
);
48-
$this->_installDate = $deploymentConfig->get(self::INSTALL_DATE);
44+
$this->_installDate = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE);
4945
$this->_storeManager = $storeManager;
5046
}
5147

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Setup;
7+
8+
use Magento\Framework\Config\Data\ConfigData;
9+
use Magento\Framework\Config\File\ConfigFilePool;
10+
use Magento\Framework\Setup\ConfigOptionsListInterface;
11+
use Magento\Framework\Setup\Option\TextConfigOption;
12+
use Magento\Framework\App\DeploymentConfig;
13+
14+
/*
15+
* Deployment configuration options needed for Backend module
16+
*/
17+
class ConfigOptionsList implements ConfigOptionsListInterface
18+
{
19+
/**
20+
* Input key for the options
21+
*/
22+
const INPUT_KEY_BACKEND_FRONTNAME = 'backend_frontname';
23+
24+
/**
25+
* Path to the values in the deployment config
26+
*/
27+
const CONFIG_PATH_BACKEND_FRONTNAME = 'backend/frontName';
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function getOptions()
33+
{
34+
return [
35+
new TextConfigOption(
36+
self::INPUT_KEY_BACKEND_FRONTNAME,
37+
TextConfigOption::FRONTEND_WIZARD_TEXT,
38+
self::CONFIG_PATH_BACKEND_FRONTNAME,
39+
'Backend frontname',
40+
'admin'
41+
)
42+
];
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
48+
*/
49+
public function createConfig(array $options, DeploymentConfig $deploymentConfig)
50+
{
51+
$configData = new ConfigData(ConfigFilePool::APP_CONFIG);
52+
53+
if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) {
54+
$configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]);
55+
}
56+
57+
return [$configData];
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
public function validate(array $options)
64+
{
65+
$errors = [];
66+
if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])
67+
&& !preg_match('/^[a-zA-Z0-9_]+$/', $options[self::INPUT_KEY_BACKEND_FRONTNAME])
68+
) {
69+
$errors[] = "Invalid backend frontname '{$options[self::INPUT_KEY_BACKEND_FRONTNAME]}'";
70+
}
71+
72+
return $errors;
73+
}
74+
}

app/code/Magento/Backend/Test/Unit/App/Area/FrontNameResolverTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Backend\Test\Unit\App\Area;
77

88
use Magento\Backend\App\Area\FrontNameResolver;
9+
use Magento\Backend\Setup\ConfigOptionsList;
910

1011
class FrontNameResolverTest extends \PHPUnit_Framework_TestCase
1112
{
@@ -29,10 +30,10 @@ protected function setUp()
2930
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
3031
$deploymentConfigMock->expects($this->once())
3132
->method('get')
32-
->with(FrontNameResolver::PARAM_BACKEND_FRONT_NAME)
33+
->with(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
3334
->will($this->returnValue($this->_defaultFrontName));
3435
$this->_configMock = $this->getMock('\Magento\Backend\App\Config', [], [], '', false);
35-
$this->_model = new \Magento\Backend\App\Area\FrontNameResolver($this->_configMock, $deploymentConfigMock);
36+
$this->_model = new FrontNameResolver($this->_configMock, $deploymentConfigMock);
3637
}
3738

3839
public function testIfCustomPathUsed()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Setup;
7+
8+
use Magento\Backend\Setup\ConfigOptionsList;
9+
use Magento\Framework\Config\File\ConfigFilePool;
10+
11+
class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var ConfigOptionsList
15+
*/
16+
private $object;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\DeploymentConfig
20+
*/
21+
private $deploymentConfig;
22+
23+
protected function setUp()
24+
{
25+
$this->object = new ConfigOptionsList();
26+
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
27+
}
28+
29+
public function testGetOptions()
30+
{
31+
$options = $this->object->getOptions();
32+
$this->assertInternalType('array', $options);
33+
foreach ($options as $option) {
34+
$this->assertInstanceOf('\Magento\Framework\Setup\Option\AbstractConfigOption', $option);
35+
}
36+
}
37+
38+
public function testCreateConfig()
39+
{
40+
$options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin'];
41+
$actualConfig = $this->object->createConfig($options, $this->deploymentConfig);
42+
43+
$expectedData = [
44+
[
45+
'file' => ConfigFilePool::APP_CONFIG,
46+
'segment' => 'backend',
47+
'data' => [
48+
'backend' => ['frontName' => 'admin']
49+
]
50+
]
51+
];
52+
53+
$this->assertInternalType('array', $actualConfig);
54+
/** @var \Magento\Framework\Config\Data\ConfigData $config */
55+
foreach ($actualConfig as $i => $config) {
56+
$this->assertInstanceOf('\Magento\Framework\Config\Data\ConfigData', $config);
57+
$this->assertSame($expectedData[$i]['file'], $config->getFileKey());
58+
$this->assertSame($expectedData[$i]['data'], $config->getData());
59+
}
60+
}
61+
62+
public function testValidate()
63+
{
64+
$options = [ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'admin'];
65+
$errors = $this->object->validate($options);
66+
$this->assertEmpty($errors);
67+
}
68+
69+
/**
70+
* @param array $options
71+
* @param string $expectedError
72+
* @dataProvider validateInvalidDataProvider
73+
*/
74+
public function testValidateInvalid(array $options, $expectedError)
75+
{
76+
$errors = $this->object->validate($options);
77+
$this->assertSame([$expectedError], $errors);
78+
}
79+
80+
/**
81+
* @return array
82+
*/
83+
public function validateInvalidDataProvider()
84+
{
85+
return [
86+
[[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => '**'], "Invalid backend frontname '**'"],
87+
[
88+
[ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'invalid frontname'],
89+
"Invalid backend frontname 'invalid frontname'"
90+
],
91+
];
92+
}
93+
}

app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Customer\Block\Address\Renderer;
77

8-
use Magento\Customer\Model\Address\AbstractAddress;
8+
use Magento\Customer\Model\Address\AddressModelInterface;
99
use Magento\Customer\Model\Address\Mapper;
1010
use Magento\Customer\Model\Metadata\ElementFactory;
1111
use Magento\Framework\View\Element\AbstractBlock;
@@ -111,7 +111,7 @@ public function getFormat(AbstractAddress $address = null)
111111
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
112112
* @SuppressWarnings(PHPMD.NPathComplexity)
113113
*/
114-
public function render(AbstractAddress $address, $format = null)
114+
public function render(AddressModelInterface $address, $format = null)
115115
{
116116
$address = $address->getDataModel(0, 0);
117117
return $this->renderArray($this->addressMapper->toFlatArray($address), $format);

app/code/Magento/Customer/Block/Address/Renderer/RendererInterface.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Block\Address\Renderer;
77

88
use Magento\Directory\Model\Country\Format;
9+
use Magento\Customer\Model\Address\AddressModelInterface;
910

1011
/**
1112
* Address renderer interface
@@ -32,12 +33,12 @@ public function getType();
3233
/**
3334
* Render address
3435
*
35-
* @param \Magento\Customer\Model\Address\AbstractAddress $address
36+
* @param AddressModelInterface $address
3637
* @param string|null $format
3738
* @return mixed
3839
* @deprecated All new code should use renderArray based on Metadata service
3940
*/
40-
public function render(\Magento\Customer\Model\Address\AbstractAddress $address, $format = null);
41+
public function render(AddressModelInterface $address, $format = null);
4142

4243
/**
4344
* Get a format object for a given address attributes, based on the type set earlier.

app/code/Magento/Customer/Model/Address/AbstractAddress.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @method bool getShouldIgnoreValidation()
3030
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3131
*/
32-
class AbstractAddress extends AbstractExtensibleModel
32+
class AbstractAddress extends AbstractExtensibleModel implements AddressModelInterface
3333
{
3434
/**
3535
* Possible customer address types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model\Address;
8+
9+
/**
10+
* Interface AddressInterface
11+
*/
12+
interface AddressModelInterface
13+
{
14+
/**
15+
* Get steet line by number
16+
*
17+
* @param int $number
18+
* @return string
19+
*/
20+
public function getStreetLine($number);
21+
22+
/**
23+
* Create fields street1, street2, etc.
24+
*
25+
* To be used in controllers for views data
26+
*
27+
* @return $this
28+
*/
29+
public function explodeStreetAddress();
30+
}

0 commit comments

Comments
 (0)