Skip to content

Commit de17ade

Browse files
committed
fix: missing file header
1 parent 86a71bf commit de17ade

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

src/generator/module/ModuleXmlGenerator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FileGenerator from '../FileGenerator';
66
import Magento from 'util/Magento';
77
import HandlebarsTemplateRenderer from 'generator/HandlebarsTemplateRenderer';
88
import { TemplatePath } from 'types/handlebars';
9+
import FileHeader from 'common/xml/FileHeader';
910

1011
export default class ModuleXmlGenerator extends FileGenerator {
1112
public constructor(protected data: ModuleWizardData | ModuleWizardComposerData) {
@@ -28,10 +29,12 @@ export default class ModuleXmlGenerator extends FileGenerator {
2829
protected async getXmlContent(): Promise<string> {
2930
const renderer = new HandlebarsTemplateRenderer();
3031
const moduleName = Magento.getModuleName(this.data.vendor, this.data.module);
32+
const fileHeader = FileHeader.getHeader(moduleName);
3133

3234
const moduleConfigXml = await renderer.render(TemplatePath.XmlModuleConfig, {
3335
moduleName,
3436
sequence: this.data.sequence,
37+
fileHeader,
3538
});
3639

3740
return moduleConfigXml;

src/test/generator/module/ModuleXmlGenerator.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ModuleXmlGenerator from 'generator/module/ModuleXmlGenerator';
66
import { describe, it, before, afterEach } from 'mocha';
77
import { setup } from 'test/setup';
88
import { getReferenceFile, getTestWorkspaceUri } from 'test/util';
9+
import FileHeader from 'common/xml/FileHeader';
910
import sinon from 'sinon';
1011

1112
describe('ModuleXmlGenerator Tests', () => {
@@ -82,4 +83,28 @@ describe('ModuleXmlGenerator Tests', () => {
8283
// Compare the generated content with reference
8384
assert.strictEqual(generatedFile.content, referenceContent);
8485
});
86+
87+
it('should generate module.xml with comment', async () => {
88+
sinon.stub(FileHeader, 'getHeader').returns('<!--\nFoo_Bar\n-->');
89+
90+
// Create test data with sequence
91+
const dataWithSequence: ModuleWizardData = {
92+
...moduleWizardData,
93+
};
94+
95+
// Create the generator with sequence data
96+
const generator = new ModuleXmlGenerator(dataWithSequence);
97+
98+
// Use a test workspace URI
99+
const workspaceUri = getTestWorkspaceUri();
100+
101+
// Generate the file
102+
const generatedFile = await generator.generate(workspaceUri);
103+
104+
// Get the reference file content
105+
const referenceContent = getReferenceFile('generator/module/module-with-comment.xml');
106+
107+
// Compare the generated content with reference
108+
assert.strictEqual(generatedFile.content, referenceContent);
109+
});
85110
});
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0"?>
22
{{> fileHeader}}
33
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
55
{{#if sequence}}
66
<module name="{{ moduleName }}">
77
<sequence>
88
{{#each sequence}}
9-
<module name="{{ this }}" />
9+
<module name="{{ this }}"/>
1010
{{/each}}
1111
</sequence>
1212
</module>
1313
{{else}}
14-
<module name="{{ moduleName }}" />
14+
<module name="{{ moduleName }}"/>
1515
{{/if}}
1616
</config>
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
3-
* Foo_Bar
4-
-->
5-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
Foo_Bar
4+
-->
5+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
67
<module name="Foo_Bar"/>
78
</config>

test-resources/reference/generator/module/module-with-sequence.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
34
<module name="Foo_Bar">
45
<sequence>
56
<module name="Magento_Catalog"/>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
34
<module name="Foo_Bar"/>
45
</config>

0 commit comments

Comments
 (0)