|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | +package com.magento.idea.magento2plugin.completion.xml; |
| 6 | + |
| 7 | +import com.intellij.openapi.vfs.VirtualFile; |
| 8 | +import com.magento.idea.magento2plugin.magento.files.ModuleConfigXml; |
| 9 | +import com.magento.idea.magento2plugin.magento.files.ModuleSystemXml; |
| 10 | +import java.io.File; |
| 11 | + |
| 12 | +public class BackendModelXmlCompletionRegistrarTest extends CompletionLightJavaCodeInsightFixtureTestCase { |
| 13 | + |
| 14 | + private static VirtualFile systemXmlVirtualFile; |
| 15 | + private static VirtualFile configXmlVirtualFile; |
| 16 | + private static final String testDataFolderPath; |
| 17 | + private static final String fixturesFolderPath; |
| 18 | + private static final String classesSourceFile; |
| 19 | + private static final String[] systemXmlBackendModelLookupStringCheck; |
| 20 | + private static final String[] configXmlBackendModelLookupStringCheck; |
| 21 | + |
| 22 | + static { |
| 23 | + testDataFolderPath = "testData/completion/common/"; |
| 24 | + fixturesFolderPath = "xml/BackendModelXmlCompletionRegistrar"; |
| 25 | + classesSourceFile = "classes.php"; |
| 26 | + systemXmlBackendModelLookupStringCheck = new String[]{ |
| 27 | + "Magento\\Backend\\Model\\Source\\Roles" |
| 28 | + }; |
| 29 | + configXmlBackendModelLookupStringCheck = new String[]{ |
| 30 | + "Magento\\Config\\Model\\Config\\Source\\Yesno" |
| 31 | + }; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected void setUp() throws Exception { |
| 36 | + super.setUp(); |
| 37 | + myFixture.copyFileToProject(classesSourceFile); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected String getTestDataPath() { |
| 42 | + return testDataFolderPath; |
| 43 | + } |
| 44 | + |
| 45 | + protected String getFixturePath(String folderName, String fileName) { |
| 46 | + return fixturesFolderPath + File.separator + folderName + File.separator + fileName; |
| 47 | + } |
| 48 | + |
| 49 | + public void testSystemXmlBackendModelElementProvideCompletion() { |
| 50 | + String filePath = this.getFixturePath("systemXmlElementProvideCompletion", ModuleSystemXml.FILE_NAME); |
| 51 | + systemXmlVirtualFile = myFixture.copyFileToProject(filePath); |
| 52 | + |
| 53 | + assertCompletionContains(filePath, systemXmlBackendModelLookupStringCheck); |
| 54 | + } |
| 55 | + |
| 56 | + public void testSystemXmlBackendModelElementCompletionWontShow() { |
| 57 | + String filePath = this.getFixturePath( |
| 58 | + "systemXmlElementCompletionWontShow", |
| 59 | + ModuleSystemXml.FILE_NAME |
| 60 | + ); |
| 61 | + systemXmlVirtualFile = myFixture.copyFileToProject(filePath); |
| 62 | + |
| 63 | + assertCompletionNotShowing(filePath); |
| 64 | + } |
| 65 | + |
| 66 | + public void testSystemXmlBackendModelAttributeMatchWithFile() { |
| 67 | + String filePath = this.getFixturePath( |
| 68 | + "systemXmlBackendModelAttributeMatchWithFile", |
| 69 | + ModuleSystemXml.FILE_NAME |
| 70 | + ); |
| 71 | + |
| 72 | + assertCompletionMatchWithFilePositiveCase(filePath, systemXmlBackendModelLookupStringCheck); |
| 73 | + } |
| 74 | + |
| 75 | + public void testSystemXmlBackendModelAttributeDontMatchWithFile() { |
| 76 | + String filePath = this.getFixturePath( |
| 77 | + "systemXmlBackendModelAttributeDontMatchWithFile", |
| 78 | + "other-file-than-system.xml" |
| 79 | + ); |
| 80 | + |
| 81 | + assertCompletionMatchWithFileNegativeCase( |
| 82 | + filePath, |
| 83 | + systemXmlBackendModelLookupStringCheck |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + public void testConfigXmlBackendModelElementProvideCompletion() { |
| 88 | + String filePath = this.getFixturePath( |
| 89 | + "configXmlElementProvideCompletion", |
| 90 | + ModuleConfigXml.FILE_NAME |
| 91 | + ); |
| 92 | + configXmlVirtualFile = myFixture.copyFileToProject(filePath); |
| 93 | + |
| 94 | + assertCompletionContains(filePath, configXmlBackendModelLookupStringCheck); |
| 95 | + } |
| 96 | + |
| 97 | + public void testConfigXmlBackendModelElementCompletionWontShow() { |
| 98 | + String filePath = this.getFixturePath( |
| 99 | + "configXmlElementCompletionWontShow", |
| 100 | + ModuleConfigXml.FILE_NAME |
| 101 | + ); |
| 102 | + configXmlVirtualFile = myFixture.copyFileToProject(filePath); |
| 103 | + |
| 104 | + assertCompletionNotShowing(filePath); |
| 105 | + } |
| 106 | + |
| 107 | + public void testConfigXmlBackendModelAttributeMatchWithFile() { |
| 108 | + String filePath = this.getFixturePath( |
| 109 | + "configXmlBackendModelAttributeMatchWithFile", |
| 110 | + ModuleConfigXml.FILE_NAME |
| 111 | + ); |
| 112 | + |
| 113 | + assertCompletionMatchWithFilePositiveCase(filePath, configXmlBackendModelLookupStringCheck); |
| 114 | + } |
| 115 | + |
| 116 | + public void testConfigXmlBackendModelAttributeDontMatchWithFile() { |
| 117 | + String filePath = this.getFixturePath( |
| 118 | + "configXmlBackendModelAttributeDontMatchWithFile", |
| 119 | + "other-file-than-config.xml" |
| 120 | + ); |
| 121 | + |
| 122 | + assertCompletionMatchWithFileNegativeCase( |
| 123 | + filePath, |
| 124 | + configXmlBackendModelLookupStringCheck |
| 125 | + ); |
| 126 | + } |
| 127 | +} |
0 commit comments