File tree Expand file tree Collapse file tree 7 files changed +127
-0
lines changed
completion/xml/ModuleNameCompletionRegistrar
moduleNameMustHaveCompletion
sequenceModuleNameMustHaveCompletion
reference/xml/ModuleNameReferenceRegistrar
moduleNameMustHaveReference
sequenceModuleNameMustHaveReference
tests/com/magento/idea/magento2plugin Expand file tree Collapse file tree 7 files changed +127
-0
lines changed Original file line number Diff line number Diff line change
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"
9
+ xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
10
+ <module name =" Magento_C<caret>" />
11
+ </config >
Original file line number Diff line number Diff line change
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"
9
+ xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
10
+ <module name =" Magento_Theme" >
11
+ <sequence >
12
+ <module name =" Magento_C<caret>" />
13
+ </sequence >
14
+ </module >
15
+ </config >
Original file line number Diff line number Diff line change
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"
9
+ xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
10
+ <module name =" Magento_Catalog<caret>" />
11
+ </config >
Original file line number Diff line number Diff line change
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"
9
+ xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
10
+ <module name =" Magento_Catalog" >
11
+ <sequence >
12
+ <module name =" Magento_Config<caret>" />
13
+ </sequence >
14
+ </module >
15
+ </config >
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+
6
+ package com .magento .idea .magento2plugin .completion .xml ;
7
+
8
+ public class ModuleNameCompletionRegistrarTest extends CompletionXmlFixtureTestCase {
9
+ private static final String [] LOOKUP_MODULE_NAMES = {
10
+ "Magento_Catalog" ,
11
+ "Magento_Config"
12
+ };
13
+
14
+ /**
15
+ * Tests for module name completion in module.xml
16
+ */
17
+ public void testModuleNameMustHaveCompletion () {
18
+ final String filePath = this .getFixturePath ("module.xml" );
19
+ myFixture .copyFileToProject (filePath );
20
+
21
+ assertFileContainsCompletions (filePath , LOOKUP_MODULE_NAMES );
22
+ }
23
+
24
+ /**
25
+ * Tests for module name completion under the sequence node in module.xml
26
+ */
27
+ public void testSequenceModuleNameMustHaveCompletion () {
28
+ final String filePath = this .getFixturePath ("module.xml" );
29
+ myFixture .copyFileToProject (filePath );
30
+
31
+ assertFileContainsCompletions (filePath , LOOKUP_MODULE_NAMES );
32
+ }
33
+ }
Original file line number Diff line number Diff line change 9
9
import com .intellij .psi .PsiFile ;
10
10
import com .intellij .psi .PsiReference ;
11
11
import com .intellij .psi .ResolveResult ;
12
+ import com .intellij .psi .impl .file .PsiDirectoryImpl ;
12
13
import com .intellij .psi .xml .XmlAttributeValue ;
13
14
import com .intellij .psi .xml .XmlFile ;
14
15
import com .intellij .psi .xml .XmlTag ;
@@ -113,6 +114,20 @@ protected void assertHasReferenceToXmlFile(final String fileName) {
113
114
fail (String .format (referenceNotFound , fileName ));
114
115
}
115
116
117
+ protected void assertHasReferenceToDirectory (final String directoryName ) {
118
+ for (final PsiReference psiReference : getElementFromCaret ().getReferences ()) {
119
+ final PsiElement resolvedElement = psiReference .resolve ();
120
+ if (resolvedElement instanceof PsiDirectoryImpl
121
+ && ((PsiDirectoryImpl ) resolvedElement ).getName ().equals (directoryName )) {
122
+ return ;
123
+ }
124
+ }
125
+
126
+ final String referenceNotFound
127
+ = "Failed that element contains reference to the directory `%s`" ;
128
+ fail (String .format (referenceNotFound , directoryName ));
129
+ }
130
+
116
131
@ SuppressWarnings ("PMD" )
117
132
protected void assertHasReferencePhpClass (final String phpClassFqn ) {
118
133
final PsiElement element = getElementFromCaret ();
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+
6
+ package com .magento .idea .magento2plugin .reference .xml ;
7
+
8
+ public class ModuleNameReferenceRegistrarTest extends ReferenceXmlFixtureTestCase {
9
+
10
+ /**
11
+ * Tests for module name reference in module.xml
12
+ */
13
+ public void testModuleNameMustHaveReference () {
14
+ myFixture .configureByFile (this .getFixturePath ("module.xml" ));
15
+
16
+ assertHasReferenceToDirectory ("module-catalog" );
17
+ }
18
+
19
+ /**
20
+ * Tests for module name reference under sequence node in module.xml
21
+ */
22
+ public void testSequenceModuleNameMustHaveReference () {
23
+ myFixture .configureByFile (this .getFixturePath ("module.xml" ));
24
+
25
+ assertHasReferenceToDirectory ("module-config" );
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments