|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | +package com.magento.idea.magento2plugin.linemarker.php; |
| 6 | + |
| 7 | +import com.intellij.openapi.application.impl.ApplicationInfoImpl; |
| 8 | +import com.magento.idea.magento2plugin.MagentoIcons; |
| 9 | + |
| 10 | +public class WebApiLinemarkerRegistrarTest extends LinemarkerPhpFixtureTestCase { |
| 11 | + |
| 12 | + private static final String expectedClassLineMarkerTooltip = |
| 13 | + "Navigate to Web API configuration:<pre> PUT /V1/blog/post\n" + |
| 14 | + " POST /V1/blog/update\n" + |
| 15 | + "</pre>"; |
| 16 | + |
| 17 | + private static final String expectedMethodCreateLineMarkerTooltip = |
| 18 | + "Navigate to Web API configuration:<pre> POST /V1/blog/update\n" + |
| 19 | + "</pre>"; |
| 20 | + |
| 21 | + private static final String expectedMethodUpdateLineMarkerTooltip = |
| 22 | + "Navigate to Web API configuration:<pre> PUT /V1/blog/post\n" + |
| 23 | + "</pre>"; |
| 24 | + |
| 25 | + /** |
| 26 | + * Class configured as WEB API service in web_api.xml should have WEB API line markers |
| 27 | + */ |
| 28 | + public void testWebApiServiceShouldHaveLinemarker() { |
| 29 | + String filePath = this.getFixturePath("TestService.php"); |
| 30 | + |
| 31 | + //work around for issue caused by com.magento.idea.magento2plugin.linemarker.xml.LineMarkerXmlTagDecorator |
| 32 | + //in com.intellij.psi.impl.smartPointers.SmartPsiElementPointerImpl.createElementInfo |
| 33 | + boolean isInStressTestCurrent = ApplicationInfoImpl.isInStressTest(); |
| 34 | + ApplicationInfoImpl.setInStressTest(true); |
| 35 | + |
| 36 | + myFixture.configureByFile(filePath); |
| 37 | + |
| 38 | + //assert class line marker |
| 39 | + assertHasLinemarkerWithTooltipAndIcon(expectedClassLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 40 | + |
| 41 | + //assert methods line markers |
| 42 | + assertHasLinemarkerWithTooltipAndIcon(expectedMethodCreateLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 43 | + assertHasLinemarkerWithTooltipAndIcon(expectedMethodUpdateLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 44 | + |
| 45 | + //restore default value |
| 46 | + ApplicationInfoImpl.setInStressTest(isInStressTestCurrent); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Regular class should not have WEB API line markers |
| 51 | + */ |
| 52 | + public void testRegularPhpClassShouldNotHaveLinemarker() { |
| 53 | + String filePath = this.getFixturePath("ClassNotConfiguredInWebApiXml.php"); |
| 54 | + myFixture.configureByFile(filePath); |
| 55 | + |
| 56 | + //assert class line marker |
| 57 | + assertHasNoLinemarkerWithTooltipAndIcon(expectedClassLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 58 | + |
| 59 | + //assert methods line markers |
| 60 | + assertHasNoLinemarkerWithTooltipAndIcon(expectedMethodCreateLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 61 | + assertHasNoLinemarkerWithTooltipAndIcon(expectedMethodUpdateLineMarkerTooltip, MagentoIcons.WEB_API.toString()); |
| 62 | + } |
| 63 | +} |
0 commit comments