Skip to content

Commit e726f1c

Browse files
committed
Add integration test
1 parent 0d1c108 commit e726f1c

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-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_TestModuleMview"/>
10+
</config>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mview/etc/mview.xsd">
9+
<view id="test_view_with_additional_columns" class="Magento\Framework\Indexer\Action\Dummy" group="indexer">
10+
<subscriptions>
11+
<table name="test_mview_table" entity_column="entity_id">
12+
<additionalColumns>
13+
<column name="additional_column" cl_name="test_additional_column" />
14+
</additionalColumns>
15+
</table>
16+
</subscriptions>
17+
</view>
18+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleMview') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleMview', __DIR__);
12+
}

dev/tests/integration/testsuite/Magento/Framework/Mview/View/ChangelogTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Framework\Mview\View;
77

88
use Magento\Framework\App\ResourceConnection;
9+
use Magento\Framework\Mview\View;
910

1011
/**
1112
* Test Class for \Magento\Framework\Mview\View\Changelog
@@ -123,6 +124,54 @@ public function testClear()
123124
$this->assertEquals(1, $this->model->getVersion()); //the same that a table is empty
124125
}
125126

127+
/**
128+
* Create entity table for MView
129+
*
130+
* @param string $tableName
131+
* @return void
132+
*/
133+
private function createEntityTable(string $tableName)
134+
{
135+
$table = $this->resource->getConnection()->newTable(
136+
$tableName
137+
)->addColumn(
138+
'entity_id',
139+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
140+
null,
141+
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
142+
'Version ID'
143+
)->addColumn(
144+
'additional_column',
145+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
146+
null,
147+
['unsigned' => true, 'nullable' => false, 'default' => '0'],
148+
'Entity ID'
149+
);
150+
$this->resource->getConnection()->createTable($table);
151+
}
152+
153+
public function testAdditionalColumns()
154+
{
155+
$tableName = 'test_mview_table';
156+
$this->createEntityTable($tableName);
157+
$view = $this->objectManager->create(View::class);
158+
$view->load('test_view_with_additional_columns');
159+
$view->subscribe();
160+
$this->connection->insert($tableName, ['entity_id' => 12, 'additional_column' => 13]);
161+
$select = $this->connection->select()
162+
->from($view->getChangelog()->getName(), ['entity_id', 'test_additional_column']);
163+
$actual = $this->connection->fetchAll($select);
164+
$this->assertEquals(
165+
[
166+
'entity_id' => "12",
167+
'test_additional_column' => "13"
168+
],
169+
reset($actual)
170+
);
171+
$this->connection->dropTable($tableName);
172+
$this->connection->dropTable($view->getChangelog()->getName());
173+
}
174+
126175
/**
127176
* Test for getList() method
128177
*

0 commit comments

Comments
 (0)