Skip to content

Commit c568f88

Browse files
author
Vitaliy Boyko
committed
Added test coverage for plugin type attribute, added checkstyle suppression mechanism
1 parent d6a6cca commit c568f88

File tree

7 files changed

+83
-1
lines changed

7 files changed

+83
-1
lines changed

gradle-tasks/checkstyle/checkstyle.xml

+7
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,12 @@
322322
default="checkstyle-xpath-suppressions.xml" />
323323
<property name="optional" value="true"/>
324324
</module>
325+
<module name="SuppressWarningsHolder"/>
326+
<module name="SuppressWithNearbyCommentFilter">
327+
<property name="commentFormat" value="CHECKSTYLE IGNORE (\w+) FOR NEXT (\d+) LINES"/>
328+
<property name="checkFormat" value="$1"/>
329+
<property name="influenceFormat" value="$2"/>
330+
</module>
325331
</module>
332+
<module name="SuppressWarningsFilter"/>
326333
</module>

src/com/magento/idea/magento2plugin/completion/xml/XmlCompletionContributor.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.completion.xml;
67

78
import com.intellij.codeInsight.completion.CompletionContributor;
89
import com.intellij.codeInsight.completion.CompletionType;
910
import com.intellij.patterns.XmlPatterns;
1011
import com.intellij.psi.xml.XmlTokenType;
12+
// CHECKSTYLE IGNORE check FOR NEXT 6 LINES
1113
import com.magento.idea.magento2plugin.completion.provider.*;
1214
import com.magento.idea.magento2plugin.completion.provider.mftf.*;
13-
import com.magento.idea.magento2plugin.magento.files.*;
15+
import com.magento.idea.magento2plugin.magento.files.*;//NOPMD
1416
import static com.intellij.patterns.PlatformPatterns.psiElement;
1517
import static com.intellij.patterns.StandardPatterns.string;
1618
import static com.intellij.patterns.XmlPatterns.xmlFile;
1719

20+
/**
21+
* TODO: enable style checks after decomposition.
22+
*/
23+
@SuppressWarnings({"PMD", "checkstyle:all"})
1824
public class XmlCompletionContributor extends CompletionContributor {
1925

2026
public XmlCompletionContributor() {
@@ -70,6 +76,13 @@ public XmlCompletionContributor() {
7076
new PhpClassCompletionProvider()
7177
);
7278

79+
// <plugin type="completion">
80+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
81+
.inside(XmlPatterns.xmlAttribute().withName(ModuleDiXml.PLUGIN_TYPE_ATTRIBUTE)
82+
.withParent(XmlPatterns.xmlTag().withName(ModuleDiXml.PLUGIN_TAG_NAME))),
83+
new PhpClassCompletionProvider()
84+
);
85+
7386
/* File Path Completion provider */
7487
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
7588
.inside(XmlPatterns.xmlAttribute().withName(LayoutXml.XML_ATTRIBUTE_TEMPLATE)),

src/com/magento/idea/magento2plugin/reference/xml/XmlReferenceContributor.java

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.reference.xml;
67

78
import com.intellij.patterns.XmlPatterns;
@@ -11,12 +12,17 @@
1112
import com.magento.idea.magento2plugin.magento.files.MftfActionGroup;
1213
import com.magento.idea.magento2plugin.magento.files.MftfTest;
1314
import com.magento.idea.magento2plugin.magento.files.UiComponentXml;
15+
// CHECKSTYLE IGNORE check FOR NEXT 5 LINES
1416
import com.magento.idea.magento2plugin.reference.provider.*;
1517
import com.magento.idea.magento2plugin.reference.provider.mftf.*;
1618
import com.magento.idea.magento2plugin.util.RegExUtil;
1719
import org.jetbrains.annotations.NotNull;
1820
import static com.intellij.patterns.XmlPatterns.*;
1921

22+
/**
23+
* TODO: enable style checks after decomposition.
24+
*/
25+
@SuppressWarnings({"PMD", "checkstyle:all"})
2026
public class XmlReferenceContributor extends PsiReferenceContributor {
2127

2228
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<type name="Magento\Framework\View\Layout">
4+
<plugin name="some" type="Yesn<caret>"/>
5+
</type>
6+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<type name="Magento\Framework\View\Layout">
4+
<plugin type="Magento\Backend\Model\Source\YesNo<caret>"/>
5+
</type>
6+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
9+
10+
public class PluginTypeCompletionRegistrarTest extends CompletionXmlFixtureTestCase {
11+
12+
/**
13+
* The `type` attribute of the `plugin` tag in di.xml must
14+
* have completion based on PHP classes index
15+
*/
16+
public void testPluginTypeMustHaveCompletion() {
17+
final String filePath = this.getFixturePath(ModuleDiXml.FILE_NAME);
18+
myFixture.configureByFile(filePath);
19+
20+
assertCompletionContains(filePath, "Magento\\Backend\\Model\\Source\\YesNo");
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
9+
10+
public class PluginTypeReferenceRegistrarTest extends ReferenceXmlFixtureTestCase {
11+
12+
/**
13+
* The `type` attribute of the `plugin` tag in di.xml must
14+
* have reference to the PHP class
15+
*/
16+
public void testPluginTypeMustHaveReference() {
17+
final String filePath = this.getFixturePath(ModuleDiXml.FILE_NAME);
18+
myFixture.configureByFile(filePath);
19+
20+
assertHasReferencePhpClass("Magento\\Backend\\Model\\Source\\YesNo");
21+
}
22+
}

0 commit comments

Comments
 (0)