File tree 6 files changed +84
-0
lines changed
completion/xml/LayoutBlockCompletionRegistrar/referenceBlockMustHaveCompletion
project/magento2/vendor/magento/module-catalog/view/frontend/layout
reference/xml/LayoutBlockReferenceRegistrar/referenceBlockMustHaveReference
tests/com/magento/idea/magento2plugin
6 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+
3
+ <page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
4
+ <body >
5
+ <referenceContainer name =" after.body.start" >
6
+ <referenceBlock name =" test_index_index<caret>" />
7
+ </referenceContainer >
8
+ </body >
9
+ </page >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+
3
+ <page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
4
+ <body >
5
+ <referenceContainer name =" after.body.start" >
6
+ <block name =" test_index_index_block" />
7
+ <block name =" test_index_index_block2" />
8
+ </referenceContainer >
9
+ </body >
10
+ </page >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+
3
+ <page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
4
+ <body >
5
+ <referenceContainer name =" after.body.start" >
6
+ <referenceBlock name =" test_index_index_block2<caret>" />
7
+ </referenceContainer >
8
+ </body >
9
+ </page >
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+ package com .magento .idea .magento2plugin .completion .xml ;
6
+
7
+ import com .magento .idea .magento2plugin .magento .files .LayoutXml ;
8
+
9
+ public class LayoutBlockCompletionRegistrarTest extends CompletionXmlFixtureTestCase {
10
+
11
+ public void testReferenceBlockMustHaveCompletion () {
12
+ String filePath = this .getFixturePath (LayoutXml .DEFAULT_FILENAME );
13
+ myFixture .configureByFile (filePath );
14
+
15
+ assertCompletionContains (filePath , new String [] {
16
+ "test_index_index_block" ,
17
+ "test_index_index_block2"
18
+ });
19
+ }
20
+ }
Original file line number Diff line number Diff line change 8
8
import com .intellij .psi .PsiFile ;
9
9
import com .intellij .psi .PsiReference ;
10
10
import com .intellij .psi .xml .XmlAttributeValue ;
11
+ import com .intellij .psi .xml .XmlTag ;
11
12
import com .jetbrains .php .lang .psi .elements .PhpClass ;
12
13
import com .magento .idea .magento2plugin .inspections .BaseInspectionsTestCase ;
13
14
import com .magento .idea .magento2plugin .magento .packages .File ;
@@ -40,6 +41,24 @@ protected void assertHasReferenceToXmlAttributeValue(String reference) {
40
41
fail (String .format (referenceNotFound , reference ));
41
42
}
42
43
44
+ protected void assertHasReferenceToXmlTag (String tagName ) {
45
+ String referenceNotFound = "Failed that element contains reference to the XML tag `%s`" ;
46
+
47
+ PsiElement element = getElementFromCaret ();
48
+ for (PsiReference psiReference : element .getReferences ()) {
49
+ PsiElement resolved = psiReference .resolve ();
50
+ if (!(resolved instanceof XmlTag )) {
51
+ continue ;
52
+ }
53
+
54
+ if (((XmlTag ) resolved ).getName ().equals (tagName )) {
55
+ return ;
56
+ }
57
+ }
58
+
59
+ fail (String .format (referenceNotFound , tagName ));
60
+ }
61
+
43
62
protected void assertHasReferenceToFile (String reference ) {
44
63
String referenceNotFound = "Failed that element contains reference to the file `%s`" ;
45
64
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright © Magento, Inc. All rights reserved.
3
+ * See COPYING.txt for license details.
4
+ */
5
+ package com .magento .idea .magento2plugin .reference .xml ;
6
+
7
+ import com .magento .idea .magento2plugin .magento .files .LayoutXml ;
8
+
9
+ public class LayoutBlockReferenceRegistrarTest extends ReferenceXmlFixtureTestCase {
10
+
11
+ public void testReferenceBlockMustHaveReference () {
12
+ String filePath = this .getFixturePath (LayoutXml .DEFAULT_FILENAME );
13
+ myFixture .configureByFile (filePath );
14
+
15
+ assertHasReferenceToXmlTag ("block" );
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments