aboutsummaryrefslogtreecommitdiffstats
path: root/its
diff options
context:
space:
mode:
authorAlban Auzeill2019-12-12 10:47:22 +0100
committerElena Vilchik2019-12-12 10:47:22 +0100
commit13fe08e87c8a70ffe6e248b774ef826bbe1f779d (patch)
tree582a26fb92a2382a76153a35e61316bd360614ab /its
parentccc590679d3a9ed060b875fbbaf2825bd37bf334 (diff)
downloadsonar-css-13fe08e87c8a70ffe6e248b774ef826bbe1f779d.tar.bz2
Analyze CSS in non-CSS files even if no CSS files in the project (#218)
Diffstat (limited to 'its')
-rw-r--r--its/plugin/projects/php-project/src/index.php13
-rw-r--r--its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java64
-rw-r--r--its/plugin/src/test/java/org/sonar/css/its/Tests.java1
3 files changed, 78 insertions, 0 deletions
diff --git a/its/plugin/projects/php-project/src/index.php b/its/plugin/projects/php-project/src/index.php
new file mode 100644
index 0000000..54d36ee
--- /dev/null
+++ b/its/plugin/projects/php-project/src/index.php
@@ -0,0 +1,13 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <title>Index</title>
+ <style>
+ /* S4658 empty block */
+ p { }
+ </style>
+</head>
+<body>
+ <?= "Hello World!" ?>
+</body>
+</html>
diff --git a/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java b/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java
new file mode 100644
index 0000000..04f2384
--- /dev/null
+++ b/its/plugin/src/test/java/org/sonar/css/its/NoCssFileProjectTest.java
@@ -0,0 +1,64 @@
+/*
+ * SonarCSS
+ * Copyright (C) 2018-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.css.its;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.ws.Issues;
+import org.sonarqube.ws.client.issues.SearchRequest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.sonar.css.its.Tests.newWsClient;
+
+public class NoCssFileProjectTest {
+
+ private static String PROJECT_KEY = "php-project";
+
+ @ClassRule
+ public static Orchestrator orchestrator = Tests.ORCHESTRATOR;
+
+ @BeforeClass
+ public static void prepare() {
+ orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
+ SonarScanner scanner = Tests.createScanner(PROJECT_KEY);
+ scanner.setProperty("sonar.php.file.suffixes", ".php");
+ orchestrator.executeBuild(scanner);
+ }
+
+ @Test
+ public void test() {
+ SearchRequest request = new SearchRequest();
+ request.setComponentKeys(Collections.singletonList(PROJECT_KEY));
+ List<Issues.Issue> issuesList = newWsClient().issues().search(request).getIssuesList().stream()
+ .filter(i -> i.getRule().startsWith("css:"))
+ .collect(Collectors.toList());
+
+ assertThat(issuesList).extracting(Issues.Issue::getRule, Issues.Issue::getLine, Issues.Issue::getComponent).containsExactlyInAnyOrder(
+ tuple("css:S4658", 7, "php-project:src/index.php"));
+ }
+
+}
diff --git a/its/plugin/src/test/java/org/sonar/css/its/Tests.java b/its/plugin/src/test/java/org/sonar/css/its/Tests.java
index f252263..bc9a418 100644
--- a/its/plugin/src/test/java/org/sonar/css/its/Tests.java
+++ b/its/plugin/src/test/java/org/sonar/css/its/Tests.java
@@ -40,6 +40,7 @@ import org.sonarqube.ws.client.measures.ComponentRequest;
@Suite.SuiteClasses({
MetricsTest.class,
IssuesTest.class,
+ NoCssFileProjectTest.class,
StylelintReportTest.class,
MinifiedTest.class
})