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

Fixed plugin generation sort order requirement #389

Merged
merged 5 commits into from
Nov 18, 2020
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 @@ -2,7 +2,12 @@
<type name="${TYPE}">
#end
<plugin name="${NAME}"
type="${PLUGIN_TYPE}" sortOrder="${SORT_ORDER}" />
#if (${SORT_ORDER})
type="${PLUGIN_TYPE}"
sortOrder="${SORT_ORDER}" />
#else
type="${PLUGIN_TYPE}" />
#end
#if (${TYPE})
</type>
#end
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
</grid>
</constraints>
<properties>
<text value="10"/>
<toolTipText value="Plugin sort order in di.xml"/>
</properties>
<clientProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public class CreateAPluginDialog extends AbstractDialog {
message = {DirectoryRule.MESSAGE, DIRECTORY})
private JTextField pluginDirectory;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, SORT_ORDER})
@FieldValidation(rule = RuleRegistry.NUMERIC,
message = {NumericRule.MESSAGE, SORT_ORDER})
private JTextField pluginSortOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ protected void fillAttributes(final Properties attributes) {
attributes.setProperty("NAME", pluginFileData.getPluginName());
attributes.setProperty("PLUGIN_TYPE", pluginFileData.getPluginFqn());
attributes.setProperty("PLUGIN_NAME", pluginFileData.getPluginName());
attributes.setProperty("SORT_ORDER", pluginFileData.getSortOrder());
final String sortOrder = pluginFileData.getSortOrder();
if (!sortOrder.isEmpty()) {
attributes.setProperty("SORT_ORDER", sortOrder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Foo\Bar\Model\PluginTargetClassOne">
<plugin name="test_plugin_name_1"
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
type="Foo\Bar\Plugin\TestOnePlugin"
sortOrder="10"/>
</type>
<type name="Foo\Bar\Model\PluginTargetClassTwo">
<plugin name="test_plugin_name_2"
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
type="Foo\Bar\Plugin\TestTwoPlugin"
sortOrder="20"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Foo\Bar\Model\PluginTargetClassOne">
<plugin name="test_plugin_name_1"
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
type="Foo\Bar\Plugin\TestOnePlugin"
sortOrder="10"/>
<plugin name="test_plugin_name_2"
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
type="Foo\Bar\Plugin\TestTwoPlugin"
sortOrder="20"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Foo\Bar\Model\PluginTargetClassTwo">
<plugin name="test_plugin_name_2"
type="Foo\Bar\Plugin\TestTwoPlugin" sortOrder="20"/>
type="Foo\Bar\Plugin\TestTwoPlugin"
sortOrder="20"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Foo\Bar\Model\PluginTargetClassOne">
<plugin name="test_plugin_name_1"
type="Foo\Bar\Plugin\TestOnePlugin" sortOrder="10"/>
type="Foo\Bar\Plugin\TestOnePlugin"
sortOrder="10"/>
</type>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Foo\Bar\Model\PluginTargetClassOne">
<plugin name="test_plugin_name_1"
type="Foo\Bar\Plugin\TestOnePlugin"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ public class PluginDiXmlGeneratorTest extends BaseGeneratorTestCase {
private static final String PLUGIN_CLASS_TWO_FNQ = "Foo\\Bar\\Plugin\\TestTwoPlugin";
private static final String MODULE = "Foo_Bar";
private static final String MODULE_DIR = "src/app/code/Foo/Bar/";
private static final String TEST_PLUGIN_NAME = "test_plugin_name_1";

/**
* Test checks whether di.xml is generated correctly for the base area
*/
public void testGeneratePluginDiXmlFileWithoutSortOrder() {
final PsiFile expectedFile = myFixture.configureByFile(
this.getFixturePath(ModuleDiXml.FILE_NAME)
);
final String area = Areas.base.toString();

final PsiFile diXml = addPluginDiXml(
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"",
TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);

assertGeneratedFileIsCorrect(
expectedFile,
getExpectedDirectory(area),
diXml
);
}

/**
* Test checks whether di.xml is generated correctly for the base area
Expand All @@ -37,7 +62,7 @@ public void testGeneratePluginDiXmlFileForBaseArea() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
"test_plugin_name_1",
TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);

Expand Down Expand Up @@ -82,7 +107,7 @@ public void testAddTwoPluginsToOneDiXml() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
"test_plugin_name_1",
TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);
final PsiFile diXml = addPluginDiXml(
Expand Down Expand Up @@ -111,7 +136,7 @@ public void testAddTwoPluginsToOneTargetClass() {
PLUGIN_TARGET_CLASS_ONE_FNQ,
area,
"10",
"test_plugin_name_1",
TEST_PLUGIN_NAME,
PLUGIN_CLASS_ONE_FNQ
);
final PsiFile diXml = addPluginDiXml(
Expand Down