forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseProjectTestCase.java
88 lines (75 loc) · 2.91 KB
/
BaseProjectTestCase.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
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.IndexingTestUtil;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import com.magento.idea.magento2plugin.indexes.IndexManager;
import com.magento.idea.magento2plugin.magento.packages.File;
import com.magento.idea.magento2plugin.project.Settings;
/**
* Configure test environment with Magento 2 project.
*/
public abstract class BaseProjectTestCase extends BasePlatformTestCase {
private static final String testDataProjectPath = "testData" //NOPMD
+ File.separator
+ "project";
private static final String testDataProjectDirectory = "magento2"; //NOPMD
@Override
public void setUp() throws Exception {
super.setUp();
copyMagento2ToTestProject();
enablePluginAndReindex();
}
private void copyMagento2ToTestProject() {
myFixture.setTestDataPath(testDataProjectPath);
myFixture.copyDirectoryToProject(
testDataProjectDirectory,
""
);
}
@Override
protected String getTestDataPath() {
//configure specific test data in your test.
return "testData";
}
protected void enablePluginAndReindex() {
final Settings settings = Settings.getInstance(myFixture.getProject());
settings.magentoPath = "/src";
settings.pluginEnabled = true;
settings.mftfSupportEnabled = true;
IndexManager.manualReindex();
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
IndexingTestUtil.waitUntilIndexesAreReady(myFixture.getProject());
}
protected void disablePluginAndReindex() {
final Settings settings = Settings.getInstance(myFixture.getProject());
settings.pluginEnabled = false;
IndexManager.manualReindex();
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
IndexingTestUtil.waitUntilIndexesAreReady(myFixture.getProject());
}
protected void disableMftfSupportAndReindex() {
final Settings settings = Settings.getInstance(myFixture.getProject());
settings.mftfSupportEnabled = false;
IndexManager.manualReindex();
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
IndexingTestUtil.waitUntilIndexesAreReady(myFixture.getProject());
}
protected String prepareFixturePath(
final String fileName,
final String fixturesFolderPath
) {
return fixturesFolderPath + getClass().getSimpleName().replace("Test", "")
+ File.separator
+ name()
+ File.separator
+ fileName;
}
private String name() {
return StringUtil.trimEnd(getTestName(true), "Test");
}
}