Skip to content

Commit

Permalink
Merge branch '2.4-develop' into save-checkout-address
Browse files Browse the repository at this point in the history
  • Loading branch information
Usik2203 committed Nov 4, 2020
2 parents d804a12 + 632a7c6 commit fad49b8
Show file tree
Hide file tree
Showing 439 changed files with 22,174 additions and 6,514 deletions.
8 changes: 4 additions & 4 deletions app/code/Magento/Analytics/Model/ReportWriter.php
Expand Up @@ -103,14 +103,14 @@ public function write(WriteInterface $directory, $path)
/**
* Replace wrong symbols in row
*
* Strip backslashes before double quotes so they will be properly escaped in the generated csv
*
* @see fputcsv()
* @param array $row
* @return array
*/
private function prepareRow(array $row): array
{
$row = preg_replace('/(?<!\\\\)"/', '\\"', $row);
$row = preg_replace('/[\\\\]+/', '\\', $row);

return $row;
return preg_replace('/\\\+(?=\")/', '', $row);
}
}
55 changes: 32 additions & 23 deletions app/code/Magento/Analytics/ReportXml/ConnectionFactory.php
Expand Up @@ -6,56 +6,65 @@

namespace Magento\Analytics\ReportXml;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ResourceConnection\ConfigInterface as ResourceConfigInterface;
use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactoryInterface;

/**
* Creates connection instance for export according to existing one
*
* This connection does not use buffered statement, also this connection is not persistent
*/
class ConnectionFactory
{
/**
* @var ResourceConnection
* @var ResourceConfigInterface
*/
private $resourceConnection;
private $resourceConfig;

/**
* @var ObjectManagerInterface
* @var DeploymentConfig
*/
private $objectManager;
private $deploymentConfig;

/**
* @param ResourceConnection $resourceConnection
* @param ObjectManagerInterface $objectManager
* @var ConnectionFactoryInterface
*/
private $connectionFactory;

/**
* @param ResourceConfigInterface $resourceConfig
* @param DeploymentConfig $deploymentConfig
* @param ConnectionFactoryInterface $connectionFactory
*/
public function __construct(
ResourceConnection $resourceConnection,
ObjectManagerInterface $objectManager
ResourceConfigInterface $resourceConfig,
DeploymentConfig $deploymentConfig,
ConnectionFactoryInterface $connectionFactory
) {
$this->resourceConnection = $resourceConnection;
$this->objectManager = $objectManager;
$this->resourceConfig = $resourceConfig;
$this->deploymentConfig = $deploymentConfig;
$this->connectionFactory = $connectionFactory;
}

/**
* Creates one-time connection for export
*
* @param string $connectionName
* @param string $resourceName
* @return AdapterInterface
*/
public function getConnection($connectionName)
public function getConnection($resourceName)
{
$connection = $this->resourceConnection->getConnection($connectionName);
$connectionClassName = get_class($connection);
$configData = $connection->getConfig();
$connectionName = $this->resourceConfig->getConnectionName($resourceName);
$configData = $this->deploymentConfig->get(
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/' . $connectionName
);
$configData['use_buffered_query'] = false;
unset($configData['persistent']);
return $this->objectManager->create(
$connectionClassName,
[
'config' => $configData
]
);
$connection = $this->connectionFactory->create($configData);

return $connection;
}
}
79 changes: 69 additions & 10 deletions app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php
Expand Up @@ -103,7 +103,7 @@ protected function setUp(): void
* @param array $expectedFileData
* @return void
*
* @dataProvider configDataProvider
* @dataProvider writeDataProvider
*/
public function testWrite(array $configData, array $fileData, array $expectedFileData): void
{
Expand Down Expand Up @@ -162,7 +162,7 @@ public function testWrite(array $configData, array $fileData, array $expectedFil
* @param array $configData
* @return void
*
* @dataProvider configDataProvider
* @dataProvider writeErrorFileDataProvider
*/
public function testWriteErrorFile(array $configData): void
{
Expand Down Expand Up @@ -195,10 +195,75 @@ public function testWriteEmptyReports(): void
/**
* @return array
*/
public function configDataProvider(): array
public function writeDataProvider(): array
{
$configData = [
'providers' => [
[
'name' => $this->providerName,
'class' => $this->providerClass,
'parameters' => [
'name' => $this->reportName
],
]
]
];
return [
[
'configData' => $configData,
'fileData' => [
['number' => 1, 'type' => 'Shoes\"" Usual\\\\"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'Shoes"" Usual"']
]
],
[
'configData' => $configData,
'fileData' => [
['number' => 1, 'type' => 'hello "World"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'hello "World"']
]
],
[
'configData' => $configData,
'fileData' => [
['number' => 1, 'type' => 'hello \"World\"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'hello "World"']
]
],
[
'configData' => $configData,
'fileData' => [
['number' => 1, 'type' => 'hello \\"World\\"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'hello "World"']
]
],
[
'configData' => $configData,
'fileData' => [
['number' => 1, 'type' => 'hello \\\"World\\\"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'hello "World"']
]
],
];
}

/**
* @return array
*/
public function writeErrorFileDataProvider(): array
{
return [
'reportProvider' => [
[
'configData' => [
'providers' => [
[
Expand All @@ -210,12 +275,6 @@ public function configDataProvider(): array
]
]
],
'fileData' => [
['number' => 1, 'type' => 'Shoes\"" Usual\\\\"']
],
'expectedFileData' => [
['number' => 1, 'type' => 'Shoes\"\" Usual\\"']
]
],
];
}
Expand Down
Expand Up @@ -8,40 +8,29 @@
namespace Magento\Analytics\Test\Unit\ReportXml;

use Magento\Analytics\ReportXml\ConnectionFactory;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ResourceConnection\ConfigInterface as ResourceConfigInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\DB\Adapter\Pdo\Mysql as MysqlPdoAdapter;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactoryInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ConnectionFactoryTest extends TestCase
{
/**
* @var ResourceConnection|MockObject
* @var ResourceConfigInterface|MockObject
*/
private $resourceConnectionMock;
private $resourceConfigMock;

/**
* @var ObjectManagerInterface|MockObject
* @var DeploymentConfig|MockObject
*/
private $objectManagerMock;
private $deploymentConfigMock;

/**
* @var ConnectionFactory|MockObject
* @var ConnectionFactoryInterface|MockObject
*/
private $connectionNewMock;

/**
* @var AdapterInterface|MockObject
*/
private $connectionMock;

/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;
private $connectionFactoryMock;

/**
* @var ConnectionFactory
Expand All @@ -53,47 +42,36 @@ class ConnectionFactoryTest extends TestCase
*/
protected function setUp(): void
{
$this->resourceConnectionMock = $this->createMock(ResourceConnection::class);

$this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);

$this->connectionMock = $this->createMock(MysqlPdoAdapter::class);

$this->connectionNewMock = $this->createMock(MysqlPdoAdapter::class);

$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->connectionFactory = $this->objectManagerHelper->getObject(
ConnectionFactory::class,
[
'resourceConnection' => $this->resourceConnectionMock,
'objectManager' => $this->objectManagerMock,
]
$this->resourceConfigMock = $this->createMock(ResourceConfigInterface::class);
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
$this->connectionFactoryMock = $this->createMock(ConnectionFactoryInterface::class);

$this->connectionFactory = new ConnectionFactory(
$this->resourceConfigMock,
$this->deploymentConfigMock,
$this->connectionFactoryMock
);
}

public function testGetConnection()
{
$connectionName = 'read';

$this->resourceConnectionMock
->expects($this->once())
->method('getConnection')
->with($connectionName)
->willReturn($this->connectionMock);

$this->connectionMock
->expects($this->once())
->method('getConfig')
->with()
->willReturn(['persistent' => 1]);

$this->objectManagerMock
->expects($this->once())
$resourceName = 'default';

$this->resourceConfigMock->expects($this->once())
->method('getConnectionName')
->with($resourceName)
->willReturn('default');
$this->deploymentConfigMock->expects($this->once())
->method('get')
->with('db/connection/default')
->willReturn(['host' => 'localhost', 'port' => 3306, 'persistent' => true]);
$connectionMock = $this->createMock(AdapterInterface::class);
$this->connectionFactoryMock->expects($this->once())
->method('create')
->with(get_class($this->connectionMock), ['config' => ['use_buffered_query' => false]])
->willReturn($this->connectionNewMock);
->with(['host' => 'localhost', 'port' => 3306, 'use_buffered_query' => false])
->willReturn($connectionMock);

$this->assertSame($this->connectionNewMock, $this->connectionFactory->getConnection($connectionName));
$connection = $this->connectionFactory->getConnection($resourceName);
$this->assertSame($connectionMock, $connection);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Analytics/etc/config.xml
Expand Up @@ -20,6 +20,7 @@
<integration_name>Magento Analytics user</integration_name>
<general>
<collection_time>02,00,00</collection_time>
<token/>
</general>
</analytics>
</default>
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Analytics/etc/di.xml
Expand Up @@ -266,4 +266,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Analytics\ReportXml\ConnectionFactory">
<arguments>
<argument name="connectionFactory" xsi:type="object">Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory</argument>
</arguments>
</type>
</config>
6 changes: 3 additions & 3 deletions app/code/Magento/Authorization/Model/CompositeUserContext.php
Expand Up @@ -56,15 +56,15 @@ protected function add(UserContextInterface $userContext)
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getUserId()
{
return $this->getUserContext() ? $this->getUserContext()->getUserId() : null;
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getUserType()
{
Expand All @@ -78,7 +78,7 @@ public function getUserType()
*/
protected function getUserContext()
{
if ($this->chosenUserContext === null) {
if (!$this->chosenUserContext) {
/** @var UserContextInterface $userContext */
foreach ($this->userContexts as $userContext) {
if ($userContext->getUserType() && $userContext->getUserId() !== null) {
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Authorization/Model/ResourceModel/Role.php
Expand Up @@ -119,6 +119,8 @@ protected function _afterDelete(\Magento\Framework\Model\AbstractModel $role)

$connection->delete($this->_ruleTable, ['role_id = ?' => (int)$role->getId()]);

$this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [\Magento\Backend\Block\Menu::CACHE_TAGS]);

return $this;
}

Expand Down

0 comments on commit fad49b8

Please sign in to comment.