|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | +package com.magento.idea.magento2plugin.actions.generation.generator; |
| 6 | + |
| 7 | +import com.intellij.openapi.project.Project; |
| 8 | +import com.intellij.psi.PsiDirectory; |
| 9 | +import com.intellij.psi.PsiFile; |
| 10 | +import com.magento.idea.magento2plugin.actions.generation.data.ModuleComposerJsonData; |
| 11 | +import com.magento.idea.magento2plugin.magento.files.ComposerJson; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.Arrays; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +public class ModuleComposerJsonGeneratorTest extends BaseGeneratorTestCase { |
| 17 | + |
| 18 | + public void testGenerateModuleFile() { |
| 19 | + String filePath = this.getFixturePath(ComposerJson.FILE_NAME); |
| 20 | + PsiFile expectedFile = myFixture.configureByFile(filePath); |
| 21 | + PsiDirectory projectDir = getProjectDirectory(); |
| 22 | + |
| 23 | + Project project = myFixture.getProject(); |
| 24 | + List<String> dependencies = new ArrayList<>(Arrays.asList("Foo_Bar", "Magento_Backend")); |
| 25 | + List<String> licenses = new ArrayList<>(Arrays.asList("Test License 1", "Test License 2")); |
| 26 | + ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData( |
| 27 | + "Test", |
| 28 | + "Module", |
| 29 | + projectDir, |
| 30 | + "test-description", |
| 31 | + "test/module", |
| 32 | + "1.0.0-dev", |
| 33 | + licenses, |
| 34 | + dependencies, |
| 35 | + true |
| 36 | + ); |
| 37 | + ModuleComposerJsonGenerator composerJsonGenerator = new ModuleComposerJsonGenerator(composerJsonData, project); |
| 38 | + PsiFile composerJson = composerJsonGenerator.generate("test"); |
| 39 | + |
| 40 | + assertGeneratedFileIsCorrect( |
| 41 | + expectedFile, |
| 42 | + projectDir.getVirtualFile().getPath() + "/Test/Module", |
| 43 | + composerJson |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + public void testGenerateFileInRoot() { |
| 48 | + String filePath = this.getFixturePath(ComposerJson.FILE_NAME); |
| 49 | + PsiFile expectedFile = myFixture.configureByFile(filePath); |
| 50 | + PsiDirectory projectDir = getProjectDirectory(); |
| 51 | + |
| 52 | + Project project = myFixture.getProject(); |
| 53 | + List<String> dependencies = new ArrayList<>(Arrays.asList("Foo_Bar", "Magento_Backend")); |
| 54 | + List<String> licenses = new ArrayList<>(Arrays.asList("Test License 1", "Test License 2")); |
| 55 | + ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData( |
| 56 | + "Test", |
| 57 | + "Module", |
| 58 | + projectDir, |
| 59 | + "test-description", |
| 60 | + "test/module", |
| 61 | + "1.0.0-dev", |
| 62 | + licenses, |
| 63 | + dependencies, |
| 64 | + false |
| 65 | + ); |
| 66 | + ModuleComposerJsonGenerator composerJsonGenerator = new ModuleComposerJsonGenerator(composerJsonData, project); |
| 67 | + PsiFile composerJson = composerJsonGenerator.generate("test"); |
| 68 | + |
| 69 | + assertGeneratedFileIsCorrect( |
| 70 | + expectedFile, |
| 71 | + projectDir.getVirtualFile().getPath(), |
| 72 | + composerJson |
| 73 | + ); |
| 74 | + } |
| 75 | +} |
0 commit comments