Skip to content

Commit 375110d

Browse files
author
Vitaliy
authored
Merge pull request #248 from magento/133-plugin-type-test-coverage
Added test coverage for plugin type attribute, added checkstyle suppression mechanism
2 parents d6a6cca + 1fab70b commit 375110d

File tree

7 files changed

+89
-7
lines changed

7 files changed

+89
-7
lines changed

gradle-tasks/checkstyle/checkstyle.xml

Lines changed: 8 additions & 1 deletion
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>
326-
</module>
332+
<module name="SuppressWarningsFilter"/>
333+
</module>

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

Lines changed: 16 additions & 3 deletions
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;
11-
import com.magento.idea.magento2plugin.completion.provider.*;
12-
import com.magento.idea.magento2plugin.completion.provider.mftf.*;
13-
import com.magento.idea.magento2plugin.magento.files.*;
12+
// CHECKSTYLE IGNORE check FOR NEXT 6 LINES
13+
import com.magento.idea.magento2plugin.completion.provider.*;//NOPMD
14+
import com.magento.idea.magento2plugin.completion.provider.mftf.*;//NOPMD
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

Lines changed: 9 additions & 3 deletions
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;
14-
import com.magento.idea.magento2plugin.reference.provider.*;
15-
import com.magento.idea.magento2plugin.reference.provider.mftf.*;
15+
// CHECKSTYLE IGNORE check FOR NEXT 5 LINES
16+
import com.magento.idea.magento2plugin.reference.provider.*;//NOPMD
17+
import com.magento.idea.magento2plugin.reference.provider.mftf.*;//NOPMD
1618
import com.magento.idea.magento2plugin.util.RegExUtil;
1719
import org.jetbrains.annotations.NotNull;
18-
import static com.intellij.patterns.XmlPatterns.*;
20+
import static com.intellij.patterns.XmlPatterns.*;//NOPMD
1921

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

2228
@Override
Lines changed: 6 additions & 0 deletions
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>
Lines changed: 6 additions & 0 deletions
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>
Lines changed: 22 additions & 0 deletions
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+
}
Lines changed: 22 additions & 0 deletions
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)