diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php index 59e12d72ded6c6cd4de5aaf323acd5f1ffbbd122..fd2ceaf09695bfb4a413bc6f680f254ca4edca4c 100644 --- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php +++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php @@ -72,6 +72,7 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Index ) { $metadataForm = $this->getMetadataForm($entityType, $formCode, $scope); $formData = $metadataForm->extractData($this->getRequest(), $scope); + $formData = $metadataForm->compactData($formData); // Initialize additional attributes /** @var \Magento\Framework\DataObject $object */ @@ -81,11 +82,6 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Index $formData[$attributeCode] = isset($requestData[$attributeCode]) ? $requestData[$attributeCode] : false; } - $result = $metadataForm->compactData($formData); - - // Re-initialize additional attributes - $formData = array_replace($result, $formData); - // Unset unused attributes $formAttributes = $metadataForm->getAttributes(); foreach ($formAttributes as $attribute) { diff --git a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php index 8fb48fe9f87e76dcf4f5d489a830bb15bf910c79..11fd1b5a7fc3356f54cc1e72b76e111b22446383 100644 --- a/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php +++ b/app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php @@ -304,33 +304,28 @@ class SaveTest extends \PHPUnit_Framework_TestCase ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ + $compactedData = [ 'entity_id' => $customerId, 'code' => 'value', 'coolness' => false, 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - 'extension_attributes' => false, + CustomerInterface::DEFAULT_BILLING => 2, + CustomerInterface::DEFAULT_SHIPPING => 2 ]; - $addressFilteredData = [ + $addressExtractedData = [ 'entity_id' => $addressId, - 'default_billing' => 'true', - 'default_shipping' => 'true', 'code' => 'value', 'coolness' => false, 'region' => 'region', 'region_id' => 'region_id', ]; - $addressDataToCompact = [ + $addressCompactedData = [ 'entity_id' => $addressId, 'default_billing' => 'true', 'default_shipping' => 'true', @@ -430,11 +425,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($compactedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -445,11 +440,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerAddressFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'address/' . $addressId) - ->willReturn($addressFilteredData); + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('compactData') - ->with($addressDataToCompact) - ->willReturn($addressFilteredData); + ->with($addressExtractedData) + ->willReturn($addressCompactedData); $customerAddressFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -625,8 +620,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase '_template_' => '_template_', $addressId => [ 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', @@ -635,32 +628,12 @@ class SaveTest extends \PHPUnit_Framework_TestCase ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - 'extension_attributes' => false, - ]; - $addressFilteredData = [ + $addressExtractedData = [ 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', - 'code' => 'value', - 'coolness' => false, - 'region' => 'region', - 'region_id' => 'region_id', - ]; - $addressDataToCompact = [ - 'entity_id' => $addressId, - 'default_billing' => 'false', - 'default_shipping' => 'false', 'code' => 'value', 'coolness' => false, 'region' => 'region', @@ -739,11 +712,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -754,11 +727,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerAddressFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'address/' . $addressId) - ->willReturn($addressFilteredData); + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('compactData') - ->with($addressDataToCompact) - ->willReturn($addressFilteredData); + ->with($addressExtractedData) + ->willReturn($addressExtractedData); $customerAddressFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -910,19 +883,10 @@ class SaveTest extends \PHPUnit_Framework_TestCase ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - 'extension_attributes' => false, - ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */ $attributeMock = $this->getMockBuilder( @@ -971,11 +935,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -1062,19 +1026,10 @@ class SaveTest extends \PHPUnit_Framework_TestCase ], 'subscription' => $subscription, ]; - $filteredData = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', ]; - $dataToCompact = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - 'extension_attributes' => false, - ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */ $attributeMock = $this->getMockBuilder( @@ -1124,11 +1079,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); @@ -1214,18 +1169,9 @@ class SaveTest extends \PHPUnit_Framework_TestCase ], 'subscription' => $subscription, ]; - $filteredData = [ - 'coolness' => false, - 'disable_auto_group_change' => 'false', - ]; - $dataToCompact = [ + $extractedData = [ 'coolness' => false, 'disable_auto_group_change' => 'false', - CustomerInterface::DEFAULT_BILLING => false, - CustomerInterface::DEFAULT_SHIPPING => false, - 'confirmation' => false, - 'sendemail_store_id' => false, - 'extension_attributes' => false, ]; /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */ @@ -1275,11 +1221,11 @@ class SaveTest extends \PHPUnit_Framework_TestCase $customerFormMock->expects($this->once()) ->method('extractData') ->with($this->requestMock, 'customer') - ->willReturn($filteredData); + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('compactData') - ->with($dataToCompact) - ->willReturn($filteredData); + ->with($extractedData) + ->willReturn($extractedData); $customerFormMock->expects($this->once()) ->method('getAttributes') ->willReturn($attributes); diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php index 9eed3d2b044ca166d35703d35e1fd1995e181108..28697fa5cf85faf8bb33dd61c9f5816fc0b60eed 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php @@ -1146,7 +1146,7 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $storeId = 1; - mt_srand(mt_rand() + (100000000 * microtime()) % PHP_INT_MAX); + mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX); $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true)); $this->emailNotificationMock->expects($this->once()) @@ -1168,7 +1168,7 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; - mt_srand(mt_rand() + (100000000 * microtime()) % PHP_INT_MAX); + mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX); $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true)); $this->emailNotificationMock->expects($this->once()) @@ -1194,7 +1194,7 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $templateIdentifier = 'Template Identifier'; $sender = 'Sender'; - mt_srand(mt_rand() + (100000000 * microtime()) % PHP_INT_MAX); + mt_srand(mt_rand() + (100000000 * (float)microtime()) % PHP_INT_MAX); $hash = md5(uniqid(microtime() . mt_rand(0, mt_getrandmax()), true)); $this->prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash); diff --git a/app/code/Magento/PageCache/Model/Config.php b/app/code/Magento/PageCache/Model/Config.php index 222d9d57e467a31988fd6b6ac221f7ce640c06c5..786165728406f0162be0da04f869a10020d9d3bb 100644 --- a/app/code/Magento/PageCache/Model/Config.php +++ b/app/code/Magento/PageCache/Model/Config.php @@ -148,12 +148,17 @@ class Config ), '/* {{ ips }} */' => $this->_getAccessList(), '/* {{ design_exceptions_code }} */' => $this->_getDesignExceptions(), - // http headers get transformed by php `X-Forwarded-Proto: https` becomes $SERVER['HTTP_X_FORWARDED_PROTO'] = 'https' + // http headers get transformed by php `X-Forwarded-Proto: https` + // becomes $SERVER['HTTP_X_FORWARDED_PROTO'] = 'https' // Apache and Nginx drop all headers with underlines by default. - '/* {{ ssl_offloaded_header }} */' => str_replace('_', '-', $this->_scopeConfig->getValue( - \Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) - + '/* {{ ssl_offloaded_header }} */' => str_replace( + '_', + '-', + $this->_scopeConfig->getValue( + \Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ) ]; } @@ -176,6 +181,7 @@ class Config \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); if (!empty($accessList)) { + $result = []; $ips = explode(',', $accessList); foreach ($ips as $ip) { $result[] = sprintf($tpl, trim($ip)); diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php index a3ed3b941844eec7497eb233d1c43e74045c45e1..779e8cf0a0e5ecf15b0fcb6da1e48b80a5bb3072 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Compiled.php @@ -1,15 +1,15 @@ <?php /** - * * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Framework\ObjectManager\Config; +use Magento\Framework\ObjectManager\ConfigInterface; use Magento\Framework\ObjectManager\ConfigCacheInterface; use Magento\Framework\ObjectManager\RelationsInterface; -class Compiled implements \Magento\Framework\ObjectManager\ConfigInterface +class Compiled implements ConfigInterface { /** * @var array @@ -129,9 +129,15 @@ class Compiled implements \Magento\Framework\ObjectManager\ConfigInterface */ public function extend(array $configuration) { - $this->arguments = $configuration['arguments']; - $this->virtualTypes = $configuration['instanceTypes']; - $this->preferences = $configuration['preferences']; + $this->arguments = isset($configuration['arguments']) + ? array_replace($this->arguments, $configuration['arguments']) + : $this->arguments; + $this->virtualTypes = isset($configuration['instanceTypes']) + ? array_replace($this->virtualTypes, $configuration['instanceTypes']) + : $this->virtualTypes; + $this->preferences = isset($configuration['preferences']) + ? array_replace($this->preferences, $configuration['preferences']) + : $this->preferences; } /** diff --git a/lib/internal/Magento/Framework/Test/Unit/ObjectManager/Config/CompiledTest.php b/lib/internal/Magento/Framework/Test/Unit/ObjectManager/Config/CompiledTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3dd9f5065a1421ec822d4a81377ea81a5c3f8f52 --- /dev/null +++ b/lib/internal/Magento/Framework/Test/Unit/ObjectManager/Config/CompiledTest.php @@ -0,0 +1,91 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Test\Unit\ObjectManager\Config; + +use Magento\Framework\ObjectManager\Config\Compiled as CompiledConfig; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + +class CompiledTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var ObjectManagerHelper + */ + private $objectManagerHelper; + + protected function setUp() + { + $this->objectManagerHelper = new ObjectManagerHelper($this); + } + + /** + * @param array $initialData + * @param array $configuration + * @param array $expectedArguments + * @param array $expectedVirtualTypes + * @param array $expectedPreferences + * + * @dataProvider extendDataProvider + */ + public function testExtend( + array $initialData, + array $configuration, + array $expectedArguments, + array $expectedVirtualTypes, + array $expectedPreferences + ) { + /** @var CompiledConfig $compiledConfig */ + $compiledConfig = $this->objectManagerHelper->getObject(CompiledConfig::class, ['data' => $initialData]); + $compiledConfig->extend($configuration); + + foreach ($expectedArguments as $type => $arguments) { + $this->assertEquals($arguments, $compiledConfig->getArguments($type)); + } + + $this->assertEquals($expectedVirtualTypes, $compiledConfig->getVirtualTypes()); + $this->assertEquals($expectedPreferences, $compiledConfig->getPreferences()); + } + + /** + * @return array + */ + public function extendDataProvider() + { + return [ + [ + 'initialData' => [ + 'arguments' => [ + 'type1' => serialize(['argument1_1' => 'argumentValue1_1', 'argument1_2' => 'argumentValue1_2']) + ], + 'instanceTypes' => [ + 'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'instanceTypeValue2' + ], + 'preferences' => ['preference1' => 'preferenceValue1', 'preference2' => 'preferenceValue2'] + ], + 'configuration' => [ + 'arguments' => [ + 'type1' => serialize(['argument1_1' => 'newArgumentValue1_1']), + 'type2' => serialize(['argument2_1' => 'newArgumentValue2_1']) + ], + 'instanceTypes' => [ + 'instanceType2' => 'newInstanceTypeValue2', 'instanceType3' => 'newInstanceTypeValue3' + ], + 'preferences' => ['preference1' => 'newPreferenceValue1'] + ], + 'expectedArguments' => [ + 'type1' => ['argument1_1' => 'newArgumentValue1_1'], + 'type2' => ['argument2_1' => 'newArgumentValue2_1'] + ], + 'expectedVirtualTypes' => [ + 'instanceType1' => 'instanceTypeValue1', 'instanceType2' => 'newInstanceTypeValue2', + 'instanceType3' => 'newInstanceTypeValue3' + ], + 'expectedPreferences' => [ + 'preference1' => 'newPreferenceValue1', 'preference2' => 'preferenceValue2' + ] + ] + ]; + } +}