Skip to content

Commit 0b9fa1b

Browse files
212: Added test coverage
1 parent 927e3cb commit 0b9fa1b

File tree

14 files changed

+233
-5
lines changed

14 files changed

+233
-5
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public XmlCompletionContributor() {
193193
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
194194
.inside(XmlPatterns.xmlAttribute().withName("method")
195195
.withParent(XmlPatterns.xmlTag().withName("job"))
196-
).inFile(xmlFile().withName(string().endsWith("crontab.xml"))),
196+
).inFile(xmlFile().withName(string().matches("crontab.xml"))),
197197
new PhpJobMethodCompletionContributor()
198198
);
199199

src/com/magento/idea/magento2plugin/reference/provider/PhpJobMethodReferenceProvider.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
@@ -15,7 +15,6 @@
1515
import com.jetbrains.php.lang.psi.elements.PhpClass;
1616
import com.magento.idea.magento2plugin.indexes.DiIndex;
1717
import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase;
18-
// CHECKSTYLE IGNORE check FOR NEXT 1 LINES
1918
import java.util.ArrayList;
2019
import java.util.Collection;
2120
import java.util.List;
@@ -41,7 +40,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu
4140
PhpClass phpClass = DiIndex.getPhpClassOfJobMethod((XmlElement) element);
4241
if (phpClass != null) {
4342
Collection<Method> methods = phpClass.getMethods();
44-
methods.removeIf(m -> !m.getName().equalsIgnoreCase(methodName));
43+
methods.removeIf(method -> !method.getName().contains(methodName));
4544
psiReferences.add(new PolyVariantReferenceBase(element, methods));
4645
}
4746

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar)
9393
XmlPatterns.xmlAttribute().withName("method").withParent(
9494
XmlPatterns.xmlTag().withName("job")
9595
)
96-
).inFile(xmlFile().withName(string().endsWith("crontab.xml"))),
96+
).inFile(xmlFile().withName(string().matches("crontab.xml"))),
9797
new PhpJobMethodReferenceProvider()
9898
);
9999

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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="RefreshSpe<caret>" method="">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="Magento\Catalog\Cron\RefreshSpecialPrices" method="exe<caret>">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="Magento\Catalog\Cron\RefreshSpecialPrices" method="ex<caret>">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="RefreshSpe<caret>" method="">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" wrong_attr="RefreshSpe<caret>" method="">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<jobless name="test_catalog_index_refresh_price" instance="RefreshSpe<caret>" method="">
12+
<schedule>0 * * * *</schedule>
13+
</jobless>
14+
</group>
15+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Cron;
8+
9+
class RefreshSpecialPrices
10+
{
11+
public function execute()
12+
{
13+
}
14+
15+
public function executeFull()
16+
{
17+
}
18+
}
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="Magento\Catalog\Cron\RefreshSpecialPrices<caret>" method="">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
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:module:Magento_Cron:etc/crontab.xsd">
10+
<group id="default">
11+
<job name="test_catalog_index_refresh_price" instance="Magento\Catalog\Cron\RefreshSpecialPrices" method="execute<caret>">
12+
<schedule>0 * * * *</schedule>
13+
</job>
14+
</group>
15+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.CrontabXmlTemplate;
9+
10+
public class CrontabCompletionRegistrarTest extends CompletionXmlFixtureTestCase {
11+
private static final String EXPECTED_INSTANCE = "Magento\\Catalog\\Cron\\RefreshSpecialPrices";
12+
private static final String EXPECTED_METHOD = "execute";
13+
private static final String WRONG_FILE_NAME = "wrong_named_crontab.xml";
14+
15+
/**
16+
* The `instance` attribute of the `job` tag in crontab.xml must
17+
* have completion based on PHP classes index.
18+
*/
19+
public void testCronJobInstanceMustHaveCompletion() {
20+
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
21+
assertCompletionContains(filePath, EXPECTED_INSTANCE);
22+
}
23+
24+
/**
25+
* The `instance` attribute of the `job` tag in the
26+
* non crontab.xml file must not have completion.
27+
*/
28+
public void testNotCrontabXmlMustHaveNotCompletion() {
29+
final String filePath = this.getFixturePath(WRONG_FILE_NAME);
30+
assertCompletionNotShowing(filePath);
31+
}
32+
33+
/**
34+
* The non `instance` attribute of the `job` tag in crontab.xml must
35+
* not have completion.
36+
*/
37+
public void testNotInstanceAttrMustHaveNotCompletion() {
38+
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
39+
assertCompletionNotShowing(filePath);
40+
}
41+
42+
/**
43+
* The `instance` attribute that isn't in the `job` tag in crontab.xml must
44+
* not have completion.
45+
*/
46+
public void testNotJobTagMustHaveNotCompletion() {
47+
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
48+
assertCompletionNotShowing(filePath);
49+
}
50+
51+
/**
52+
* The `method` attribute of the `job` tag in crontab.xml must
53+
* have completion based on PHP Job method completion provider.
54+
*/
55+
public void testCronJobMethodMustHaveCompletion() {
56+
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
57+
assertCompletionContains(filePath, EXPECTED_METHOD);
58+
}
59+
60+
/**
61+
* The `method` attribute must not have completion
62+
* if it isn`t in the crontab.xml file.
63+
*/
64+
public void testNotCrontabXmlMethodMustHaveNotCompletion() {
65+
final String filePath = this.getFixturePath(WRONG_FILE_NAME);
66+
assertCompletionNotShowing(filePath);
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.CrontabXmlTemplate;
9+
10+
public class CrontabReferenceRegistrarTest extends ReferenceXmlFixtureTestCase {
11+
private static final String EXPECTED_REFERENCE = "Magento\\Catalog\\Cron\\RefreshSpecialPrices";
12+
13+
/**
14+
* Test instance attribute of the crontab.xml file
15+
* must have reference.
16+
*/
17+
public void testCrontabInstanceMustHaveReference() {
18+
final String filePath = this.getFixturePath(CrontabXmlTemplate.FILE_NAME);
19+
myFixture.configureByFile(filePath);
20+
21+
assertHasReferencePhpClass(EXPECTED_REFERENCE);
22+
}
23+
}

0 commit comments

Comments
 (0)