Skip to content

Commit dbd36e1

Browse files
authored
Merge pull request #367 from drpayyne/issue-131
Module name completion and reference tests
2 parents a61d897 + 4dc4a3c commit dbd36e1

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

tests/com/magento/idea/magento2plugin/reference/BaseReferenceTestCase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.psi.PsiFile;
1010
import com.intellij.psi.PsiReference;
1111
import com.intellij.psi.ResolveResult;
12+
import com.intellij.psi.impl.file.PsiDirectoryImpl;
1213
import com.intellij.psi.xml.XmlAttributeValue;
1314
import com.intellij.psi.xml.XmlFile;
1415
import com.intellij.psi.xml.XmlTag;
@@ -113,6 +114,20 @@ protected void assertHasReferenceToXmlFile(final String fileName) {
113114
fail(String.format(referenceNotFound, fileName));
114115
}
115116

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+
116131
@SuppressWarnings("PMD")
117132
protected void assertHasReferencePhpClass(final String phpClassFqn) {
118133
final PsiElement element = getElementFromCaret();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)