Skip to content

Commit 8653503

Browse files
authored
Merge pull request #6236 from magento-tango/PR-10-14
[tango] Bugfix delivery
2 parents 3bcbd95 + 4b8e59d commit 8653503

File tree

55 files changed

+1920
-321
lines changed

Some content is hidden

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

55 files changed

+1920
-321
lines changed

app/code/Magento/Analytics/Model/ReportWriter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ public function write(WriteInterface $directory, $path)
103103
/**
104104
* Replace wrong symbols in row
105105
*
106+
* Strip backslashes before double quotes so they will be properly escaped in the generated csv
107+
*
108+
* @see fputcsv()
106109
* @param array $row
107110
* @return array
108111
*/
109112
private function prepareRow(array $row): array
110113
{
111-
$row = preg_replace('/(?<!\\\\)"/', '\\"', $row);
112-
$row = preg_replace('/[\\\\]+/', '\\', $row);
113-
114-
return $row;
114+
return preg_replace('/\\\+(?=\")/', '', $row);
115115
}
116116
}

app/code/Magento/Analytics/ReportXml/ConnectionFactory.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,65 @@
66

77
namespace Magento\Analytics\ReportXml;
88

9-
use Magento\Framework\App\ResourceConnection;
10-
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\ResourceConnection\ConfigInterface as ResourceConfigInterface;
11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1112
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactoryInterface;
1214

1315
/**
1416
* Creates connection instance for export according to existing one
17+
*
1518
* This connection does not use buffered statement, also this connection is not persistent
1619
*/
1720
class ConnectionFactory
1821
{
1922
/**
20-
* @var ResourceConnection
23+
* @var ResourceConfigInterface
2124
*/
22-
private $resourceConnection;
25+
private $resourceConfig;
2326

2427
/**
25-
* @var ObjectManagerInterface
28+
* @var DeploymentConfig
2629
*/
27-
private $objectManager;
30+
private $deploymentConfig;
2831

2932
/**
30-
* @param ResourceConnection $resourceConnection
31-
* @param ObjectManagerInterface $objectManager
33+
* @var ConnectionFactoryInterface
34+
*/
35+
private $connectionFactory;
36+
37+
/**
38+
* @param ResourceConfigInterface $resourceConfig
39+
* @param DeploymentConfig $deploymentConfig
40+
* @param ConnectionFactoryInterface $connectionFactory
3241
*/
3342
public function __construct(
34-
ResourceConnection $resourceConnection,
35-
ObjectManagerInterface $objectManager
43+
ResourceConfigInterface $resourceConfig,
44+
DeploymentConfig $deploymentConfig,
45+
ConnectionFactoryInterface $connectionFactory
3646
) {
37-
$this->resourceConnection = $resourceConnection;
38-
$this->objectManager = $objectManager;
47+
$this->resourceConfig = $resourceConfig;
48+
$this->deploymentConfig = $deploymentConfig;
49+
$this->connectionFactory = $connectionFactory;
3950
}
4051

4152
/**
4253
* Creates one-time connection for export
4354
*
44-
* @param string $connectionName
55+
* @param string $resourceName
4556
* @return AdapterInterface
4657
*/
47-
public function getConnection($connectionName)
58+
public function getConnection($resourceName)
4859
{
49-
$connection = $this->resourceConnection->getConnection($connectionName);
50-
$connectionClassName = get_class($connection);
51-
$configData = $connection->getConfig();
60+
$connectionName = $this->resourceConfig->getConnectionName($resourceName);
61+
$configData = $this->deploymentConfig->get(
62+
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/' . $connectionName
63+
);
5264
$configData['use_buffered_query'] = false;
5365
unset($configData['persistent']);
54-
return $this->objectManager->create(
55-
$connectionClassName,
56-
[
57-
'config' => $configData
58-
]
59-
);
66+
$connection = $this->connectionFactory->create($configData);
67+
68+
return $connection;
6069
}
6170
}

app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function setUp(): void
103103
* @param array $expectedFileData
104104
* @return void
105105
*
106-
* @dataProvider configDataProvider
106+
* @dataProvider writeDataProvider
107107
*/
108108
public function testWrite(array $configData, array $fileData, array $expectedFileData): void
109109
{
@@ -162,7 +162,7 @@ public function testWrite(array $configData, array $fileData, array $expectedFil
162162
* @param array $configData
163163
* @return void
164164
*
165-
* @dataProvider configDataProvider
165+
* @dataProvider writeErrorFileDataProvider
166166
*/
167167
public function testWriteErrorFile(array $configData): void
168168
{
@@ -195,10 +195,75 @@ public function testWriteEmptyReports(): void
195195
/**
196196
* @return array
197197
*/
198-
public function configDataProvider(): array
198+
public function writeDataProvider(): array
199+
{
200+
$configData = [
201+
'providers' => [
202+
[
203+
'name' => $this->providerName,
204+
'class' => $this->providerClass,
205+
'parameters' => [
206+
'name' => $this->reportName
207+
],
208+
]
209+
]
210+
];
211+
return [
212+
[
213+
'configData' => $configData,
214+
'fileData' => [
215+
['number' => 1, 'type' => 'Shoes\"" Usual\\\\"']
216+
],
217+
'expectedFileData' => [
218+
['number' => 1, 'type' => 'Shoes"" Usual"']
219+
]
220+
],
221+
[
222+
'configData' => $configData,
223+
'fileData' => [
224+
['number' => 1, 'type' => 'hello "World"']
225+
],
226+
'expectedFileData' => [
227+
['number' => 1, 'type' => 'hello "World"']
228+
]
229+
],
230+
[
231+
'configData' => $configData,
232+
'fileData' => [
233+
['number' => 1, 'type' => 'hello \"World\"']
234+
],
235+
'expectedFileData' => [
236+
['number' => 1, 'type' => 'hello "World"']
237+
]
238+
],
239+
[
240+
'configData' => $configData,
241+
'fileData' => [
242+
['number' => 1, 'type' => 'hello \\"World\\"']
243+
],
244+
'expectedFileData' => [
245+
['number' => 1, 'type' => 'hello "World"']
246+
]
247+
],
248+
[
249+
'configData' => $configData,
250+
'fileData' => [
251+
['number' => 1, 'type' => 'hello \\\"World\\\"']
252+
],
253+
'expectedFileData' => [
254+
['number' => 1, 'type' => 'hello "World"']
255+
]
256+
],
257+
];
258+
}
259+
260+
/**
261+
* @return array
262+
*/
263+
public function writeErrorFileDataProvider(): array
199264
{
200265
return [
201-
'reportProvider' => [
266+
[
202267
'configData' => [
203268
'providers' => [
204269
[
@@ -210,12 +275,6 @@ public function configDataProvider(): array
210275
]
211276
]
212277
],
213-
'fileData' => [
214-
['number' => 1, 'type' => 'Shoes\"" Usual\\\\"']
215-
],
216-
'expectedFileData' => [
217-
['number' => 1, 'type' => 'Shoes\"\" Usual\\"']
218-
]
219278
],
220279
];
221280
}

app/code/Magento/Analytics/Test/Unit/ReportXml/ConnectionFactoryTest.php

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,29 @@
88
namespace Magento\Analytics\Test\Unit\ReportXml;
99

1010
use Magento\Analytics\ReportXml\ConnectionFactory;
11-
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\App\DeploymentConfig;
12+
use Magento\Framework\App\ResourceConnection\ConfigInterface as ResourceConfigInterface;
1213
use Magento\Framework\DB\Adapter\AdapterInterface;
13-
use Magento\Framework\DB\Adapter\Pdo\Mysql as MysqlPdoAdapter;
14-
use Magento\Framework\ObjectManagerInterface;
15-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactoryInterface;
1615
use PHPUnit\Framework\MockObject\MockObject;
1716
use PHPUnit\Framework\TestCase;
1817

1918
class ConnectionFactoryTest extends TestCase
2019
{
2120
/**
22-
* @var ResourceConnection|MockObject
21+
* @var ResourceConfigInterface|MockObject
2322
*/
24-
private $resourceConnectionMock;
23+
private $resourceConfigMock;
2524

2625
/**
27-
* @var ObjectManagerInterface|MockObject
26+
* @var DeploymentConfig|MockObject
2827
*/
29-
private $objectManagerMock;
28+
private $deploymentConfigMock;
3029

3130
/**
32-
* @var ConnectionFactory|MockObject
31+
* @var ConnectionFactoryInterface|MockObject
3332
*/
34-
private $connectionNewMock;
35-
36-
/**
37-
* @var AdapterInterface|MockObject
38-
*/
39-
private $connectionMock;
40-
41-
/**
42-
* @var ObjectManagerHelper
43-
*/
44-
private $objectManagerHelper;
33+
private $connectionFactoryMock;
4534

4635
/**
4736
* @var ConnectionFactory
@@ -53,47 +42,36 @@ class ConnectionFactoryTest extends TestCase
5342
*/
5443
protected function setUp(): void
5544
{
56-
$this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
57-
58-
$this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
59-
60-
$this->connectionMock = $this->createMock(MysqlPdoAdapter::class);
61-
62-
$this->connectionNewMock = $this->createMock(MysqlPdoAdapter::class);
63-
64-
$this->objectManagerHelper = new ObjectManagerHelper($this);
65-
66-
$this->connectionFactory = $this->objectManagerHelper->getObject(
67-
ConnectionFactory::class,
68-
[
69-
'resourceConnection' => $this->resourceConnectionMock,
70-
'objectManager' => $this->objectManagerMock,
71-
]
45+
$this->resourceConfigMock = $this->createMock(ResourceConfigInterface::class);
46+
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
47+
$this->connectionFactoryMock = $this->createMock(ConnectionFactoryInterface::class);
48+
49+
$this->connectionFactory = new ConnectionFactory(
50+
$this->resourceConfigMock,
51+
$this->deploymentConfigMock,
52+
$this->connectionFactoryMock
7253
);
7354
}
7455

7556
public function testGetConnection()
7657
{
77-
$connectionName = 'read';
78-
79-
$this->resourceConnectionMock
80-
->expects($this->once())
81-
->method('getConnection')
82-
->with($connectionName)
83-
->willReturn($this->connectionMock);
84-
85-
$this->connectionMock
86-
->expects($this->once())
87-
->method('getConfig')
88-
->with()
89-
->willReturn(['persistent' => 1]);
90-
91-
$this->objectManagerMock
92-
->expects($this->once())
58+
$resourceName = 'default';
59+
60+
$this->resourceConfigMock->expects($this->once())
61+
->method('getConnectionName')
62+
->with($resourceName)
63+
->willReturn('default');
64+
$this->deploymentConfigMock->expects($this->once())
65+
->method('get')
66+
->with('db/connection/default')
67+
->willReturn(['host' => 'localhost', 'port' => 3306, 'persistent' => true]);
68+
$connectionMock = $this->createMock(AdapterInterface::class);
69+
$this->connectionFactoryMock->expects($this->once())
9370
->method('create')
94-
->with(get_class($this->connectionMock), ['config' => ['use_buffered_query' => false]])
95-
->willReturn($this->connectionNewMock);
71+
->with(['host' => 'localhost', 'port' => 3306, 'use_buffered_query' => false])
72+
->willReturn($connectionMock);
9673

97-
$this->assertSame($this->connectionNewMock, $this->connectionFactory->getConnection($connectionName));
74+
$connection = $this->connectionFactory->getConnection($resourceName);
75+
$this->assertSame($connectionMock, $connection);
9876
}
9977
}

app/code/Magento/Analytics/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<integration_name>Magento Analytics user</integration_name>
2121
<general>
2222
<collection_time>02,00,00</collection_time>
23+
<token/>
2324
</general>
2425
</analytics>
2526
</default>

app/code/Magento/Analytics/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,9 @@
266266
</argument>
267267
</arguments>
268268
</type>
269+
<type name="Magento\Analytics\ReportXml\ConnectionFactory">
270+
<arguments>
271+
<argument name="connectionFactory" xsi:type="object">Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactory</argument>
272+
</arguments>
273+
</type>
269274
</config>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminReloadDashboardDataActionGroup">
12+
<annotations>
13+
<description>Go to Admin Dashboard Page, and reload Dashboard data.</description>
14+
</annotations>
15+
16+
<amOnPage url="{{AdminDashboardPage.url}}" stepKey="amOnDashboardPage"/>
17+
<click selector="{{AdminDashboardSection.dashboardButtonReloadData}}" stepKey="reloadDashboardData"/>
18+
<waitForPageLoad stepKey="waitForPageToReload"/>
19+
</actionGroup>
20+
</actionGroups>

app/code/Magento/Backend/Test/Mftf/Section/AdminDashboardSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<element name="dashboardDiagramAmountsContentTab" type="block" selector="#diagram_tab_amounts_content"/>
1818
<element name="dashboardDiagramTotals" type="text" selector="#diagram_tab_amounts_content"/>
1919
<element name="dashboardTotals" type="text" selector="//*[@class='dashboard-totals-label' and contains(text(), '{{columnName}}')]/../*[@class='dashboard-totals-value']" parameterized="true"/>
20+
<element name="productInBestsellers" type="text" selector="#productsOrderedGrid_table td.col-product.col-name"/>
21+
<element name="dashboardButtonReloadData" type="button" selector=".action-primary[title='Reload Data'][type='submit']"/>
2022
</section>
2123
</sections>

app/code/Magento/Backend/Test/Mftf/Test/AdminLoginWithRestrictPermissionTest.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutAsSaleRoleUser"/>
4343
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
4444
<!--Delete created data-->
45-
<actionGroup ref="AdminUserOpenAdminRolesPageActionGroup" stepKey="navigateToUserRoleGrid"/>
46-
<actionGroup ref="AdminDeleteRoleActionGroup" stepKey="deleteUserRole">
47-
<argument name="role" value="adminRole"/>
45+
<actionGroup ref="AdminDeleteUserRoleActionGroup" stepKey="deleteUserRole">
46+
<argument name="roleName" value="{{adminRole.rolename}}"/>
4847
</actionGroup>
4948
<actionGroup ref="AdminOpenAdminUsersPageActionGroup" stepKey="goToAllUsersPage"/>
5049
<actionGroup ref="AdminDeleteNewUserActionGroup" stepKey="deleteUser">

0 commit comments

Comments
 (0)