|
| 1 | +package com.cedricziel.idea.typo3.provider; |
| 2 | + |
| 3 | +import com.cedricziel.idea.typo3.AbstractTestCase; |
| 4 | +import com.intellij.psi.PsiElement; |
| 5 | +import com.intellij.psi.PsiFile; |
| 6 | +import com.jetbrains.php.lang.PhpFileType; |
| 7 | +import com.jetbrains.php.lang.psi.elements.MethodReference; |
| 8 | + |
| 9 | +public class PhpGlobalsTypeProviderTest extends AbstractTestCase { |
| 10 | + @Override |
| 11 | + protected String getTestDataPath() { |
| 12 | + return "testData/com/cedricziel/idea/typo3/provider"; |
| 13 | + } |
| 14 | + |
| 15 | + public void testGlobalTypesAreResolved() { |
| 16 | + assertCanResolveGlobalsValue( |
| 17 | + "TYPO3_REQUEST", |
| 18 | + "#M#C\\Psr\\Http\\Message\\ServerRequestInterface.getServerParams", |
| 19 | + "getServer<caret>Params" |
| 20 | + ); |
| 21 | + assertCanResolveGlobalsValue( |
| 22 | + "LANG", |
| 23 | + "#M#C\\TYPO3\\CMS\\Lang\\LanguageService.getLL", |
| 24 | + "get<caret>LL" |
| 25 | + ); |
| 26 | + assertCanResolveGlobalsValue( |
| 27 | + "TYPO3_DB", |
| 28 | + "#M#C\\TYPO3\\CMS\\Core\\Database\\DatabaseConnection.exec_SELECTgetRows", |
| 29 | + "exec_<caret>SELECTgetRows" |
| 30 | + ); |
| 31 | + assertCanResolveGlobalsValue( |
| 32 | + "BE_USER", |
| 33 | + "#M#C\\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication.getPagePermsClause", |
| 34 | + "getPagePerms<caret>Clause" |
| 35 | + ); |
| 36 | + assertCanResolveGlobalsValue( |
| 37 | + "TSFE", |
| 38 | + "#M#C\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController.getPageAndRootlineWithDomain", |
| 39 | + "getPageAndRootlineWith<caret>Domain" |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + private void assertCanResolveGlobalsValue(String index, String expectedType, String method) { |
| 44 | + PsiFile psiFile = myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" + |
| 45 | + "$foo = $GLOBALS['" + index + "'];\n" + |
| 46 | + "$foo->" + method + "();"); |
| 47 | + |
| 48 | + PsiElement elementAtCaret = psiFile.findElementAt(myFixture.getCaretOffset()); |
| 49 | + assertNotNull(elementAtCaret); |
| 50 | + assertInstanceOf(elementAtCaret.getParent(), MethodReference.class); |
| 51 | + |
| 52 | + MethodReference methodReference = (MethodReference) elementAtCaret.getParent(); |
| 53 | + assertTrue(methodReference.getType().getTypes().contains(expectedType)); |
| 54 | + } |
| 55 | +} |
0 commit comments