Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] [Tests] Test coverage for PHP class completion for backend model; bugfix for #126 #127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,19 @@ public XmlCompletionContributor() {
new PhpClassCompletionProvider()
);

// <backend_model>completion</backend_model>
extend(CompletionType.BASIC,
psiElement(XmlTokenType.XML_DATA_CHARACTERS)
.inside(XmlPatterns.xmlTag().withName(ModuleSystemXml.XML_TAG_BACKEND_MODEL)),
new PhpClassCompletionProvider()
// <backend_model>completion</backend_model> in system.xml
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
.inside(XmlPatterns.xmlTag().withName(ModuleSystemXml.XML_TAG_BACKEND_MODEL)
.withParent(XmlPatterns.xmlTag().withName(ModuleSystemXml.FIELD_ELEMENT_NAME))
).inFile(xmlFile().withName(string().matches(ModuleSystemXml.FILE_NAME))),
new PhpClassCompletionProvider()
);

// <randomTag backend_model="completion">
// <randomTag backend_model="completion"> in config.xml
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
.inside(XmlPatterns.xmlAttribute().withName(ModuleConfigXml.XML_ATTRIBUTE_BACKEND_MODEL)),
new PhpClassCompletionProvider()
.inside(XmlPatterns.xmlAttribute().withName(ModuleConfigXml.XML_ATTRIBUTE_BACKEND_MODEL))
.inFile(xmlFile().withName(string().matches(ModuleConfigXml.FILE_NAME))),
new PhpClassCompletionProvider()
);

// <parameter source_model="completion">...</parameter> in widget.xml files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
package com.magento.idea.magento2plugin.magento.files;

public class ModuleConfigXml {
public static final String FILE_NAME = "config.xml";
public static final String XML_ATTRIBUTE_BACKEND_MODEL = "backend_model";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<test>
<test backend_model="Yesno<caret>" />
</test>
</payment>
</default>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<test>
<test backend_model="Yesno<caret>" />
</test>
</payment>
</default>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<test>
<test backend_model="NotExistentClass<caret>" />
</test>
</payment>
</default>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<payment>
<test>
<test backend_model="Yesno<caret>" />
</test>
</payment>
</default>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check completion WON'T work for backend_model tag</label>
<backend_model>Roles<caret></backend_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check completion for backend_model tag exactly in system.xml file</label>
<backend_model>Roles<caret></backend_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check missing completion for backend_model tag</label>
<backend_model>NotExistingSource<caret></backend_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check completion for backend_model tag</label>
<backend_model>Roles<caret></backend_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="test">
<label translate="true">Test Widget</label>
<description translate="true">Test Widget</description>
<parameters>
<parameter name="test_yesno" xsi:type="select" source_model="Yesno<caret>">
<label translate="true">Test Boolean field</label>
</parameter>
</parameters>
</widget>
</widgets>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="test">
<label translate="true">Test Widget</label>
<description translate="true">Test Widget</description>
<parameters>
<parameter name="test_yesno" xsi:type="select" source_model="Yesno<caret>">
<label translate="true">Test Boolean field</label>
</parameter>
</parameters>
</widget>
</widgets>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check completion for source_model tag</label>
<source_model>Yesno<caret></source_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="catalog">
<group id="test">
<field id="test">
<label>Test suit to check completion for source_model tag</label>
<source_model>Yesno<caret></source_model>
</field>
</group>
</section>
</system>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.completion.xml;

import com.intellij.openapi.vfs.VirtualFile;
import com.magento.idea.magento2plugin.magento.files.ModuleConfigXml;
import com.magento.idea.magento2plugin.magento.files.ModuleSystemXml;
import java.io.File;

public class BackendModelXmlCompletionRegistrarTest extends CompletionLightJavaCodeInsightFixtureTestCase {

private static VirtualFile systemXmlVirtualFile;
private static VirtualFile configXmlVirtualFile;
private static final String testDataFolderPath;
private static final String fixturesFolderPath;
private static final String classesSourceFile;
private static final String[] systemXmlBackendModelLookupStringCheck;
private static final String[] configXmlBackendModelLookupStringCheck;

static {
testDataFolderPath = "testData/completion/common/";
fixturesFolderPath = "xml/BackendModelXmlCompletionRegistrar";
classesSourceFile = "classes.php";
systemXmlBackendModelLookupStringCheck = new String[]{
"Magento\\Backend\\Model\\Source\\Roles"
};
configXmlBackendModelLookupStringCheck = new String[]{
"Magento\\Config\\Model\\Config\\Source\\Yesno"
};
}

@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.copyFileToProject(classesSourceFile);
}

@Override
protected String getTestDataPath() {
return testDataFolderPath;
}

protected String getFixturePath(String folderName, String fileName) {
return fixturesFolderPath + File.separator + folderName + File.separator + fileName;
}

public void testSystemXmlBackendModelElementProvideCompletion() {
String filePath = this.getFixturePath("systemXmlElementProvideCompletion", ModuleSystemXml.FILE_NAME);
systemXmlVirtualFile = myFixture.copyFileToProject(filePath);

assertCompletionContains(filePath, systemXmlBackendModelLookupStringCheck);
}

public void testSystemXmlBackendModelElementCompletionWontShow() {
String filePath = this.getFixturePath(
"systemXmlElementCompletionWontShow",
ModuleSystemXml.FILE_NAME
);
systemXmlVirtualFile = myFixture.copyFileToProject(filePath);

assertCompletionNotShowing(filePath);
}

public void testSystemXmlBackendModelAttributeMatchWithFile() {
String filePath = this.getFixturePath(
"systemXmlBackendModelAttributeMatchWithFile",
ModuleSystemXml.FILE_NAME
);

assertCompletionMatchWithFilePositiveCase(filePath, systemXmlBackendModelLookupStringCheck);
}

public void testSystemXmlBackendModelAttributeDontMatchWithFile() {
String filePath = this.getFixturePath(
"systemXmlBackendModelAttributeDontMatchWithFile",
"other-file-than-system.xml"
);

assertCompletionMatchWithFileNegativeCase(
filePath,
systemXmlBackendModelLookupStringCheck
);
}

public void testConfigXmlBackendModelElementProvideCompletion() {
String filePath = this.getFixturePath(
"configXmlElementProvideCompletion",
ModuleConfigXml.FILE_NAME
);
configXmlVirtualFile = myFixture.copyFileToProject(filePath);

assertCompletionContains(filePath, configXmlBackendModelLookupStringCheck);
}

public void testConfigXmlBackendModelElementCompletionWontShow() {
String filePath = this.getFixturePath(
"configXmlElementCompletionWontShow",
ModuleConfigXml.FILE_NAME
);
configXmlVirtualFile = myFixture.copyFileToProject(filePath);

assertCompletionNotShowing(filePath);
}

public void testConfigXmlBackendModelAttributeMatchWithFile() {
String filePath = this.getFixturePath(
"configXmlBackendModelAttributeMatchWithFile",
ModuleConfigXml.FILE_NAME
);

assertCompletionMatchWithFilePositiveCase(filePath, configXmlBackendModelLookupStringCheck);
}

public void testConfigXmlBackendModelAttributeDontMatchWithFile() {
String filePath = this.getFixturePath(
"configXmlBackendModelAttributeDontMatchWithFile",
"other-file-than-config.xml"
);

assertCompletionMatchWithFileNegativeCase(
filePath,
configXmlBackendModelLookupStringCheck
);
}
}
Loading