Skip to content

Commit 0bb353e

Browse files
committed
MC-14937: Complete Page Builder Analytics data collection
- fix array format of returned data and update tests
1 parent 62d6fd3 commit 0bb353e

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

app/code/Magento/PageBuilderAnalytics/Model/ContentTypeUsageReportProvider.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ContentTypeUsageReportProvider
5050
*
5151
* @param Config $config
5252
* @param QueryFactory $queryFactory
53+
* @param IteratorFactory $iteratorFactory
5354
* @param ConnectionFactory $connectionFactory
5455
* @param int $batchSize
5556
*/
@@ -109,12 +110,16 @@ public function getReport($name) : \IteratorIterator
109110
}
110111
}
111112

112-
$reportData[] = ['Content Type', 'Count'];
113113
foreach ($contentTypes as $type) {
114-
$reportData[] = [$type['name'], $typeCounts[$type['name']]];
114+
$reportData[] = [
115+
'type' => $type['name'],
116+
'count' => $typeCounts[$type['name']]
117+
];
115118
}
116119

117-
return $this->iteratorFactory->create($reportData);
120+
return $this->iteratorFactory->create(
121+
new \ArrayIterator($reportData)
122+
);
118123
}
119124

120125
/**

dev/tests/integration/testsuite/Magento/CmsPageBuilderAnalytics/Model/ContentTypeUsageReportProviderTest.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function testGetReport($expectedReportData, $ignoredContentTypes)
3030
$connectionFactoryMock->expects($this->once())
3131
->method('getConnection')
3232
->willReturn($resourceConnection);
33+
// $iteratorFactoryMock = $this->createMock(\Magento\Analytics\ReportXml\IteratorFactory::class);
34+
// $iteratorFactoryMock->expects($this->once())
35+
// ->method('create');
3336
/* @var $contentTypeUsageReportProvider \Magento\PageBuilderAnalytics\Model\ContentTypeUsageReportProvider */
3437
$contentTypeUsageReportProvider = Bootstrap::getObjectManager()->create(
3538
\Magento\PageBuilderAnalytics\Model\ContentTypeUsageReportProvider::class,
@@ -46,23 +49,18 @@ public function testGetReport($expectedReportData, $ignoredContentTypes)
4649
}
4750

4851
foreach ($reportData->getInnerIterator() as $reportItem) {
49-
// Ignore the header within the report
50-
if ($reportItem[0] === 'Content Type') {
51-
continue;
52-
}
53-
5452
// Skip over any ignored content types
55-
if (in_array($reportItem[0], $ignoredContentTypes)) {
53+
if (in_array($reportItem['type'], $ignoredContentTypes)) {
5654
continue;
5755
}
5856

5957
// Verify we have expected report data for the content type
6058
if (!isset($expectedReportData[$reportItem[0]])) {
61-
$this->fail('There is no report data for ' . $reportItem[0] . '.');
59+
$this->fail('There is no report data for ' . $reportItem['type'] . '.');
6260
}
6361

6462
// Verify the count values match the expected report data
65-
$this->assertEquals($expectedReportData[$reportItem[0]], $reportItem[1]);
63+
$this->assertEquals($expectedReportData[$reportItem['type']], $reportItem['count']);
6664
}
6765
}
6866

@@ -74,25 +72,25 @@ public function reportDataProvider(): array
7472
return [
7573
[
7674
[
77-
'button-item' => 6,
78-
'slide' => 12,
79-
'text' => 1,
80-
'image' => 2,
81-
'block' => 1,
82-
'row' => 7,
83-
'column-group' => 5,
84-
'column' => 12,
85-
'video' => 2,
86-
'heading' => 3,
87-
'tabs' => 1,
88-
'products' => 0,
89-
'tab-item' => 2,
90-
'banner' => 4,
91-
'buttons' => 2,
92-
'slider' => 3,
93-
'divider' => 5,
94-
'map' => 2,
95-
'html' => 2
75+
['type' => 'button-item', 'count' => 6],
76+
['type' => 'slide', 'count' => 12],
77+
['type' => 'text', 'count' => 1],
78+
['type' => 'image', 'count' => 2],
79+
['type' => 'block', 'count' => 1],
80+
['type' => 'row', 'count' => 7],
81+
['type' => 'column-group', 'count' => 5],
82+
['type' => 'column', 'count' => 12],
83+
['type' => 'video', 'count' => 2],
84+
['type' => 'heading', 'count' => 3],
85+
['type' => 'tabs', 'count' => 1],
86+
['type' => 'products', 'count' => 0],
87+
['type' => 'tab-item', 'count' => 2],
88+
['type' => 'banner', 'count' => 4],
89+
['type' => 'buttons', 'count' => 2],
90+
['type' => 'slider', 'count' => 3],
91+
['type' => 'divider', 'count' => 5],
92+
['type' => 'map', 'count' => 2],
93+
['type' => 'html', 'count' => 2]
9694
],
9795
// Ignored content types
9896
[

0 commit comments

Comments
 (0)