getValue();
+ return 'category_ids_index.category_id = ' . (int) $filter->getValue();
} elseif ($attribute->isStatic()) {
$alias = $this->tableMapper->getMappingAlias($filter);
$resultQuery = str_replace(
@@ -194,10 +194,10 @@ private function processTermSelect(FilterInterface $filter, $isNegation)
$value = sprintf(
'%s IN (%s)',
($isNegation ? 'NOT' : ''),
- implode(',', $filter->getValue())
+ implode(',', array_map([$this->connection, 'quote'], $filter->getValue()))
);
} else {
- $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
+ $value = ($isNegation ? '!' : '') . '= ' . $this->connection->quote($filter->getValue());
}
$resultQuery = sprintf(
'%1$s.value %2$s',
diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php
index ccc83be62eb11..368fdb039fdf4 100644
--- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php
+++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php
@@ -104,7 +104,7 @@ protected function setUp()
->getMock();
$this->connection = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')
->disableOriginalConstructor()
- ->setMethods(['select', 'getIfNullSql'])
+ ->setMethods(['select', 'getIfNullSql', 'quote'])
->getMockForAbstractClass();
$this->select = $this->getMockBuilder('\Magento\Framework\DB\Select')
->disableOriginalConstructor()
@@ -170,9 +170,25 @@ public function testProcessPrice()
$this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
}
- public function testProcessCategoryIds()
+ /**
+ * @return array
+ */
+ public function processCategoryIdsDataProvider()
+ {
+ return [
+ ['5', 'category_ids_index.category_id = 5'],
+ [3, 'category_ids_index.category_id = 3'],
+ ["' and 1 = 0", 'category_ids_index.category_id = 0'],
+ ];
+ }
+
+ /**
+ * @param string|int $categoryId
+ * @param string $expectedResult
+ * @dataProvider processCategoryIdsDataProvider
+ */
+ public function testProcessCategoryIds($categoryId, $expectedResult)
{
- $expectedResult = 'category_ids_index.category_id = FilterValue';
$isNegation = false;
$query = 'SELECT category_ids FROM catalog_product_entity';
@@ -182,7 +198,7 @@ public function testProcessCategoryIds()
$this->filter->expects($this->once())
->method('getValue')
- ->will($this->returnValue('FilterValue'));
+ ->will($this->returnValue($categoryId));
$this->config->expects($this->exactly(1))
->method('getAttribute')
@@ -249,6 +265,7 @@ public function testProcessTermFilter($frontendInput, $fieldValue, $isNegation,
->method('getValue')
->willReturn($fieldValue);
+ $this->connection->expects($this->atLeastOnce())->method('quote')->willReturnArgument(0);
$actualResult = $this->target->process($this->filter, $isNegation, 'This filter is not depends on used query');
$this->assertSame($expected, $this->removeWhitespaces($actualResult));
}
diff --git a/app/code/Magento/Checkout/Controller/Cart/Delete.php b/app/code/Magento/Checkout/Controller/Cart/Delete.php
index 3d73a5f0c205a..fae9903a845e1 100644
--- a/app/code/Magento/Checkout/Controller/Cart/Delete.php
+++ b/app/code/Magento/Checkout/Controller/Cart/Delete.php
@@ -15,6 +15,10 @@ class Delete extends \Magento\Checkout\Controller\Cart
*/
public function execute()
{
+ if (!$this->_formKeyValidator->validate($this->getRequest())) {
+ return $this->resultRedirectFactory->create()->setPath('*/*/');
+ }
+
$id = (int)$this->getRequest()->getParam('id');
if ($id) {
try {
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js b/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js
index 6872c8e5acd54..f3f1c012790ae 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js
@@ -12,6 +12,9 @@ define(
function($, address, customerData, mageUtils) {
'use strict';
var countryData = customerData.get('directory-data');
+ if (_.isEmpty(countryData())) {
+ countryData(customerData.reload(['directory-data'], false));
+ }
return {
/**
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js
index 0b3290b3c3960..55a9a90504075 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js
@@ -50,6 +50,10 @@ define(
});
addressOptions.push(newAddressOption);
+ if (_.isEmpty(countryData())) {
+ countryData(customerData.reload(['directory-data'], false));
+ }
+
return Component.extend({
defaults: {
template: 'Magento_Checkout/billing-address'
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js
index 0b932a29e52d9..b2d558dcf804f 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-address/address-renderer/default.js
@@ -15,6 +15,10 @@ define([
], function($, ko, Component, selectShippingAddressAction, quote, formPopUpState, checkoutData, customerData) {
'use strict';
var countryData = customerData.get('directory-data');
+ if (_.isEmpty(countryData())) {
+ countryData(customerData.reload(['directory-data'], false));
+ }
+
return Component.extend({
defaults: {
template: 'Magento_Checkout/shipping-address/address-renderer/default'
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/address-renderer/default.js b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/address-renderer/default.js
index 59c4911fc992c..128e9f4549859 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/address-renderer/default.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping-information/address-renderer/default.js
@@ -9,6 +9,10 @@ define([
], function(Component, customerData) {
'use strict';
var countryData = customerData.get('directory-data');
+ if (_.isEmpty(countryData())) {
+ countryData(customerData.reload(['directory-data'], false));
+ }
+
return Component.extend({
defaults: {
template: 'Magento_Checkout/shipping-information/address-renderer/default'
diff --git a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html
index 3c87e88b6ad65..9efc76a8ee05a 100644
--- a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html
+++ b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html
@@ -6,7 +6,7 @@
-->
-
+
diff --git a/app/code/Magento/Config/Model/Config/Backend/Image/Adapter.php b/app/code/Magento/Config/Model/Config/Backend/Image/Adapter.php
index 23e65a6e1d11c..be7c4739b53f2 100644
--- a/app/code/Magento/Config/Model/Config/Backend/Image/Adapter.php
+++ b/app/code/Magento/Config/Model/Config/Backend/Image/Adapter.php
@@ -53,7 +53,7 @@ public function beforeSave()
try {
$this->_imageFactory->create($this->getValue());
} catch (\Exception $e) {
- $message = __('The specified image adapter cannot be used because of: ' . $e->getMessage());
+ $message = __('The specified image adapter cannot be used because of: %1', $e->getMessage());
throw new \Magento\Framework\Exception\LocalizedException($message);
}
diff --git a/app/code/Magento/Config/Model/Config/Compiler/IncludeElement.php b/app/code/Magento/Config/Model/Config/Compiler/IncludeElement.php
index 941cdc8529a1b..977cd035a1c04 100644
--- a/app/code/Magento/Config/Model/Config/Compiler/IncludeElement.php
+++ b/app/code/Magento/Config/Model/Config/Compiler/IncludeElement.php
@@ -112,6 +112,6 @@ protected function getContent($includePath)
return $directoryRead->readFile($path);
}
- throw new LocalizedException(__('The file "' . $path . '" does not exist'));
+ throw new LocalizedException(__('The file "%1" does not exist', $path));
}
}
diff --git a/app/code/Magento/Cookie/Model/Config/Backend/Domain.php b/app/code/Magento/Cookie/Model/Config/Backend/Domain.php
index 2f84b6d2fd067..1aeefdf6f7310 100644
--- a/app/code/Magento/Cookie/Model/Config/Backend/Domain.php
+++ b/app/code/Magento/Cookie/Model/Config/Backend/Domain.php
@@ -50,7 +50,7 @@ public function beforeSave()
// Empty value is treated valid and will be handled when read the value out
if (!empty($value) && !$this->configValidator->isValid($value)) {
- $msg = __('Invalid domain name: ' . join('; ', $this->configValidator->getMessages()));
+ $msg = __('Invalid domain name: %1', join('; ', $this->configValidator->getMessages()));
throw new \Magento\Framework\Exception\LocalizedException($msg);
}
}
diff --git a/app/code/Magento/Cookie/Model/Config/Backend/Lifetime.php b/app/code/Magento/Cookie/Model/Config/Backend/Lifetime.php
index 9d650159e4501..c7f418f92152e 100644
--- a/app/code/Magento/Cookie/Model/Config/Backend/Lifetime.php
+++ b/app/code/Magento/Cookie/Model/Config/Backend/Lifetime.php
@@ -49,7 +49,7 @@ public function beforeSave()
$value = $this->getValue();
if (!empty($value) && !$this->configValidator->isValid($value)) {
- $msg = __('Invalid cookie lifetime: ' . join('; ', $this->configValidator->getMessages()));
+ $msg = __('Invalid cookie lifetime: %1', join('; ', $this->configValidator->getMessages()));
throw new \Magento\Framework\Exception\LocalizedException($msg);
}
return parent::beforeSave();
diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml
index ae600be3c5c8a..0b78824ef4807 100644
--- a/app/code/Magento/Cron/etc/di.xml
+++ b/app/code/Magento/Cron/etc/di.xml
@@ -36,4 +36,11 @@
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php
index b77183b6c05f3..d09156a107ebb 100644
--- a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php
+++ b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php
@@ -497,7 +497,7 @@ public function getBackend()
}
$backend = $this->_universalFactory->create($this->getBackendModel());
if (!$backend) {
- throw new LocalizedException(__('Invalid backend model specified: ' . $this->getBackendModel()));
+ throw new LocalizedException(__('Invalid backend model specified: %1', $this->getBackendModel()));
}
$this->_backend = $backend->setAttribute($this);
}
diff --git a/app/code/Magento/Eav/i18n/en_US.csv b/app/code/Magento/Eav/i18n/en_US.csv
index 37bc177bd3572..df3f5cced4c3a 100644
--- a/app/code/Magento/Eav/i18n/en_US.csv
+++ b/app/code/Magento/Eav/i18n/en_US.csv
@@ -71,7 +71,7 @@ Letters,Letters
"Invalid default decimal value","Invalid default decimal value"
"Invalid default date","Invalid default date"
"Invalid entity supplied","Invalid entity supplied"
-"Invalid backend model specified: ","Invalid backend model specified: "
+"Invalid backend model specified: %1","Invalid backend model specified: %1"
"Source model ""%1"" not found for attribute ""%2""","Source model ""%1"" not found for attribute ""%2"""
"The value of attribute ""%1"" must be unique","The value of attribute ""%1"" must be unique"
"Invalid date","Invalid date"
diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php
index 645c2d7aff607..7d285c36ee96d 100644
--- a/app/code/Magento/Email/Model/Template/Filter.php
+++ b/app/code/Magento/Email/Model/Template/Filter.php
@@ -920,7 +920,7 @@ public function applyInlineCss($html)
!== false
) {
throw new \Magento\Framework\Exception\MailException(
- __('
' . PHP_EOL . $cssToInline . PHP_EOL . '
')
+ __('
%1
', PHP_EOL . $cssToInline . PHP_EOL)
);
}
diff --git a/app/code/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserver.php b/app/code/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserver.php
new file mode 100644
index 0000000000000..fe6fc525e044f
--- /dev/null
+++ b/app/code/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserver.php
@@ -0,0 +1,72 @@
+dataHelper = $dataHelper;
+ }
+
+ /**
+ * Adds Google Experiment fields to category creation form on product edit page
+ *
+ * @param EventObserver $observer
+ * @return void
+ */
+ public function execute(EventObserver $observer)
+ {
+ if ($this->dataHelper->isGoogleExperimentActive()) {
+ $block = $observer->getEvent()->getBlock();
+ if ($block->getForm() && $block->getForm()->getId() == 'new_category_form') {
+ $fieldset = $block->getForm()->getElement('new_category_form_fieldset');
+ $fieldset->addField(
+ 'experiment_script',
+ 'textarea',
+ [
+ 'name' => 'google_experiment[experiment_script]',
+ 'label' => __('Experiment Code'),
+ 'value' => '',
+ 'class' => 'textarea googleoptimizer',
+ 'required' => false,
+ 'note' => __('Experiment code should be added to the original page only.')
+ ]
+ );
+
+ $fieldset->addField(
+ 'code_id',
+ 'hidden',
+ [
+ 'name' => 'google_experiment[code_id]',
+ 'value' => '',
+ 'required' => false
+ ]
+ );
+ }
+ }
+ }
+}
diff --git a/app/code/Magento/GoogleOptimizer/etc/events.xml b/app/code/Magento/GoogleOptimizer/etc/events.xml
index bb71f28673684..3595289a987aa 100644
--- a/app/code/Magento/GoogleOptimizer/etc/events.xml
+++ b/app/code/Magento/GoogleOptimizer/etc/events.xml
@@ -27,4 +27,7 @@
+
+
+
diff --git a/app/code/Magento/PageCache/etc/adminhtml/system.xml b/app/code/Magento/PageCache/etc/adminhtml/system.xml
index b6c79ee8c853f..fe6b8c6f85b14 100644
--- a/app/code/Magento/PageCache/etc/adminhtml/system.xml
+++ b/app/code/Magento/PageCache/etc/adminhtml/system.xml
@@ -18,7 +18,7 @@
- IPs access list separated with ',' that can purge Varnish configuration for config file generation.
+ IPs access list separated with \',\' that can purge Varnish configuration for config file generation.
If field is empty default value localhost will be saved.
Magento\PageCache\Model\System\Config\Backend\Varnish
diff --git a/app/code/Magento/RequireJs/Block/Html/Head/Config.php b/app/code/Magento/RequireJs/Block/Html/Head/Config.php
index 8eec827a91fdb..07e91e0877228 100644
--- a/app/code/Magento/RequireJs/Block/Html/Head/Config.php
+++ b/app/code/Magento/RequireJs/Block/Html/Head/Config.php
@@ -119,16 +119,4 @@ protected function _prepareLayout()
return parent::_prepareLayout();
}
-
- /**
- * Include base RequireJs configuration necessary for working with Magento application
- *
- * @return string|void
- */
- protected function _toHtml()
- {
- return "\n";
- }
}
diff --git a/app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php b/app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php
index e976f7563a845..32adea00ffbdc 100644
--- a/app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php
+++ b/app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php
@@ -131,35 +131,4 @@ public function testSetLayout()
);
$object->setLayout($layout);
}
-
- public function testToHtml()
- {
- $this->context->expects($this->once())
- ->method('getEventManager')
- ->will($this->returnValue($this->getMockForAbstractClass('\Magento\Framework\Event\ManagerInterface')));
- $this->context->expects($this->once())
- ->method('getScopeConfig')
- ->will($this->returnValue(
- $this->getMockForAbstractClass('\Magento\Framework\App\Config\ScopeConfigInterface')
- ));
- $this->config->expects($this->once())->method('getBaseConfig')->will($this->returnValue('the config data'));
- $this->minificationMock = $this->getMockBuilder('Magento\Framework\View\Asset\Minification')
- ->disableOriginalConstructor()
- ->getMock();
-
- $object = new Config(
- $this->context,
- $this->config,
- $this->fileManager,
- $this->pageConfig,
- $this->bundleConfig,
- $this->minificationMock
- );
- $html = $object->toHtml();
- $expectedFormat = <<
-the config data
-expected;
- $this->assertStringMatchesFormat($expectedFormat, $html);
- }
}
diff --git a/app/code/Magento/Review/Controller/Product/Post.php b/app/code/Magento/Review/Controller/Product/Post.php
index a68f0d18c3bc5..e20872b41dcd6 100644
--- a/app/code/Magento/Review/Controller/Product/Post.php
+++ b/app/code/Magento/Review/Controller/Product/Post.php
@@ -37,10 +37,10 @@ public function execute()
$data = $this->getRequest()->getPostValue();
$rating = $this->getRequest()->getParam('ratings', []);
}
-
if (($product = $this->initProduct()) && !empty($data)) {
/** @var \Magento\Review\Model\Review $review */
$review = $this->reviewFactory->create()->setData($data);
+ $review->unsetData('review_id');
$validate = $review->validate();
if ($validate === true) {
diff --git a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php
index 9cedb87e15afe..38f1a27a4d430 100644
--- a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php
+++ b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php
@@ -127,7 +127,7 @@ public function setUp()
'\Magento\Review\Model\Review',
[
'setData', 'validate', 'setEntityId', 'getEntityIdByCode', 'setEntityPkValue', 'setStatusId',
- 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate'
+ 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate', 'unsetData'
],
[],
'',
@@ -219,7 +219,10 @@ public function setUp()
*/
public function testExecute()
{
- $ratingsData = ['ratings' => [1 => 1]];
+ $reviewData = [
+ 'ratings' => [1 => 1],
+ 'review_id' => 2
+ ];
$productId = 1;
$customerId = 1;
$storeId = 1;
@@ -230,7 +233,7 @@ public function testExecute()
->willReturn(true);
$this->reviewSession->expects($this->any())->method('getFormData')
->with(true)
- ->willReturn($ratingsData);
+ ->willReturn($reviewData);
$this->request->expects($this->at(0))->method('getParam')
->with('category', false)
->willReturn(false);
@@ -260,7 +263,7 @@ public function testExecute()
->with('product', $product)
->willReturnSelf();
$this->review->expects($this->once())->method('setData')
- ->with($ratingsData)
+ ->with($reviewData)
->willReturnSelf();
$this->review->expects($this->once())->method('validate')
->willReturn(true);
@@ -270,6 +273,7 @@ public function testExecute()
$this->review->expects($this->once())->method('setEntityId')
->with(1)
->willReturnSelf();
+ $this->review->expects($this->once())->method('unsetData')->with('review_id');
$product->expects($this->exactly(2))
->method('getId')
->willReturn($productId);
diff --git a/app/code/Magento/Sales/Helper/Guest.php b/app/code/Magento/Sales/Helper/Guest.php
index a69fa337b8da2..c5c755bda8d17 100644
--- a/app/code/Magento/Sales/Helper/Guest.php
+++ b/app/code/Magento/Sales/Helper/Guest.php
@@ -176,7 +176,7 @@ public function loadValidOrder(App\RequestInterface $request)
$errors = true;
if (!empty($protectCode) && !empty($incrementId)) {
$order->loadByIncrementId($incrementId);
- if ($order->getProtectCode() == $protectCode) {
+ if ($order->getProtectCode() === $protectCode) {
// renew cookie
$this->setGuestViewCookie($fromCookie);
$errors = false;
diff --git a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php
index 8b3ca20ca09c9..6a8ada8a43693 100644
--- a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php
+++ b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
if (!empty($sampleDataPackages)) {
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
- $commonArgs = ['--working-dir' => $baseDir, '--no-interaction' => 1, '--no-progress' => 1];
+ $commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1];
$packages = [];
foreach ($sampleDataPackages as $name => $version) {
$packages[] = "$name:$version";
diff --git a/app/code/Magento/Search/Model/Query.php b/app/code/Magento/Search/Model/Query.php
index 894d8d69f3646..2819a6e2ec570 100644
--- a/app/code/Magento/Search/Model/Query.php
+++ b/app/code/Magento/Search/Model/Query.php
@@ -172,6 +172,12 @@ public function getSuggestCollection()
public function loadByQuery($text)
{
$this->_getResource()->loadByQuery($this, $text);
+
+ $synonymFor = $this->getSynonymFor();
+ if (!empty($synonymFor)) {
+ $this->setQueryText($synonymFor);
+ }
+
$this->_afterLoad();
$this->setOrigData();
return $this;
diff --git a/app/code/Magento/Theme/view/frontend/layout/default.xml b/app/code/Magento/Theme/view/frontend/layout/default.xml
index e34fc0ad52988..abcfc0905f650 100644
--- a/app/code/Magento/Theme/view/frontend/layout/default.xml
+++ b/app/code/Magento/Theme/view/frontend/layout/default.xml
@@ -8,6 +8,7 @@
+
diff --git a/app/code/Magento/Theme/view/frontend/templates/page/js/require_js.phtml b/app/code/Magento/Theme/view/frontend/templates/page/js/require_js.phtml
new file mode 100644
index 0000000000000..7928160420a79
--- /dev/null
+++ b/app/code/Magento/Theme/view/frontend/templates/page/js/require_js.phtml
@@ -0,0 +1,11 @@
+
+
diff --git a/app/code/Magento/Ui/Component/Form.php b/app/code/Magento/Ui/Component/Form.php
index 24f4f5ed60436..41088748c0fd7 100644
--- a/app/code/Magento/Ui/Component/Form.php
+++ b/app/code/Magento/Ui/Component/Form.php
@@ -53,21 +53,22 @@ public function getComponentName()
public function getDataSourceData()
{
$dataSource = [];
- $id = $this->getContext()->getRequestParam($this->getContext()->getDataProvider()->getRequestFieldName());
+ $id = $this->getContext()->getRequestParam($this->getContext()->getDataProvider()->getRequestFieldName());
if ($id) {
$filter = $this->filterBuilder->setField($this->getContext()->getDataProvider()->getPrimaryFieldName())
->setValue($id)
->create();
$this->getContext()->getDataProvider()
->addFilter($filter);
- }
- $data = $this->getContext()->getDataProvider()->getData();
- if (isset($data[$id])) {
- $dataSource = [
- 'data' => $data[$id]
- ];
+ $data = $this->getContext()->getDataProvider()->getData();
+
+ if (isset($data[$id])) {
+ $dataSource = [
+ 'data' => $data[$id]
+ ];
+ }
}
return $dataSource;
diff --git a/app/code/Magento/Ui/Component/Form/Field.php b/app/code/Magento/Ui/Component/Form/Field.php
index d2ff377ae5bd4..c79b162b8cab0 100644
--- a/app/code/Magento/Ui/Component/Form/Field.php
+++ b/app/code/Magento/Ui/Component/Form/Field.php
@@ -71,7 +71,8 @@ public function prepare()
$formElement = $this->getData('config/formElement');
if (null === $formElement) {
throw new LocalizedException(__(
- 'The configuration parameter "formElement" is a required for "' . $this->getName() . '" field.'
+ 'The configuration parameter "formElement" is a required for "%1" field.',
+ $this->getName()
));
}
// Create of wrapped component
diff --git a/app/code/Magento/Ui/Component/Layout/Tabs.php b/app/code/Magento/Ui/Component/Layout/Tabs.php
index 34021f0d8782d..66ff8693add39 100644
--- a/app/code/Magento/Ui/Component/Layout/Tabs.php
+++ b/app/code/Magento/Ui/Component/Layout/Tabs.php
@@ -96,6 +96,7 @@ public function build(UiComponentInterface $component)
* @param string $componentType
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function addChildren(array &$topNode, UiComponentInterface $component, $componentType)
{
@@ -137,8 +138,8 @@ protected function addChildren(array &$topNode, UiComponentInterface $component,
'type' => 'collection',
'config' => [
'active' => 1,
- 'removeLabel' => __('Remove ' . $label),
- 'addLabel' => __('Add New ' . $label),
+ 'removeLabel' => __('Remove %1', $label),
+ 'addLabel' => __('Add New %1', $label),
'removeMessage' => $childComponent->getData('config/removeMessage'),
'itemTemplate' => 'item_template',
],
@@ -148,7 +149,7 @@ protected function addChildren(array &$topNode, UiComponentInterface $component,
'component' => 'Magento_Ui/js/form/components/collection/item',
'childType' => 'group',
'config' => [
- 'label' => __('New ' . $label),
+ 'label' => __('New %1', $label),
],
'children' => $childrenStructure
]
diff --git a/app/code/Magento/Ui/Test/Unit/Component/FormTest.php b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php
new file mode 100644
index 0000000000000..b03c4ad72ffed
--- /dev/null
+++ b/app/code/Magento/Ui/Test/Unit/Component/FormTest.php
@@ -0,0 +1,208 @@
+contextMock = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\ContextInterface')
+ ->getMockForAbstractClass();
+ $this->filterBuilderMock = $this->getMockBuilder('Magento\Framework\Api\FilterBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->processorMock = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\Processor')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->contextMock->expects($this->any())
+ ->method('getProcessor')
+ ->willReturn($this->processorMock);
+
+ $this->processorMock->expects($this->once())
+ ->method('register');
+
+ $this->model = new Form(
+ $this->contextMock,
+ $this->filterBuilderMock
+ );
+ }
+
+ public function testGetComponentName()
+ {
+ $this->assertEquals(Form::NAME, $this->model->getComponentName());
+ }
+
+ public function testGetDataSourceData()
+ {
+ $requestFieldName = 'request_id';
+ $primaryFieldName = 'primary_id';
+ $fieldId = 44;
+ $row = ['key' => 'value'];
+ $data = [
+ $fieldId => $row,
+ ];
+ $dataSource = [
+ 'data' => $row,
+ ];
+
+ /** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */
+ $dataProviderMock =
+ $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface')
+ ->getMock();
+ $dataProviderMock->expects($this->once())
+ ->method('getRequestFieldName')
+ ->willReturn($requestFieldName);
+ $dataProviderMock->expects($this->once())
+ ->method('getPrimaryFieldName')
+ ->willReturn($primaryFieldName);
+
+ $this->contextMock->expects($this->any())
+ ->method('getDataProvider')
+ ->willReturn($dataProviderMock);
+ $this->contextMock->expects($this->once())
+ ->method('getRequestParam')
+ ->with($requestFieldName)
+ ->willReturn($fieldId);
+
+ /** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */
+ $filterMock = $this->getMockBuilder('Magento\Framework\Api\Filter')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->filterBuilderMock->expects($this->once())
+ ->method('setField')
+ ->with($primaryFieldName)
+ ->willReturnSelf();
+ $this->filterBuilderMock->expects($this->once())
+ ->method('setValue')
+ ->with($fieldId)
+ ->willReturnSelf();
+ $this->filterBuilderMock->expects($this->once())
+ ->method('create')
+ ->willReturn($filterMock);
+
+ $dataProviderMock->expects($this->once())
+ ->method('addFilter')
+ ->with($filterMock);
+ $dataProviderMock->expects($this->once())
+ ->method('getData')
+ ->willReturn($data);
+
+ $this->assertEquals($dataSource, $this->model->getDataSourceData());
+ }
+
+ public function testGetDataSourceDataWithoutData()
+ {
+ $requestFieldName = 'request_id';
+ $primaryFieldName = 'primary_id';
+ $fieldId = 44;
+ $data = [];
+ $dataSource = [];
+
+ /** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */
+ $dataProviderMock =
+ $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface')
+ ->getMock();
+ $dataProviderMock->expects($this->once())
+ ->method('getRequestFieldName')
+ ->willReturn($requestFieldName);
+ $dataProviderMock->expects($this->once())
+ ->method('getPrimaryFieldName')
+ ->willReturn($primaryFieldName);
+
+ $this->contextMock->expects($this->any())
+ ->method('getDataProvider')
+ ->willReturn($dataProviderMock);
+ $this->contextMock->expects($this->once())
+ ->method('getRequestParam')
+ ->with($requestFieldName)
+ ->willReturn($fieldId);
+
+ /** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */
+ $filterMock = $this->getMockBuilder('Magento\Framework\Api\Filter')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->filterBuilderMock->expects($this->once())
+ ->method('setField')
+ ->with($primaryFieldName)
+ ->willReturnSelf();
+ $this->filterBuilderMock->expects($this->once())
+ ->method('setValue')
+ ->with($fieldId)
+ ->willReturnSelf();
+ $this->filterBuilderMock->expects($this->once())
+ ->method('create')
+ ->willReturn($filterMock);
+
+ $dataProviderMock->expects($this->once())
+ ->method('addFilter')
+ ->with($filterMock);
+ $dataProviderMock->expects($this->once())
+ ->method('getData')
+ ->willReturn($data);
+
+ $this->assertEquals($dataSource, $this->model->getDataSourceData());
+ }
+
+ public function testGetDataSourceDataWithoutId()
+ {
+ $requestFieldName = 'request_id';
+ $dataSource = [];
+
+ /** @var DataProviderInterface|\PHPUnit_Framework_MockObject_MockObject $dataProviderMock */
+ $dataProviderMock =
+ $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface')
+ ->getMock();
+ $dataProviderMock->expects($this->once())
+ ->method('getRequestFieldName')
+ ->willReturn($requestFieldName);
+ $dataProviderMock->expects($this->never())
+ ->method('getPrimaryFieldName');
+
+ $this->contextMock->expects($this->any())
+ ->method('getDataProvider')
+ ->willReturn($dataProviderMock);
+ $this->contextMock->expects($this->once())
+ ->method('getRequestParam')
+ ->with($requestFieldName)
+ ->willReturn(null);
+
+ $this->filterBuilderMock->expects($this->never())
+ ->method('setField');
+ $this->filterBuilderMock->expects($this->never())
+ ->method('setValue');
+ $this->filterBuilderMock->expects($this->never())
+ ->method('create');
+
+ $dataProviderMock->expects($this->never())
+ ->method('addFilter');
+ $dataProviderMock->expects($this->never())
+ ->method('getData');
+
+ $this->assertEquals($dataSource, $this->model->getDataSourceData());
+ }
+}
diff --git a/app/code/Magento/Weee/Model/Tax.php b/app/code/Magento/Weee/Model/Tax.php
index b1293159031e9..d3de2f754ca00 100644
--- a/app/code/Magento/Weee/Model/Tax.php
+++ b/app/code/Magento/Weee/Model/Tax.php
@@ -344,7 +344,9 @@ public function getProductWeeeAttributes(
}
$one = new \Magento\Framework\DataObject();
- $one->setName(__($attribute['label_value'] ? $attribute['label_value'] : $attribute['frontend_label']))
+ $one->setName(
+ __($attribute['label_value']) ? __($attribute['label_value']) : __($attribute['frontend_label'])
+ )
->setAmount($amount)
->setTaxAmount($taxAmount)
->setAmountExclTax($amountExclTax)
diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php
index b005c52813a7b..5653f9c0ea46c 100644
--- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php
+++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFileTest.php
@@ -175,6 +175,25 @@ public function testValidate()
$this->assertEquals($this->expectedValidate(), $result);
}
+ public function testEmptyFile()
+ {
+ $this->prepareEnvForEmptyFile();
+
+ $this->setExpectedException(
+ '\Magento\Framework\Exception\LocalizedException',
+ 'The file is empty. Please choose another one'
+ );
+
+ $httpAdapterMock = $this->getMock('Zend_File_Transfer_Adapter_Http', ['isValid']);
+ $httpAdapterMock->expects($this->once())->method('isValid')->will($this->returnValue(true));
+ $this->httpFactoryMock->expects($this->once())->method('create')->will($this->returnValue($httpAdapterMock));
+
+ $this->model->validate(
+ $this->objectManager->create('Magento\Framework\DataObject'),
+ $this->getProductOption()
+ );
+ }
+
/**
* @param array $options
* @return \Magento\Catalog\Model\Product\Option
@@ -233,6 +252,27 @@ protected function prepareEnv()
];
}
+ /**
+ * Test exception for empty file
+ *
+ * @return void
+ */
+ protected function prepareEnvForEmptyFile()
+ {
+ $file = 'magento_empty.jpg';
+
+ /** @var \Magento\Framework\Filesystem $filesystem */
+ $filesystem = $this->objectManager->get('Magento\Framework\Filesystem');
+ $tmpDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
+ $filePath = $tmpDirectory->getAbsolutePath($file);
+
+ $_FILES['options_1_file'] = [
+ 'name' => 'test.jpg',
+ 'type' => 'image/jpeg',
+ 'tmp_name' => $filePath,
+ ];
+ }
+
/**
* @return array
*/
diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/magento_empty.jpg b/dev/tests/integration/testsuite/Magento/Catalog/_files/magento_empty.jpg
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/validate_image.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/validate_image.php
index 222ba1665b994..ab94752b170a2 100644
--- a/dev/tests/integration/testsuite/Magento/Catalog/_files/validate_image.php
+++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/validate_image.php
@@ -16,3 +16,6 @@
$targetTmpFilePath = $tmpDirectory->getAbsolutePath('magento_small_image.jpg');
copy(__DIR__ . '/magento_small_image.jpg', $targetTmpFilePath);
// Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
+
+$targetTmpFilePath = $tmpDirectory->getAbsolutePath('magento_empty.jpg');
+copy(__DIR__ . '/magento_empty.jpg', $targetTmpFilePath);
diff --git a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php
index 7dbb721cfc39f..d7c15828557fd 100644
--- a/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php
+++ b/dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php
@@ -66,4 +66,16 @@ public function testReadDirectoryRecursivelyFailure()
{
$this->driver->readDirectoryRecursively($this->getTestPath('not-existing-directory'));
}
+
+ public function testCreateDirectory()
+ {
+ $generatedPath = $this->getTestPath('generated/roo/bar/baz/foo');
+ $generatedPathBase = $this->getTestPath('generated');
+ // Delete the generated directory if it already exists
+ if (is_dir($generatedPath)) {
+ $this->assertTrue($this->driver->deleteDirectory($generatedPathBase));
+ }
+ $this->assertTrue($this->driver->createDirectory($generatedPath, '755'));
+ $this->assertTrue(is_dir($generatedPath));
+ }
}
diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php
index ef1ea1fd983ee..fb4873b17fd95 100644
--- a/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php
+++ b/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php
@@ -5,6 +5,8 @@
*/
namespace Magento\Framework\View\Element;
+use Magento\Framework\View\Element\AbstractBlock;
+
/**
* @magentoAppIsolation enabled
*/
@@ -556,7 +558,7 @@ public function testGetCacheKey()
$this->assertNotEquals($name, $key);
$block->setCacheKey('key');
- $this->assertEquals('key', $block->getCacheKey());
+ $this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . 'key', $block->getCacheKey());
}
/**
diff --git a/dev/tests/integration/testsuite/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserverTest.php b/dev/tests/integration/testsuite/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserverTest.php
new file mode 100644
index 0000000000000..319d9909682f5
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/GoogleOptimizer/Observer/Block/Category/AddGoogleExperimentFieldsObserverTest.php
@@ -0,0 +1,67 @@
+objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
+ $this->config = $this->objectManager->create(
+ 'Magento\Config\Model\ResourceModel\Config'
+ );
+ $this->config->saveConfig('google/analytics/active', 1, 'default', 0);
+ $this->config->saveConfig('google/analytics/type', 'universal', 'default', 0);
+ $this->config->saveConfig('google/analytics/experiments', 1, 'default', 0);
+ $this->config->saveConfig('google/analytics/account', 1234567890, 'default', 0);
+ $this->resetConfig();
+ }
+
+ /**
+ * @magentoAppIsolation enabled
+ * @magentoDbIsolation enabled
+ */
+ public function testExecute()
+ {
+ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
+ /** @var \Magento\Catalog\Block\Adminhtml\Product\Edit\NewCategory $newCategoryForm */
+ $newCategoryForm = $objectManager->get('Magento\Catalog\Block\Adminhtml\Product\Edit\NewCategory');
+ $html = $newCategoryForm->toHtml();
+ $this->assertContains('name="google_experiment[code_id]"', $html);
+ $this->assertContains('name="google_experiment[experiment_script]"', $html);
+ }
+
+ protected function tearDown()
+ {
+ $this->config->deleteConfig('google/analytics/active', 'default', 0);
+ $this->config->deleteConfig('google/analytics/type', 'default', 0);
+ $this->config->deleteConfig('google/analytics/experiments', 'default', 0);
+ $this->config->deleteConfig('google/analytics/account', 'default', 0);
+ $this->resetConfig();
+ }
+
+ /**
+ * Clear config cache
+ */
+ protected function resetConfig()
+ {
+ $this->objectManager->get('Magento\Framework\App\Config\ReinitableConfigInterface')->reinit();
+ }
+}
diff --git a/lib/internal/Magento/Framework/App/ResourceConnection/ConnectionFactory.php b/lib/internal/Magento/Framework/App/ResourceConnection/ConnectionFactory.php
index 7924f4babdac9..f054c815916c2 100644
--- a/lib/internal/Magento/Framework/App/ResourceConnection/ConnectionFactory.php
+++ b/lib/internal/Magento/Framework/App/ResourceConnection/ConnectionFactory.php
@@ -22,9 +22,9 @@ class ConnectionFactory extends ModelConnectionFactory
public function create(array $connectionConfig)
{
$connection = parent::create($connectionConfig);
- /** @var \Magento\Framework\App\Cache\Type\FrontendPool $pool */
- $pool = $this->objectManager->get(\Magento\Framework\App\Cache\Type\FrontendPool::class);
- $connection->setCacheAdapter($pool->get(DdlCache::TYPE_IDENTIFIER));
+ /** @var \Magento\Framework\DB\Adapter\DdlCache $ddlCache */
+ $ddlCache = $this->objectManager->get(\Magento\Framework\DB\Adapter\DdlCache::class);
+ $connection->setCacheAdapter($ddlCache);
return $connection;
}
}
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ResourceConnection/ConnectionFactoryTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ResourceConnection/ConnectionFactoryTest.php
index 8a1b7296bbff1..77e6c428ae9b2 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/ResourceConnection/ConnectionFactoryTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/ResourceConnection/ConnectionFactoryTest.php
@@ -5,8 +5,6 @@
*/
namespace Magento\Framework\App\Test\Unit\ResourceConnection;
-use Magento\Framework\DB\Adapter\DdlCache;
-
class ConnectionFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
@@ -38,7 +36,7 @@ protected function setUp()
public function testCreate()
{
- $cacheAdapterMock = $this->getMockBuilder('Magento\Framework\Cache\FrontendInterface')
+ $cacheAdapterMock = $this->getMockBuilder('Magento\Framework\DB\Adapter\DdlCache')
->disableOriginalConstructor()
->getMock();
$loggerMock = $this->getMockBuilder('Magento\Framework\DB\LoggerInterface')
@@ -63,19 +61,12 @@ public function testCreate()
->method('create')
->with('Magento\Framework\App\ResourceConnection\ConnectionAdapterInterface')
->will($this->returnValue($connectionAdapterMock));
- $poolMock = $this->getMockBuilder('Magento\Framework\App\Cache\Type\FrontendPool')
- ->disableOriginalConstructor()
- ->getMock();
- $poolMock->expects($this->once())
- ->method('get')
- ->with(DdlCache::TYPE_IDENTIFIER)
- ->will($this->returnValue($cacheAdapterMock));
$this->objectManagerMock->expects($this->any())
->method('get')
->will($this->returnValueMap(
[
['Magento\Framework\DB\LoggerInterface', $loggerMock],
- ['Magento\Framework\App\Cache\Type\FrontendPool', $poolMock],
+ ['Magento\Framework\DB\Adapter\DdlCache', $cacheAdapterMock],
]
));
$this->assertSame($connectionMock, $this->model->create(['active' => true]));
diff --git a/lib/internal/Magento/Framework/Config/Reader/Filesystem.php b/lib/internal/Magento/Framework/Config/Reader/Filesystem.php
index bbe3544318f84..e1b271f9bd0f1 100644
--- a/lib/internal/Magento/Framework/Config/Reader/Filesystem.php
+++ b/lib/internal/Magento/Framework/Config/Reader/Filesystem.php
@@ -67,6 +67,16 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
*/
protected $validationState;
+ /**
+ * @var string
+ */
+ protected $_defaultScope;
+
+ /**
+ * @var string
+ */
+ protected $_schemaFile;
+
/**
* Constructor
*
diff --git a/lib/internal/Magento/Framework/Event/Config/Converter.php b/lib/internal/Magento/Framework/Event/Config/Converter.php
index c06372a5c0732..f979ccedb1a36 100644
--- a/lib/internal/Magento/Framework/Event/Config/Converter.php
+++ b/lib/internal/Magento/Framework/Event/Config/Converter.php
@@ -38,7 +38,7 @@ public function convert($source)
$config['name'] = $observerNameNode->nodeValue;
$eventObservers[$observerNameNode->nodeValue] = $config;
}
- $output[$eventName] = $eventObservers;
+ $output[mb_strtolower($eventName)] = $eventObservers;
}
return $output;
}
diff --git a/lib/internal/Magento/Framework/Event/Manager.php b/lib/internal/Magento/Framework/Event/Manager.php
index 7f6916ddf1dc3..237cd1586577d 100644
--- a/lib/internal/Magento/Framework/Event/Manager.php
+++ b/lib/internal/Magento/Framework/Event/Manager.php
@@ -10,26 +10,19 @@
class Manager implements ManagerInterface
{
- /**
- * Events cache
- *
- * @var array
- */
- protected $_events = [];
-
/**
* Event invoker
*
* @var InvokerInterface
*/
- protected $_invoker;
+ protected $invoker;
/**
* Event config
*
* @var ConfigInterface
*/
- protected $_eventConfig;
+ protected $eventConfig;
/**
* @param InvokerInterface $invoker
@@ -37,8 +30,8 @@ class Manager implements ManagerInterface
*/
public function __construct(InvokerInterface $invoker, ConfigInterface $eventConfig)
{
- $this->_invoker = $invoker;
- $this->_eventConfig = $eventConfig;
+ $this->invoker = $invoker;
+ $this->eventConfig = $eventConfig;
}
/**
@@ -53,8 +46,9 @@ public function __construct(InvokerInterface $invoker, ConfigInterface $eventCon
*/
public function dispatch($eventName, array $data = [])
{
+ $eventName = mb_strtolower($eventName);
\Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
- foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
+ foreach ($this->eventConfig->getObservers($eventName) as $observerConfig) {
$event = new \Magento\Framework\Event($data);
$event->setName($eventName);
@@ -62,7 +56,7 @@ public function dispatch($eventName, array $data = [])
$wrapper->setData(array_merge(['event' => $event], $data));
\Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
- $this->_invoker->dispatch($observerConfig, $wrapper);
+ $this->invoker->dispatch($observerConfig, $wrapper);
\Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
}
\Magento\Framework\Profiler::stop('EVENT:' . $eventName);
diff --git a/lib/internal/Magento/Framework/Event/Test/Unit/Config/ConverterTest.php b/lib/internal/Magento/Framework/Event/Test/Unit/Config/ConverterTest.php
index e0c9593e5cf21..91bade40692c8 100644
--- a/lib/internal/Magento/Framework/Event/Test/Unit/Config/ConverterTest.php
+++ b/lib/internal/Magento/Framework/Event/Test/Unit/Config/ConverterTest.php
@@ -5,35 +5,44 @@
*/
namespace Magento\Framework\Event\Test\Unit\Config;
+use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
+use Magento\Framework\Event\Config\Converter;
+
class ConverterTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var \Magento\Framework\Event\Config\Converter
+ * @var Converter
*/
- protected $_model;
+ protected $model;
/**
* @var string
*/
- protected $_filePath;
+ protected $filePath;
/**
* @var \DOMDocument
*/
- protected $_source;
+ protected $source;
+
+ /**
+ * @var ObjectManagerHelper
+ */
+ protected $objectManagerHelper;
protected function setUp()
{
- $this->_filePath = __DIR__ . '/_files/';
- $this->_source = new \DOMDocument();
- $this->_model = new \Magento\Framework\Event\Config\Converter();
+ $this->objectManagerHelper = new ObjectManagerHelper($this);
+ $this->filePath = __DIR__ . '/_files/';
+ $this->source = new \DOMDocument();
+ $this->model = $this->objectManagerHelper->getObject(Converter::class);
}
public function testConvert()
{
- $this->_source->loadXML(file_get_contents($this->_filePath . 'event_config.xml'));
- $convertedFile = include $this->_filePath . 'event_config.php';
- $this->assertEquals($convertedFile, $this->_model->convert($this->_source));
+ $this->source->loadXML(file_get_contents($this->filePath . 'event_config.xml'));
+ $convertedFile = include $this->filePath . 'event_config.php';
+ $this->assertEquals($convertedFile, $this->model->convert($this->source));
}
/**
@@ -42,7 +51,7 @@ public function testConvert()
*/
public function testConvertThrowsExceptionWhenDomIsInvalid()
{
- $this->_source->loadXML(file_get_contents($this->_filePath . 'event_invalid_config.xml'));
- $this->_model->convert($this->_source);
+ $this->source->loadXML(file_get_contents($this->filePath . 'event_invalid_config.xml'));
+ $this->model->convert($this->source);
}
}
diff --git a/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.php b/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.php
index 141b0b4b927db..88d9961b928d2 100644
--- a/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.php
+++ b/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.php
@@ -15,5 +15,8 @@
'shared' => false,
'name' => 'observer_2',
],
+ ],
+ 'some_eventname' => [
+ 'observer_3' => ['instance' => 'instance_3', 'name' => 'observer_3'],
]
];
diff --git a/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.xml b/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.xml
index 87dcbc0d45972..228fa6b5251b8 100644
--- a/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.xml
+++ b/lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.xml
@@ -13,4 +13,7 @@
+
+
+
\ No newline at end of file
diff --git a/lib/internal/Magento/Framework/Event/Test/Unit/ManagerTest.php b/lib/internal/Magento/Framework/Event/Test/Unit/ManagerTest.php
index 6c519bc6fbbe3..43f79df53c2d9 100644
--- a/lib/internal/Magento/Framework/Event/Test/Unit/ManagerTest.php
+++ b/lib/internal/Magento/Framework/Event/Test/Unit/ManagerTest.php
@@ -5,6 +5,11 @@
*/
namespace Magento\Framework\Event\Test\Unit;
+use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
+use Magento\Framework\Event\InvokerInterface;
+use Magento\Framework\Event\ConfigInterface;
+use Magento\Framework\Event\Manager as EventManager;
+
/**
* Class ManagerTest
*
@@ -15,74 +20,74 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_invoker;
+ protected $invokerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_eventFactory;
+ protected $eventFactory;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_event;
+ protected $event;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_wrapperFactory;
+ protected $wrapperFactory;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_observer;
+ protected $observer;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
- protected $_eventConfigMock;
+ protected $eventConfigMock;
/**
* @var \Magento\Framework\Event\Manager
*/
- protected $_eventManager;
+ protected $eventManager;
+
+ /**
+ * @var ObjectManagerHelper
+ */
+ protected $objectManagerHelper;
protected function setUp()
{
- $this->_invoker = $this->getMock('Magento\Framework\Event\InvokerInterface');
- $this->_eventConfigMock = $this->getMock('Magento\Framework\Event\ConfigInterface');
+ $this->objectManagerHelper = new ObjectManagerHelper($this);
+ $this->invokerMock = $this->getMock(InvokerInterface::class);
+ $this->eventConfigMock = $this->getMock(ConfigInterface::class);
- $this->_eventManager = new \Magento\Framework\Event\Manager($this->_invoker, $this->_eventConfigMock);
+ $this->eventManager = $this->objectManagerHelper->getObject(
+ EventManager::class,
+ [
+ 'invoker' => $this->invokerMock,
+ 'eventConfig' => $this->eventConfigMock
+ ]
+ );
}
public function testDispatch()
{
- $this->_eventConfigMock->expects(
- $this->once()
- )->method(
- 'getObservers'
- )->with(
- 'some_event'
- )->will(
- $this->returnValue(
- ['observer' => ['instance' => 'class', 'method' => 'method', 'name' => 'observer']]
- )
- );
- $this->_eventManager->dispatch('some_event', ['123']);
+ $this->eventConfigMock->expects($this->once())
+ ->method('getObservers')
+ ->with('some_eventname')
+ ->willReturn(['observer' => ['instance' => 'class', 'method' => 'method', 'name' => 'observer']]);
+ $this->eventManager->dispatch('some_eventName', ['123']);
}
public function testDispatchWithEmptyEventObservers()
{
- $this->_eventConfigMock->expects(
- $this->once()
- )->method(
- 'getObservers'
- )->with(
- 'some_event'
- )->will(
- $this->returnValue([])
- );
- $this->_invoker->expects($this->never())->method('dispatch');
- $this->_eventManager->dispatch('some_event');
+ $this->eventConfigMock->expects($this->once())
+ ->method('getObservers')
+ ->with('some_event')
+ ->willReturn([]);
+ $this->invokerMock->expects($this->never())->method('dispatch');
+ $this->eventManager->dispatch('some_event');
}
}
diff --git a/lib/internal/Magento/Framework/Filesystem/Driver/File.php b/lib/internal/Magento/Framework/Filesystem/Driver/File.php
index 56b2b5b65ada1..422bc56001905 100644
--- a/lib/internal/Magento/Framework/Filesystem/Driver/File.php
+++ b/lib/internal/Magento/Framework/Filesystem/Driver/File.php
@@ -195,14 +195,39 @@ public function getParentDirectory($path)
*/
public function createDirectory($path, $permissions)
{
- $result = @mkdir($this->getScheme() . $path, $permissions, true);
+ return $this->mkdirRecursive($path, $permissions);
+ }
+
+ /**
+ * Create a directory recursively taking into account race conditions
+ *
+ * @param string $path
+ * @param int $permissions
+ * @return bool
+ * @throws FileSystemException
+ */
+ private function mkdirRecursive($path, $permissions)
+ {
+ $path = $this->getScheme() . $path;
+ if (is_dir($path)) {
+ return true;
+ }
+ $parentDir = dirname($path);
+ while (!is_dir($parentDir)) {
+ $this->mkdirRecursive($parentDir, $permissions);
+ }
+ $result = @mkdir($path, $permissions);
if (!$result) {
- throw new FileSystemException(
- new \Magento\Framework\Phrase(
- 'Directory "%1" cannot be created %2',
- [$path, $this->getWarningMessage()]
- )
- );
+ if (is_dir($path)) {
+ $result = true;
+ } else {
+ throw new FileSystemException(
+ new \Magento\Framework\Phrase(
+ 'Directory "%1" cannot be created %2',
+ [$path, $this->getWarningMessage()]
+ )
+ );
+ }
}
return $result;
}
diff --git a/lib/internal/Magento/Framework/RequireJs/Config.php b/lib/internal/Magento/Framework/RequireJs/Config.php
index 3c77d2172b553..8ba9118d4f9e8 100644
--- a/lib/internal/Magento/Framework/RequireJs/Config.php
+++ b/lib/internal/Magento/Framework/RequireJs/Config.php
@@ -54,7 +54,6 @@ class Config
*/
const FULL_CONFIG_TEMPLATE = <<getBaseConfig();
$customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
foreach ($customConfigFiles as $file) {
/** @var $fileReader \Magento\Framework\Filesystem\File\Read */
@@ -148,8 +146,8 @@ public function getConfig()
}
$fullConfig = str_replace(
- ['%function%', '%base%', '%usages%'],
- [$distributedConfig, $baseConfig],
+ ['%function%', '%usages%'],
+ [$distributedConfig],
self::FULL_CONFIG_TEMPLATE
);
diff --git a/lib/internal/Magento/Framework/RequireJs/Test/Unit/ConfigTest.php b/lib/internal/Magento/Framework/RequireJs/Test/Unit/ConfigTest.php
index 2480c753defb4..8bdb0432c7f2b 100644
--- a/lib/internal/Magento/Framework/RequireJs/Test/Unit/ConfigTest.php
+++ b/lib/internal/Magento/Framework/RequireJs/Test/Unit/ConfigTest.php
@@ -129,7 +129,6 @@ public function testGetConfig()
$expected = <<hasData('cache_key')) {
- return $this->getData('cache_key');
+ return static::CACHE_KEY_PREFIX . $this->getData('cache_key');
}
/**
* don't prevent recalculation by saving generated cache key
@@ -970,7 +975,7 @@ public function getCacheKey()
// ignore array keys
$key = implode('|', $key);
$key = sha1($key);
- return $key;
+ return static::CACHE_KEY_PREFIX . $key;
}
/**
diff --git a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php
index 660d1d9c5aa6b..c117472325c06 100644
--- a/lib/internal/Magento/Framework/View/Page/Config/Renderer.php
+++ b/lib/internal/Magento/Framework/View/Page/Config/Renderer.php
@@ -106,7 +106,7 @@ public function renderHeadContent()
*/
public function renderTitle()
{
- return '' . $this->pageConfig->getTitle()->get() . '' . "\n";
+ return '' . $this->escaper->escapeHtml($this->pageConfig->getTitle()->get()) . '' . "\n";
}
/**
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php
index f187f63c647f0..802a37b1690a3 100644
--- a/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/AbstractBlockTest.php
@@ -8,8 +8,30 @@
namespace Magento\Framework\View\Test\Unit\Element;
+use Magento\Framework\View\Element\AbstractBlock;
+use Magento\Framework\View\Element\Context;
+use Magento\Framework\Config\View;
+use Magento\Framework\View\ConfigInterface;
+
class AbstractBlockTest extends \PHPUnit_Framework_TestCase
{
+ /**
+ * @var AbstractBlock
+ */
+ protected $block;
+
+ /**
+ * @return void
+ */
+ protected function setUp()
+ {
+ $contextMock = $this->getMock(Context::class, [], [], '', false);
+ $this->block = $this->getMockForAbstractClass(
+ AbstractBlock::class,
+ ['context' => $contextMock]
+ );
+ }
+
/**
* @param string $expectedResult
* @param string $nameInLayout
@@ -18,11 +40,8 @@ class AbstractBlockTest extends \PHPUnit_Framework_TestCase
*/
public function testGetUiId($expectedResult, $nameInLayout, $methodArguments)
{
- /** @var $block \Magento\Framework\View\Element\AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
- $block = $this->getMockForAbstractClass('Magento\Framework\View\Element\AbstractBlock', [], '', false);
- $block->setNameInLayout($nameInLayout);
-
- $this->assertEquals($expectedResult, call_user_func_array([$block, 'getUiId'], $methodArguments));
+ $this->block->setNameInLayout($nameInLayout);
+ $this->assertEquals($expectedResult, call_user_func_array([$this->block, 'getUiId'], $methodArguments));
}
/**
@@ -57,46 +76,63 @@ public function getUiIdDataProvider()
];
}
+ /**
+ * @return void
+ */
public function testGetVar()
{
- $this->markTestIncomplete('MAGETWO-11727');
- $config = $this->getMock('Magento\Framework\Config\View', ['getVarValue'], [], '', false);
+ $config = $this->getMock(View::class, ['getVarValue'], [], '', false);
$module = uniqid();
- $config->expects(
- $this->at(0)
- )->method(
- 'getVarValue'
- )->with(
- 'Magento_Theme',
- 'v1'
- )->will(
- $this->returnValue('one')
- );
- $config->expects($this->at(1))->method('getVarValue')->with($module, 'v2')->will($this->returnValue('two'));
- $configManager = $this->getMock('Magento\Framework\View\ConfigInterface', [], [], '', false);
- $configManager->expects($this->exactly(2))->method('getViewConfig')->will($this->returnValue($config));
+ $config->expects($this->any())
+ ->method('getVarValue')
+ ->willReturnMap([
+ ['Magento_Theme', 'v1', 'one'],
+ [$module, 'v2', 'two']
+ ]);
+
+ $configManager = $this->getMock(ConfigInterface::class, [], [], '', false);
+ $configManager->expects($this->exactly(2))->method('getViewConfig')->willReturn($config);
- /** @var $block \Magento\Framework\View\Element\AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var $block AbstractBlock|\PHPUnit_Framework_MockObject_MockObject */
$params = ['viewConfig' => $configManager];
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$block = $this->getMockForAbstractClass(
- 'Magento\Framework\View\Element\AbstractBlock',
- $helper->getConstructArguments('Magento\Framework\View\Element\AbstractBlock', $params),
- uniqid('Magento\\Theme\\Block\\AbstractBlock\\')
+ AbstractBlock::class,
+ $helper->getConstructArguments(AbstractBlock::class, $params)
);
+ $block->setData('module_name', 'Magento_Theme');
$this->assertEquals('one', $block->getVar('v1'));
$this->assertEquals('two', $block->getVar('v2', $module));
}
+ /**
+ * @return void
+ */
public function testIsScopePrivate()
{
- $contextMock = $this->getMock('Magento\Framework\View\Element\Context', [], [], '', false);
- $block = $this->getMockForAbstractClass(
- 'Magento\Framework\View\Element\AbstractBlock',
- ['context' => $contextMock]
- );
- $this->assertEquals(false, $block->isScopePrivate());
+ $this->assertFalse($this->block->isScopePrivate());
+ }
+
+ /**
+ * @return void
+ */
+ public function testGetCacheKey()
+ {
+ $cacheKey = 'testKey';
+ $this->block->setData('cache_key', $cacheKey);
+ $this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
+ }
+
+ /**
+ * @return void
+ */
+ public function testGetCacheKeyByName()
+ {
+ $nameInLayout = 'testBlock';
+ $this->block->setNameInLayout($nameInLayout);
+ $cacheKey = sha1($nameInLayout);
+ $this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
}
}
diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php
index 62c52b45cc818..8164bd3bb18a2 100644
--- a/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php
+++ b/lib/internal/Magento/Framework/View/Test/Unit/Page/Config/RendererTest.php
@@ -179,11 +179,15 @@ public function testRenderTitle()
$this->pageConfigMock->expects($this->any())
->method('getTitle')
- ->will($this->returnValue($this->titleMock));
+ ->willReturn($this->titleMock);
$this->titleMock->expects($this->once())
->method('get')
- ->will($this->returnValue($title));
+ ->willReturn($title);
+
+ $this->escaperMock->expects($this->once())
+ ->method('escapeHtml')
+ ->willReturnArgument(0);
$this->assertEquals($expected, $this->renderer->renderTitle());
}
diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
index 8843fb66c2111..b9dbc3aebbda2 100644
--- a/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
@@ -161,15 +161,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
'application' => $excludedModulePaths,
'framework' => $excludedLibraryPaths
];
- $dataAttributesIncludePattern = [
- 'extension_attributes' => '/\/etc\/([a-zA-Z_]*\/extension_attributes|extension_attributes)\.xml$/'
- ];
$this->configureObjectManager($output);
- $operations = $this->getOperationsConfiguration(
- $compiledPathsList,
- $dataAttributesIncludePattern
- );
+ $operations = $this->getOperationsConfiguration($compiledPathsList);
try {
$this->cleanupFilesystem(
@@ -286,12 +280,10 @@ private function configureObjectManager(OutputInterface $output)
* Returns operations configuration
*
* @param array $compiledPathsList
- * @param array $dataAttributesIncludePattern
* @return array
*/
private function getOperationsConfiguration(
- array $compiledPathsList,
- array $dataAttributesIncludePattern
+ array $compiledPathsList
) {
$excludePatterns = [];
foreach ($this->excludedPathsList as $excludedPaths) {
@@ -299,20 +291,11 @@ private function getOperationsConfiguration(
}
$operations = [
- OperationFactory::PROXY_GENERATOR => [
- 'paths' => $compiledPathsList['application'],
- 'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
- 'excludePatterns' => $excludePatterns,
- ],
+ OperationFactory::PROXY_GENERATOR => [],
OperationFactory::REPOSITORY_GENERATOR => [
'paths' => $compiledPathsList['application'],
- 'filePatterns' => ['di' => '/\/etc\/([a-zA-Z_]*\/di|di)\.xml$/'],
- 'excludePatterns' => $excludePatterns,
- ],
- OperationFactory::DATA_ATTRIBUTES_GENERATOR => [
- 'paths' => $compiledPathsList['application'],
- 'filePatterns' => $dataAttributesIncludePattern
],
+ OperationFactory::DATA_ATTRIBUTES_GENERATOR => [],
OperationFactory::APPLICATION_CODE_GENERATOR => [
'paths' => [
$compiledPathsList['application'],
diff --git a/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php b/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php
index ea56ed13dbd4d..0958daf9ac20b 100644
--- a/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php
@@ -260,6 +260,9 @@ public function generateCode($generationDir, $fileExcludePatterns, $input)
$directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns)
);
}
+ $this->files['di'][] = $this->directoryList->getPath(
+ \Magento\Framework\App\Filesystem\DirectoryList::CONFIG
+ ) . '/di.xml';
$this->files['additional'] = [$input->getOption(self::INPUT_KEY_EXTRA_CLASSES_FILE)];
$repositoryScanner = new Scanner\RepositoryScanner();
$repositories = $repositoryScanner->collectEntities($this->files['di']);
diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ProxyGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ProxyGenerator.php
index ebfec0635b8bb..f5c79fec02f2e 100644
--- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ProxyGenerator.php
+++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ProxyGenerator.php
@@ -11,11 +11,6 @@
class ProxyGenerator implements OperationInterface
{
- /**
- * @var Scanner\DirectoryScanner
- */
- private $directoryScanner;
-
/**
* @var Scanner\XmlScanner
*/
@@ -27,18 +22,23 @@ class ProxyGenerator implements OperationInterface
private $data;
/**
- * @param Scanner\DirectoryScanner $directoryScanner
+ * @var Scanner\ConfigurationScanner
+ */
+ private $configurationScanner;
+
+ /**
* @param Scanner\XmlScanner $proxyScanner
+ * @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
- Scanner\DirectoryScanner $directoryScanner,
Scanner\XmlScanner $proxyScanner,
+ \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
- $this->directoryScanner = $directoryScanner;
$this->proxyScanner = $proxyScanner;
$this->data = $data;
+ $this->configurationScanner = $configurationScanner;
}
/**
@@ -48,19 +48,8 @@ public function __construct(
*/
public function doOperation()
{
- if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns'])
- !== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
- return;
- }
-
- $files = [];
- foreach ($this->data['paths'] as $path) {
- $files = array_merge_recursive(
- $files,
- $this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns'])
- );
- }
- $proxies = $this->proxyScanner->collectEntities($files['di']);
+ $files = $this->configurationScanner->scan('di.xml');
+ $proxies = $this->proxyScanner->collectEntities($files);
foreach ($proxies as $entityName) {
class_exists($entityName);
}
diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php
index 60d1159661528..2f51b34a11187 100644
--- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php
+++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/RepositoryGenerator.php
@@ -12,11 +12,6 @@
class RepositoryGenerator implements OperationInterface
{
- /**
- * @var Scanner\DirectoryScanner
- */
- private $directoryScanner;
-
/**
* @var Scanner\RepositoryScanner
*/
@@ -33,21 +28,26 @@ class RepositoryGenerator implements OperationInterface
private $classesScanner;
/**
- * @param Scanner\DirectoryScanner $directoryScanner
+ * @var Scanner\ConfigurationScanner
+ */
+ private $configurationScanner;
+
+ /**
* @param ClassesScanner $classesScanner
* @param Scanner\RepositoryScanner $repositoryScanner
+ * @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
- Scanner\DirectoryScanner $directoryScanner,
ClassesScanner $classesScanner,
Scanner\RepositoryScanner $repositoryScanner,
+ \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
- $this->directoryScanner = $directoryScanner;
$this->repositoryScanner = $repositoryScanner;
$this->data = $data;
$this->classesScanner = $classesScanner;
+ $this->configurationScanner = $configurationScanner;
}
/**
@@ -57,23 +57,12 @@ public function __construct(
*/
public function doOperation()
{
- if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns'])
- !== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
- return;
- }
-
foreach ($this->data['paths'] as $path) {
$this->classesScanner->getList($path);
}
$this->repositoryScanner->setUseAutoload(false);
- $files = [];
- foreach ($this->data['paths'] as $path) {
- $files = array_merge_recursive(
- $files,
- $this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns'])
- );
- }
- $repositories = $this->repositoryScanner->collectEntities($files['di']);
+ $files = $this->configurationScanner->scan('di.xml');
+ $repositories = $this->repositoryScanner->collectEntities($files);
foreach ($repositories as $entityName) {
class_exists($entityName);
}
diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php
index 0a28df86d27fc..2f80abd296d06 100644
--- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php
+++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ServiceDataAttributesGenerator.php
@@ -16,11 +16,6 @@
*/
class ServiceDataAttributesGenerator implements OperationInterface
{
- /**
- * @var Scanner\DirectoryScanner
- */
- private $directoryScanner;
-
/**
* @var Scanner\ServiceDataAttributesScanner
*/
@@ -32,18 +27,23 @@ class ServiceDataAttributesGenerator implements OperationInterface
private $data;
/**
- * @param Scanner\DirectoryScanner $directoryScanner
- * @param Scanner\ServiceDataAttributesScanner $repositoryScanner
+ * @var Scanner\ConfigurationScanner
+ */
+ private $configurationScanner;
+
+ /**
+ * @param Scanner\ServiceDataAttributesScanner $serviceDataAttributesScanner
+ * @param Scanner\ConfigurationScanner $configurationScanner
* @param array $data
*/
public function __construct(
- Scanner\DirectoryScanner $directoryScanner,
- Scanner\ServiceDataAttributesScanner $repositoryScanner,
+ Scanner\ServiceDataAttributesScanner $serviceDataAttributesScanner,
+ \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner $configurationScanner,
$data = []
) {
- $this->directoryScanner = $directoryScanner;
- $this->serviceDataAttributesScanner = $repositoryScanner;
+ $this->serviceDataAttributesScanner = $serviceDataAttributesScanner;
$this->data = $data;
+ $this->configurationScanner = $configurationScanner;
}
/**
@@ -53,15 +53,8 @@ public function __construct(
*/
public function doOperation()
{
- if (array_diff(array_keys($this->data), ['filePatterns', 'paths'])
- !== array_diff(['filePatterns', 'paths'], array_keys($this->data))) {
- return;
- }
- $files = [];
- foreach ($this->data['paths'] as $path) {
- $files = array_merge_recursive($files, $this->directoryScanner->scan($path, $this->data['filePatterns']));
- }
- $repositories = $this->serviceDataAttributesScanner->collectEntities($files['extension_attributes']);
+ $files = $this->configurationScanner->scan('extension_attributes.xml');
+ $repositories = $this->serviceDataAttributesScanner->collectEntities($files);
foreach ($repositories as $entityName) {
class_exists($entityName);
}
diff --git a/setup/src/Magento/Setup/Module/Di/Code/Scanner/ConfigurationScanner.php b/setup/src/Magento/Setup/Module/Di/Code/Scanner/ConfigurationScanner.php
new file mode 100644
index 0000000000000..90aed20512528
--- /dev/null
+++ b/setup/src/Magento/Setup/Module/Di/Code/Scanner/ConfigurationScanner.php
@@ -0,0 +1,48 @@
+fileResolver = $fileResolver;
+ $this->areaList = $areaList;
+ }
+
+ /**
+ * Scan configuration files
+ *
+ * @param string $fileName
+ *
+ * @return array array of paths to the configuration files
+ */
+ public function scan($fileName)
+ {
+ $files = [];
+ $areaCodes = array_merge(
+ ['primary', Area::AREA_GLOBAL],
+ $this->areaList->getCodes()
+ );
+ foreach ($areaCodes as $area) {
+ $files = array_merge_recursive(
+ $files,
+ $this->fileResolver->get($fileName, $area)->toArray()
+ );
+ }
+ return array_keys($files);
+ }
+}
diff --git a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php
index 55d060c895f8c..582ca2fcc2919 100644
--- a/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php
+++ b/setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php
@@ -93,7 +93,7 @@ public function setPhrase($phrase)
}
/**
- * Get quote type
+ * Get phrase
*
* @return string
*/
@@ -116,7 +116,7 @@ public function setQuote($quote)
}
/**
- * Get phrase
+ * Get quote type
*
* @return string
*/
@@ -269,7 +269,11 @@ public function getCompiledTranslation()
private function getCompiledString($string)
{
$encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
-
+ //find all occurrences of ' and ", with no \ before it.
+ preg_match_all('/(?directoryScannerMock = $this->getMockBuilder('Magento\Setup\Module\Di\Code\Scanner\DirectoryScanner')
- ->disableOriginalConstructor()
- ->getMock();
$this->proxyScannerMock = $this->getMockBuilder('Magento\Setup\Module\Di\Code\Scanner\XmlScanner')
->disableOriginalConstructor()
->getMock();
- }
-
- /**
- * @param array $data
- *
- * @dataProvider doOperationWrongDataDataProvider
- */
- public function testDoOperationWrongData($data)
- {
- $model = new ProxyGenerator(
- $this->directoryScannerMock,
- $this->proxyScannerMock,
- $data
- );
- $this->directoryScannerMock->expects($this->never())
- ->method('scan');
- $this->proxyScannerMock->expects($this->never())
- ->method('collectEntities');
-
- $this->assertEmpty($model->doOperation());
- }
+ $this->configurationScannerMock = $this->getMockBuilder(
+ 'Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner'
+ )->disableOriginalConstructor()
+ ->getMock();
- /**
- * @return array
- */
- public function doOperationWrongDataDataProvider()
- {
- return [
- [[]],
- [['filePatterns' => ['php' => '*.php']]],
- [['path' => 'path']],
- ];
+ $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $objectManagerHelper->getObject(
+ 'Magento\Setup\Module\Di\App\Task\Operation\ProxyGenerator',
+ [
+ 'proxyScanner' => $this->proxyScannerMock,
+ 'configurationScanner' => $this->configurationScannerMock,
+ ]
+ );
}
public function testDoOperation()
{
- $data = [
- 'paths' => ['path/to/app'],
- 'filePatterns' => ['di' => 'di.xml'],
- 'excludePatterns' => ['/\/Test\//'],
- ];
- $files = ['di' => []];
- $model = new ProxyGenerator(
- $this->directoryScannerMock,
- $this->proxyScannerMock,
- $data
- );
-
- $this->directoryScannerMock->expects($this->once())
+ $files = ['file1', 'file2'];
+ $this->configurationScannerMock->expects($this->once())
->method('scan')
- ->with(
- $data['paths'][0],
- $data['filePatterns']
- )->willReturn($files);
+ ->with('di.xml')
+ ->willReturn($files);
$this->proxyScannerMock->expects($this->once())
->method('collectEntities')
- ->with($files['di'])
+ ->with($files)
->willReturn([]);
- $this->assertEmpty($model->doOperation());
+ $this->model->doOperation();
}
}
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/RepositoryGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/RepositoryGeneratorTest.php
index 626ccfbe71346..cf8ab935db943 100644
--- a/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/RepositoryGeneratorTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/RepositoryGeneratorTest.php
@@ -12,11 +12,6 @@
class RepositoryGeneratorTest extends \PHPUnit_Framework_TestCase
{
- /**
- * @var Scanner\DirectoryScanner | \PHPUnit_Framework_MockObject_MockObject
- */
- private $directoryScannerMock;
-
/**
* @var Scanner\RepositoryScanner | \PHPUnit_Framework_MockObject_MockObject
*/
@@ -27,81 +22,59 @@ class RepositoryGeneratorTest extends \PHPUnit_Framework_TestCase
*/
private $classesScannerMock;
+
+ /**
+ * @var \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $configurationScannerMock;
+
+ /**
+ * @var \Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator
+ */
+ private $model;
+
protected function setUp()
{
- $this->directoryScannerMock = $this->getMockBuilder('Magento\Setup\Module\Di\Code\Scanner\DirectoryScanner')
- ->setMethods([])
- ->disableOriginalConstructor()
- ->getMock();
$this->repositoryScannerMock = $this->getMockBuilder('Magento\Setup\Module\Di\Code\Scanner\RepositoryScanner')
- ->setMethods([])
->disableOriginalConstructor()
->getMock();
$this->classesScannerMock = $this->getMockBuilder('Magento\Setup\Module\Di\Code\Reader\ClassesScanner')
- ->setMethods([])
->disableOriginalConstructor()
->getMock();
- }
-
- /**
- * @dataProvider wrongDataDataProvider
- */
- public function testDoOperationEmptyData($wrongData)
- {
- $model = new RepositoryGenerator(
- $this->directoryScannerMock,
- $this->classesScannerMock,
- $this->repositoryScannerMock,
- $wrongData
+ $this->configurationScannerMock = $this->getMockBuilder(
+ 'Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner'
+ )->disableOriginalConstructor()
+ ->getMock();
+ $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $objectManagerHelper->getObject(
+ 'Magento\Setup\Module\Di\App\Task\Operation\RepositoryGenerator',
+ [
+ 'repositoryScanner' => $this->repositoryScannerMock,
+ 'classesScanner' => $this->classesScannerMock,
+ 'configurationScanner' => $this->configurationScannerMock,
+ 'data' => ['paths' => ['path/to/app']]
+ ]
);
-
- $this->assertNull($model->doOperation());
- }
-
- /**
- * @return array
- */
- public function wrongDataDataProvider()
- {
- return [
- [[]],
- [['filePatterns' => ['php' => '*.php']]],
- [['path' => 'path']]
- ];
}
- public function testDoOperationEmptyRepositories()
+ public function testDoOperation()
{
- $data = [
- 'paths' => ['path/to/app'],
- 'filePatterns' => ['di' => 'di.xml'],
- 'excludePatterns' => ['/\/Test\//'],
- ];
- $files = ['di' => []];
- $model = new RepositoryGenerator(
- $this->directoryScannerMock,
- $this->classesScannerMock,
- $this->repositoryScannerMock,
- $data
- );
-
$this->classesScannerMock->expects($this->once())
->method('getList')
- ->with($data['paths'][0]);
- $this->directoryScannerMock->expects($this->once())
- ->method('scan')
- ->with(
- $data['paths'][0],
- $data['filePatterns']
- )->willReturn($files);
+ ->with('path/to/app');
$this->repositoryScannerMock->expects($this->once())
->method('setUseAutoload')
->with(false);
+ $files = ['file1', 'file2'];
+ $this->configurationScannerMock->expects($this->once())
+ ->method('scan')
+ ->with('di.xml')
+ ->willReturn($files);
$this->repositoryScannerMock->expects($this->once())
->method('collectEntities')
- ->with($files['di'])
+ ->with($files)
->willReturn([]);
- $this->assertEmpty($model->doOperation());
+ $this->model->doOperation();
}
}
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/ServiceDataAttributesGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/ServiceDataAttributesGeneratorTest.php
index b1b01608ea21d..3d97c1083927f 100644
--- a/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/ServiceDataAttributesGeneratorTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/App/Task/ServiceDataAttributesGeneratorTest.php
@@ -6,7 +6,6 @@
namespace Magento\Setup\Test\Unit\Module\Di\App\Task;
-use Magento\Setup\Module\Di\App\Task\Operation\ServiceDataAttributesGenerator;
use Magento\Setup\Module\Di\Code\Scanner;
/**
@@ -15,85 +14,52 @@
class ServiceDataAttributesGeneratorTest extends \PHPUnit_Framework_TestCase
{
/**
- * @var \Magento\Setup\Module\Di\Code\Scanner\DirectoryScanner|\PHPUnit_Framework_MockObject_MockObject
+ * @var \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner | \PHPUnit_Framework_MockObject_MockObject
*/
- private $directoryScannerMock;
-
+ private $configurationScannerMock;
+
/**
* @var \Magento\Setup\Module\Di\Code\Scanner\ServiceDataAttributesScanner|\PHPUnit_Framework_MockObject_MockObject
*/
private $serviceDataAttributesScannerMock;
- protected function setUp()
- {
- $this->directoryScannerMock = $this->getMock(
- 'Magento\Setup\Module\Di\Code\Scanner\DirectoryScanner',
- [],
- [],
- '',
- false
- );
- $this->serviceDataAttributesScannerMock = $this->getMock(
- 'Magento\Setup\Module\Di\Code\Scanner\ServiceDataAttributesScanner',
- [],
- [],
- '',
- false
- );
- }
-
/**
- * @param $data array
- * @dataProvider doOperationDataProvider
+ * @var \Magento\Setup\Module\Di\App\Task\Operation\ServiceDataAttributesGenerator
*/
- public function testDoOperationEmptyData($data)
- {
- $model = new ServiceDataAttributesGenerator(
- $this->directoryScannerMock,
- $this->serviceDataAttributesScannerMock,
- $data
- );
- $this->directoryScannerMock->expects($this->never())->method('scan');
+ private $model;
- $model->doOperation();
- }
-
- /**
- * @return array
- */
- public function doOperationDataProvider()
+ protected function setUp()
{
- return [
- [[]],
- [['filePatterns' => ['php' => '*.php']]],
- [['path' => 'path']]
- ];
+ $this->configurationScannerMock = $this->getMockBuilder(
+ 'Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner'
+ )->disableOriginalConstructor()
+ ->getMock();
+ $this->serviceDataAttributesScannerMock = $this->getMockBuilder(
+ 'Magento\Setup\Module\Di\Code\Scanner\ServiceDataAttributesScanner'
+ )->disableOriginalConstructor()
+ ->getMock();
+ $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $objectManagerHelper->getObject(
+ 'Magento\Setup\Module\Di\App\Task\Operation\ServiceDataAttributesGenerator',
+ [
+ 'serviceDataAttributesScanner' => $this->serviceDataAttributesScannerMock,
+ 'configurationScanner' => $this->configurationScannerMock,
+ ]
+ );
}
public function testDoOperation()
{
- $data = [
- 'paths' => ['path/to/app'],
- 'filePatterns' => ['di' => 'di.xml'],
- ];
- $files = ['extension_attributes' => []];
- $model = new ServiceDataAttributesGenerator(
- $this->directoryScannerMock,
- $this->serviceDataAttributesScannerMock,
- $data
- );
-
- $this->directoryScannerMock->expects($this->once())
+ $files = ['file1', 'file2'];
+ $this->configurationScannerMock->expects($this->once())
->method('scan')
- ->with(
- $data['paths'][0],
- $data['filePatterns']
- )->willReturn($files);
+ ->with('extension_attributes.xml')
+ ->willReturn($files);
$this->serviceDataAttributesScannerMock->expects($this->once())
->method('collectEntities')
- ->with($files['extension_attributes'])
+ ->with($files)
->willReturn([]);
- $model->doOperation();
+ $this->model->doOperation();
}
}
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/ConfigurationScannerTest.php b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/ConfigurationScannerTest.php
new file mode 100644
index 0000000000000..32e0398890464
--- /dev/null
+++ b/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Scanner/ConfigurationScannerTest.php
@@ -0,0 +1,64 @@
+fileResolverMock = $this->getMockBuilder('Magento\Framework\App\Config\FileResolver')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->areaListMock = $this->getMockBuilder('Magento\Framework\App\AreaList')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
+ $this->model = $objectManagerHelper->getObject(
+ 'Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner',
+ [
+ 'fileResolver' => $this->fileResolverMock,
+ 'areaList' => $this->areaListMock,
+ ]
+ );
+ }
+
+ public function testScan()
+ {
+ $codes = ['code1', 'code2'];
+ $iteratorMock = $this->getMockBuilder('Magento\Framework\Config\FileIterator')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->areaListMock->expects($this->once())
+ ->method('getCodes')
+ ->willReturn($codes);
+ $counts = count($codes) + 2;
+ $this->fileResolverMock->expects($this->exactly($counts))
+ ->method('get')
+ ->willReturn($iteratorMock);
+ $files = ['file1' => 'onefile', 'file2' => 'anotherfile'];
+ $iteratorMock->expects($this->exactly($counts))
+ ->method('toArray')
+ ->willReturn($files);
+ $this->assertEquals(array_keys($files), $this->model->scan('di.xml'));
+ }
+}