Skip to content

Commit 12d2e68

Browse files
committed
MC-14937: Complete Page Builder Analytics data collection
- Add test coverage for usage report provider
1 parent 797b9d6 commit 12d2e68

File tree

5 files changed

+578
-0
lines changed

5 files changed

+578
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModulePageBuilderAnalytics" active="true" />
10+
</config>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Analytics:etc/reports.xsd">
9+
<report name="pagebuilder_page_test" connection="default">
10+
<source name="cms_page">
11+
<attribute name="content"/>
12+
<link-source name="cms_page_store" link-type="inner">
13+
<using glue="and">
14+
<condition attribute="row_id" operator="eq" type="identifier">row_id</condition>
15+
<condition attribute="store_id" operator="in">0,1</condition>
16+
</using>
17+
</link-source>
18+
<filter glue="and">
19+
<condition attribute="created_in" operator="eq">1</condition>
20+
<condition attribute="identifier" operator="eq">page-builder-analytics-test-page</condition>
21+
</filter>
22+
</source>
23+
</report>
24+
</config>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Component\ComponentRegistrar;
9+
10+
$registrar = new ComponentRegistrar();
11+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModulePageBuilderAnalytics') === null) {
12+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModulePageBuilderAnalytics', __DIR__);
13+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\PageBuilderAnalytics\Model;
10+
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\Framework\App\ResourceConnection;
13+
14+
/**
15+
* @magentoAppArea adminhtml
16+
*/
17+
class ContentTypeUsageReportProviderTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @magentoAppIsolation enabled
21+
* @magentoDataFixture Magento/PageBuilderAnalytics/_files/pages.php
22+
* @dataProvider reportDataProvider
23+
*/
24+
public function testGetReport($expectedReportData)
25+
{
26+
/* @var $resourceConnection ResourceConnection */
27+
$resourceConnection = Bootstrap::getObjectManager()->get(ResourceConnection::class)
28+
->getConnection(ResourceConnection::DEFAULT_CONNECTION);
29+
$connectionFactoryMock = $this->createMock(\Magento\Analytics\ReportXml\ConnectionFactory::class);
30+
$connectionFactoryMock->expects($this->once())
31+
->method('getConnection')
32+
->willReturn($resourceConnection);
33+
/* @var $contentTypeUsageReportProvider \Magento\PageBuilderAnalytics\Model\ContentTypeUsageReportProvider */
34+
$contentTypeUsageReportProvider = Bootstrap::getObjectManager()->create(
35+
\Magento\PageBuilderAnalytics\Model\ContentTypeUsageReportProvider::class,
36+
[
37+
'connectionFactory' => $connectionFactoryMock
38+
]
39+
);
40+
$reportData = $contentTypeUsageReportProvider->getReport('pagebuilder_page_test');
41+
42+
$this->assertEquals($expectedReportData, iterator_to_array($reportData->getInnerIterator()));
43+
}
44+
45+
/**
46+
* @return array
47+
*/
48+
public function reportDataProvider(): array
49+
{
50+
return [
51+
[
52+
[
53+
[
54+
'Content Type',
55+
'Count'
56+
],
57+
[
58+
'button-item',
59+
6
60+
],
61+
[
62+
'slide',
63+
12
64+
],
65+
[
66+
'text',
67+
1
68+
],
69+
[
70+
'image',
71+
2
72+
],
73+
[
74+
'block',
75+
1
76+
],
77+
[
78+
'row',
79+
7
80+
],
81+
[
82+
'dynamic_block',
83+
0
84+
],
85+
[
86+
'column-group',
87+
5
88+
],
89+
[
90+
'column',
91+
12
92+
],
93+
[
94+
'video',
95+
2
96+
],
97+
[
98+
'heading',
99+
3
100+
],
101+
[
102+
'tabs',
103+
1
104+
],
105+
[
106+
'products',
107+
0
108+
],
109+
[
110+
'tab-item',
111+
2
112+
],
113+
[
114+
'banner',
115+
4
116+
],
117+
[
118+
'buttons',
119+
2
120+
],
121+
[
122+
'slider',
123+
3
124+
],
125+
[
126+
'divider',
127+
5
128+
],
129+
[
130+
'map',
131+
2
132+
],
133+
[
134+
'html',
135+
2
136+
]
137+
]
138+
]
139+
];
140+
}
141+
}

0 commit comments

Comments
 (0)