Skip to content

Commit

Permalink
Merge pull request #1204 from Privado-Inc/pawan/php-tests-migrate
Browse files Browse the repository at this point in the history
PHP: Migrate older test suites to newer ones
  • Loading branch information
pawan-privado authored Jul 4, 2024
2 parents b11ca79 + bfa0997 commit 9aa12c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/
package ai.privado.languageEngine.php.tagger.source

import ai.privado.languageEngine.php.PhpTestBase
import ai.privado.model.*
import ai.privado.testfixtures.PhpFrontendTestSuite
import io.shiftleft.semanticcpg.language.*

class FieldIdentifierTaggingTests extends PhpTestBase {
class FieldIdentifierTaggingTests extends PhpFrontendTestSuite {
"Field access in code" should {
"be tagged as part of identifier tagger" in {
val (cpg, _) = code("""
val cpg = code(
"""
|<?php
|class Person {
| public $firstName;
Expand All @@ -44,8 +44,11 @@ class FieldIdentifierTaggingTests extends PhpTestBase {
| }
|}
|?>
|""".stripMargin)
|""".stripMargin,
"Test.php"
)

"be tagged as part of identifier tagger" in {
val List(firstNameField) = cpg.fieldAccess.l
firstNameField.code shouldBe "$this->firstName"
firstNameField.tag.nameExact(Constants.catLevelOne).value.l shouldBe List(CatLevelOne.SOURCES.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
*/
package ai.privado.languageEngine.php.tagger.source

import ai.privado.languageEngine.php.PhpTestBase
import ai.privado.model.*
import ai.privado.testfixtures.PhpFrontendTestSuite
import io.shiftleft.semanticcpg.language.*

class IdentifierTaggingTest extends PhpTestBase {
class IdentifierTaggingTest extends PhpFrontendTestSuite {
"Tagging derived sources" should {
val (cpg, _) = code("""
val cpg = code(
"""
|<?php
|
| class User {
Expand All @@ -51,7 +52,9 @@ class IdentifierTaggingTest extends PhpTestBase {
| echo $user->firstName;
|?>
|
|""".stripMargin)
|""".stripMargin,
"Test.php"
)

"tag member in a structure" in {
cpg.member("firstName").tag.nameExact(Constants.id).value.l shouldBe List("Data.Sensitive.FirstName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
*/
package ai.privado.languageEngine.php.tagger.source

import ai.privado.languageEngine.php.PhpTestBase
import ai.privado.cache.RuleCache
import ai.privado.model.*
import ai.privado.rule.RuleInfoTestData
import ai.privado.testfixtures.PhpFrontendTestSuite
import io.shiftleft.semanticcpg.language.*

class LiteralTaggingTests extends PhpTestBase {
class LiteralTaggingTests extends PhpFrontendTestSuite {
val configAndRules: ConfigAndRules = ConfigAndRules(sources = RuleInfoTestData.sourceRule)
val ruleCache: RuleCache = new RuleCache().setRule(configAndRules)

"Literals in code" should {
"be tagged as part of LiteralTagger" in {
val (cpg, _) = code("""
val cpg = code(
"""
|<?php
|class Person {
| function initialize() {
Expand All @@ -40,8 +45,11 @@ class LiteralTaggingTests extends PhpTestBase {
| }
|}
|?>
|""".stripMargin)
|""".stripMargin,
"Test.php"
)

"be tagged as part of LiteralTagger" in {
val literals = cpg.literal.l
literals.last.code shouldBe "\"phone\""
literals.last.tag.nameExact(Constants.catLevelOne).value.l shouldBe List(CatLevelOne.SOURCES.name)
Expand Down

0 comments on commit 9aa12c2

Please sign in to comment.