Skip to content

Commit 17465fd

Browse files
author
Vitaliy Boyko
committed
Added Observer test coverage (LineMarkers, Completion, Reference)
1 parent 656f4d5 commit 17465fd

File tree

20 files changed

+366
-2
lines changed

20 files changed

+366
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.magento.idea.magento2plugin.completion.provider.*;
1212
import com.magento.idea.magento2plugin.completion.provider.mftf.*;
1313
import com.magento.idea.magento2plugin.magento.files.*;
14-
1514
import static com.intellij.patterns.PlatformPatterns.psiElement;
1615
import static com.intellij.patterns.StandardPatterns.string;
1716
import static com.intellij.patterns.XmlPatterns.xmlFile;
@@ -103,6 +102,16 @@ public XmlCompletionContributor() {
103102
new PhpConstructorArgumentCompletionProvider()
104103
);
105104

105+
// <observer instance="Class">
106+
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
107+
.inside(XmlPatterns.xmlAttribute().withName(ModuleEventsXml.INSTANCE_ATTRIBUTE)
108+
.withParent(XmlPatterns.xmlTag().withName(ModuleEventsXml.OBSERVER_TAG)
109+
.withParent(XmlPatterns.xmlTag().withName(ModuleEventsXml.EVENT_TAG))
110+
)
111+
).inFile(xmlFile().withName(string().matches(ModuleEventsXml.FILE_NAME))),
112+
new PhpClassCompletionProvider()
113+
);
114+
106115
// <source_model>php class completion</source_model> in system.xml files.
107116
extend(CompletionType.BASIC, psiElement(XmlTokenType.XML_DATA_CHARACTERS)
108117
.inside(XmlPatterns.xmlTag().withName(ModuleSystemXml.XML_TAG_SOURCE_MODEL)

src/com/magento/idea/magento2plugin/magento/files/ModuleEventsXml.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class ModuleEventsXml implements ModuleFileInterface {
1414
//code templates
1515
public static String TEMPLATE_OBSERVER = "Magento Module Events Xml Observer";
1616

17+
//tags
18+
public static String OBSERVER_TAG = "observer";
19+
public static String INSTANCE_ATTRIBUTE = "instance";
20+
public static String EVENT_TAG = "event";
21+
1722
private static ModuleEventsXml INSTANCE = null;
1823

1924
public static ModuleEventsXml getInstance() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
10+
<event name="test_e<caret>">
11+
<observer name="test_observer" instance="Observer" />
12+
</event>
13+
</config>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
10+
<event name="test_event">
11+
<observer name="test_observer" instance="Observer<caret>" />
12+
</event>
13+
</config>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
10+
<event name="test_event">
11+
<observer name="test_observer" instance="Observer<caret>" />
12+
</event>
13+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Observer;
8+
9+
use Magento\Framework\Event\ObserverInterface;
10+
11+
class TestObserver implements ObserverInterface
12+
{
13+
public function execute()
14+
{
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model;
8+
9+
class TestNotObserver
10+
{
11+
public function execute()
12+
{
13+
}
14+
}

testData/project/magento2/vendor/magento/module-catalog/Block/Navigation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ class Navigation extends \Magento\Framework\View\Element\Template implements
1111
{
1212
public function someMethod()
1313
{
14+
$this->_eventManager->dispatch('test_event_in_block', ['response_object' => "test"]);
1415
}
1516
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Observer;
8+
9+
use Magento\Framework\Event\ObserverInterface;
10+
11+
class TestObserver implements ObserverInterface
12+
{
13+
public function execute()
14+
{
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
10+
<event name="test_event_in_test_class">
11+
<observer name="test_observer" instance="Magento\Catalog\Observer\TestObserver" />
12+
</event>
13+
</config>

0 commit comments

Comments
 (0)