Skip to content

Commit 240c69a

Browse files
author
Vitaliy Boyko
committedApr 1, 2020
Added test for CacheableFalseInDefaultLayoutInspection, updated inspection
1 parent a3ba8f1 commit 240c69a

File tree

10 files changed

+96
-88
lines changed

10 files changed

+96
-88
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ out
5050
.idea-sandbox
5151
build
5252
gradle
53+
gradlew
54+
gradlew.bat

‎build.gradle

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ intellij {
3333
}
3434

3535
sourceSets {
36-
main.java.srcDirs = ['src']
37-
main.resources.srcDirs = ['resources']
36+
main {
37+
java.srcDirs 'src'
38+
resources.srcDir 'resources'
39+
}
40+
test {
41+
java.srcDir 'tests'
42+
resources.srcDir 'testData'
43+
}
3844
}

‎gradlew

Whitespace-only changes.

‎gradlew.bat

-84
This file was deleted.

‎src/com/magento/idea/magento2plugin/inspections/xml/CacheableFalseInDefaultLayoutInspection.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
import org.jetbrains.annotations.NotNull;
1616

1717
public class CacheableFalseInDefaultLayoutInspection extends XmlSuppressableInspectionTool {
18+
public static final String CacheDisableProblemDescription = "Cacheable false attribute on the default layout will disable cache site-wide";
19+
1820
@NotNull
1921
@Override
2022
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) {
2123
return new XmlElementVisitor() {
22-
private static final String CacheDisableProblemDescription = "Cacheable false attribute on the default layout will disable cache site-wide";
2324
@Override
2425
public void visitXmlAttribute(XmlAttribute attribute) {
2526
String fileName = holder.getFile().getName();
2627
if (!fileName.equals(LayoutXml.DefaultFileName)) return;
2728
final String text = attribute.getValue();
2829
final String attributeName = attribute.getName();
2930
if (!attributeName.equals(LayoutXml.CacheableAttributeName)) return;
30-
if (!attribute.getParent().getName().equals(LayoutXml.BlockAttributeTagName)) return;
31+
if (!attribute.getParent().getName().equals(LayoutXml.BlockAttributeTagName)
32+
&& !attribute.getParent().getName().equals(LayoutXml.ReferenceBlockAttributeTagName)) return;
3133
if (text == null) return;
3234
if (text.equals(LayoutXml.CacheableAttributeFalseValue)) {
3335
holder.registerProblem(attribute, CacheDisableProblemDescription,

‎src/com/magento/idea/magento2plugin/magento/files/LayoutXml.java

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public class LayoutXml {
99
public static String CacheableAttributeName = "cacheable";
1010
public static String CacheableAttributeFalseValue = "false";
1111
public static String BlockAttributeTagName = "block";
12+
public static String ReferenceBlockAttributeTagName = "referenceBlock";
1213
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page>
9+
<body>
10+
<referenceBlock name="footer_links" <warning descr="Cacheable false attribute on the default layout will disable cache site-wide">cacheable="false"</warning>/>
11+
</body>
12+
</page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page>
9+
<body>
10+
<referenceBlock name="footer_links" cacheable="false" />
11+
</body>
12+
</page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page>
9+
<body>
10+
<referenceBlock name="footer_links"/>
11+
</body>
12+
</page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.inspections.xml;
6+
7+
import com.magento.idea.magento2plugin.magento.files.LayoutXml;
8+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
9+
import java.io.File;
10+
11+
//tested referenceBlock only as block tag is Special markup for the tests
12+
//@see https://www.jetbrains.org/intellij/sdk/docs/basics/testing_plugins/test_project_and_testdata_directories.html
13+
public class CacheableFalseInDefaultLayoutInspectionTest extends BasePlatformTestCase {
14+
@Override
15+
public void setUp() throws Exception {
16+
super.setUp();
17+
myFixture.enableInspections(CacheableFalseInDefaultLayoutInspection.class);
18+
}
19+
20+
@Override
21+
protected String getTestDataPath() {
22+
return new File("testData/inspections/xml/"
23+
+ getClass().getSimpleName().replace("Test", "")).getAbsolutePath();
24+
}
25+
26+
@Override
27+
protected boolean isWriteActionRequired() {
28+
return false;
29+
}
30+
31+
public void testWithCacheableFalseBlock() throws Exception {
32+
myFixture.configureByFile(getTestName(true) + "/" + LayoutXml.DefaultFileName);
33+
myFixture.testHighlighting(true, false, false);
34+
}
35+
36+
public void testWithoutCacheableFalseBlock() throws Exception {
37+
myFixture.configureByFile(getTestName(true) + "/" + LayoutXml.DefaultFileName);
38+
myFixture.testHighlighting(true, true, true);
39+
}
40+
41+
public void testWithCacheableFalseBlockNotDefaultLayout() throws Exception {
42+
myFixture.configureByFile(getTestName(true) + "/" + "some_layout_index.xml");
43+
myFixture.testHighlighting(true, true, true);
44+
}
45+
}

0 commit comments

Comments
 (0)