-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New: Filter files using file extention and regexp
- Loading branch information
1 parent
a4da475
commit 7e004a7
Showing
10 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/.phpcs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="PHP compatibility"> | ||
<description>Sniff code to check different PHP compatibility</description> | ||
|
||
<!-- What to scan --> | ||
<file>../</file> | ||
<exclude-pattern>/vendor/</exclude-pattern> | ||
<exclude-pattern>/lib/</exclude-pattern> | ||
|
||
<!-- How to scan --> | ||
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage --> | ||
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml --> | ||
<arg value="sp"/> <!-- Show sniff and progress --> | ||
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit --> | ||
<arg name="colors"/> | ||
<arg name="extensions" value="php"/> | ||
<!-- Exclude test directories --> | ||
<exclude-pattern>tests/*</exclude-pattern> | ||
<exclude-pattern>vendor/*</exclude-pattern> | ||
<exclude-pattern>fw_files/*</exclude-pattern> | ||
<arg name="exclude" value="PSR12.ControlStructures.ControlStructureSpacing"/> | ||
<arg value="n"/> | ||
|
||
<!-- Rules: Check PHP version compatibility --> | ||
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions --> | ||
<config name="testVersion" value="7.4-"/> | ||
|
||
<rule ref="PHPCompatibility"/> | ||
<rule ref="PSR12"/> | ||
</ruleset> |
29 changes: 29 additions & 0 deletions
29
lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/Scanner/HTMLTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use CleantalkSP\Common\Scanner\HeuristicAnalyser\Modules\HTML; | ||
use CleantalkSP\Common\Scanner\HeuristicAnalyser\Modules\Tokens; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HTMLTest extends TestCase | ||
{ | ||
private $html; | ||
|
||
public function setUp() | ||
{ | ||
$file_content = "<?php | ||
echo( | ||
'<script>alert(1);</script>' | ||
); | ||
?> | ||
<script>alert(2);</script> | ||
"; | ||
$tokens = new Tokens($file_content); | ||
$this->html = new HTML($tokens); | ||
} | ||
|
||
public function testAnalise() | ||
{ | ||
$this->html->analise(); | ||
$this->assertEquals('T_INLINE_HTML', $this->html->result); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/Scanner/TokensTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use CleantalkSP\Common\Scanner\HeuristicAnalyser\DataStructures\Token; | ||
use CleantalkSP\Common\Scanner\HeuristicAnalyser\Modules\Tokens; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TokensTest extends TestCase | ||
{ | ||
private $tokens; | ||
|
||
public function setUp() | ||
{ | ||
$file_content = "<?php | ||
echo('hello'); | ||
"; | ||
$this->tokens = new Tokens($file_content); | ||
} | ||
|
||
public function testGetTokenFromPosition() | ||
{ | ||
$echo_token = $this->tokens->getTokenFromPosition(2); | ||
$this->assertInstanceOf(Token::class, $echo_token); | ||
$this->assertEquals($echo_token[0], 'T_ECHO'); | ||
$this->assertEquals($echo_token[1], 'echo'); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/bootstrap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* Autoloader for \CleantalkSP\* classes | ||
* | ||
* @param string $class | ||
* | ||
* @return void | ||
*/ | ||
|
||
spl_autoload_register(function ($class) { | ||
|
||
// Register class auto loader | ||
// Custom modules1 | ||
if ( strpos($class, 'CleantalkSP') !== false ) { | ||
$class = str_replace('CleantalkSP\Common\Scanner\HeuristicAnalyser\\', DIRECTORY_SEPARATOR, $class); | ||
$class_file = dirname(__DIR__) . $class . '.php'; | ||
if ( file_exists($class_file) ) { | ||
require_once($class_file); | ||
} | ||
} | ||
}); |
17 changes: 17 additions & 0 deletions
17
lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/tests/phpunit.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<phpunit | ||
bootstrap="bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="true" | ||
beStrictAboutOutputDuringTests="true" | ||
> | ||
<testsuites> | ||
<testsuite name="CleanTalk SPBCT Heuristic Analyser classes Unit Tests"> | ||
<directory suffix=".php">./</directory> | ||
<exclude>./bootstrap.php</exclude> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
30 changes: 30 additions & 0 deletions
30
lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/tests/.phpcs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="PHP compatibility"> | ||
<description>Sniff code to check different PHP compatibility</description> | ||
|
||
<!-- What to scan --> | ||
<file>../</file> | ||
<exclude-pattern>/vendor/</exclude-pattern> | ||
<exclude-pattern>/lib/</exclude-pattern> | ||
|
||
<!-- How to scan --> | ||
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage --> | ||
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml --> | ||
<arg value="sp"/> <!-- Show sniff and progress --> | ||
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit --> | ||
<arg name="colors"/> | ||
<arg name="extensions" value="php"/> | ||
<!-- Exclude test directories --> | ||
<exclude-pattern>tests/*</exclude-pattern> | ||
<exclude-pattern>vendor/*</exclude-pattern> | ||
<exclude-pattern>fw_files/*</exclude-pattern> | ||
<arg name="exclude" value="PSR12.ControlStructures.ControlStructureSpacing"/> | ||
<arg value="n"/> | ||
|
||
<!-- Rules: Check PHP version compatibility --> | ||
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions --> | ||
<config name="testVersion" value="5.6-"/> | ||
|
||
<rule ref="PHPCompatibility"/> | ||
<rule ref="PSR12"/> | ||
</ruleset> |
1 change: 1 addition & 0 deletions
1
lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/tests/bootstrap.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
17 changes: 17 additions & 0 deletions
17
lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/tests/phpunit.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<phpunit | ||
bootstrap="bootstrap.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="true" | ||
beStrictAboutOutputDuringTests="true" | ||
> | ||
<testsuites> | ||
<testsuite name="CleanTalk SPBCT Heuristic Analyser classes Unit Tests"> | ||
<directory suffix=".php">./</directory> | ||
<exclude>./bootstrap.php</exclude> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters