forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreferenceDeclarationInspectionTest.java
150 lines (120 loc) · 4.47 KB
/
PreferenceDeclarationInspectionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.inspections.xml;
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
public class PreferenceDeclarationInspectionTest extends InspectionXmlFixtureTestCase {
private static final String ARGUMENT_VALUE_IS_EMPTY =
"inspection.error.idAttributeCanNotBeEmpty";
private static final String CLASS_DOES_NOT_EXIST =
"inspection.warning.class.does.not.exist";
private static final String EXISTENT_CLASS_ONE =
"Magento\\Catalog\\Api\\ProductRepositoryInterface";
private static final String EXISTENT_CLASS_TWO =
"Foo\\Bar\\Model\\Logger";
private static final String NOT_EXISTENT_CLASS =
"Not\\Existent\\Class";
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(PreferenceDeclarationInspection.class);
}
/**
* Test for an error for the "for" attribute because it is empty.
* <preference for="" type="Foo\Bar\Model\Logger"/>
*/
public void testAttrArgForValueIsEmpty() {
configureFixture();
final String forAttrIsEmptyMessage = inspectionBundle.message(
ARGUMENT_VALUE_IS_EMPTY,
ModuleDiXml.PREFERENCE_ATTR_FOR
);
assertHasHighlighting(forAttrIsEmptyMessage);
}
/**
* Test for an error for the "type" attribute because it is empty.
* <preference for="Foo\Bar\Model\Logger" type="Foo\Bar\Model\Logger"/>
*/
public void testAttrArgTypeValueIsEmpty() {
configureFixture();
final String forAttrIsEmptyMessage = inspectionBundle.message(
ARGUMENT_VALUE_IS_EMPTY,
ModuleDiXml.TYPE_ATTR
);
assertHasHighlighting(forAttrIsEmptyMessage);
}
/**
* Test for an no error for the "for" attribute because this class exists.
* <preference for="Foo\Bar\Model\Logger" type=""/>
*/
public void testAttrForClassExists() {
configureFixture();
final String typeAttrIsEmptyMessage = inspectionBundle.message(
ARGUMENT_VALUE_IS_EMPTY,
ModuleDiXml.PREFERENCE_ATTR_FOR
);
assertHasNoHighlighting(typeAttrIsEmptyMessage);
}
/**
* Test for an no error for the "type" attribute because this class exists.
* <preference for="" type="Foo\Bar\Model\Logger"/>
*/
public void testAttrTypeClassExists() {
configureFixture();
final String typeAttrIsEmptyMessage = inspectionBundle.message(
ARGUMENT_VALUE_IS_EMPTY,
ModuleDiXml.TYPE_ATTR
);
assertHasNoHighlighting(typeAttrIsEmptyMessage);
}
/**
* Test for throwing an error for a class that does not exist for the "for" attribute.
*/
public void testClassAttrForDoesNotExists() {
configureFixture();
final String forClassDoesNotExists = inspectionBundle.message(
CLASS_DOES_NOT_EXIST,
NOT_EXISTENT_CLASS
);
assertHasHighlighting(forClassDoesNotExists);
}
/**
* Test for the absence of an error in the presence of
* classes or interfaces specified for preferences.
*/
public void testClassAttrForIsExist() {
configureFixture();
final String classOneExists = inspectionBundle.message(
CLASS_DOES_NOT_EXIST,
EXISTENT_CLASS_ONE
);
assertHasNoHighlighting(classOneExists);
}
/**
* Test for throwing an error for a class that does not exist for the "type" attribute.
*/
public void testClassAttrTypeDoesNotExists() {
configureFixture();
final String forClassDoesNotExists = inspectionBundle.message(
CLASS_DOES_NOT_EXIST,
NOT_EXISTENT_CLASS
);
assertHasHighlighting(forClassDoesNotExists);
}
/**
* Test for the absence of an error in the presence of
* classes or interfaces specified for preferences.
*/
public void testClassAttrTypeIsExist() {
configureFixture();
final String classOneExists = inspectionBundle.message(
CLASS_DOES_NOT_EXIST,
EXISTENT_CLASS_TWO
);
assertHasNoHighlighting(classOneExists);
}
private void configureFixture() {
myFixture.configureByFile(getFixturePath(ModuleDiXml.FILE_NAME));
}
}