-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from joubertredrat/feature/unit-tests
Unit tests support
- Loading branch information
Showing
11 changed files
with
269 additions
and
8 deletions.
There are no files selected for viewing
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,53 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- '*.md' | ||
- '*.json' | ||
- '*.png' | ||
- 'license' | ||
- '.editorconfig' | ||
|
||
jobs: | ||
tests: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: | ||
- '7.3' | ||
- '7.4' | ||
- '8.0' | ||
- '8.1' | ||
- '8.2' | ||
- '8.3' | ||
matomo-target: | ||
- minimum_required_matomo | ||
- maximum_supported_matomo | ||
node: | ||
- 12.x | ||
- 20.x | ||
runs-on: ubuntu-latest | ||
permissions: | ||
checks: write | ||
pull-requests: write | ||
contents: read | ||
name: >- | ||
Tests w/ PHP ${{ matrix.php }}, Node.js ${{ matrix.node }}, Target Matomo | ||
'${{ matrix.matomo-target }}' | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
lfs: true | ||
persist-credentials: false | ||
- name: Run plugin tests | ||
uses: matomo-org/github-action-tests@main | ||
with: | ||
plugin-name: ProtectTrackID | ||
test-type: PluginTests | ||
php-version: '${{ matrix.php }}' | ||
matomo-test-branch: '${{ matrix.matomo-target }}' | ||
node-version: '${{ matrix.node }}' | ||
mysql-service: true | ||
phpunit-test-options: --testdox |
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
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
{ | ||
"require": { | ||
"php": ">=7.3.5", | ||
"ext-bcmath": "*", | ||
"ext-gmp": "*", | ||
"ext-mbstring": "*", | ||
"hashids/hashids": "^4.1", | ||
"ramsey/uuid": "4.2.3" | ||
}, | ||
"suggest": { | ||
"ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).", | ||
"ext-gmp": "Required to use GNU multiple precision mathematics (*)." | ||
} | ||
} |
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,3 @@ | ||
<?php | ||
|
||
return []; |
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,3 @@ | ||
<?php | ||
|
||
return []; |
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,3 @@ | ||
<?php | ||
|
||
return []; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
* @copyright (c) 2024 Joubert RedRat | ||
* @author Joubert RedRat <[email protected]> | ||
* @license MIT | ||
* @category Matomo_Plugins | ||
* @package ProtectTrackID | ||
*/ | ||
|
||
namespace Piwik\Plugins\ProtectTrackID\tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Piwik\Plugins\ProtectTrackID\Hasher; | ||
use Piwik\Plugins\ProtectTrackID\PluginSettings; | ||
|
||
/** | ||
* @group ProtectTrackID | ||
* @group HasherTest | ||
* @group Plugins | ||
*/ | ||
class HasherTest extends TestCase | ||
{ | ||
const ID_1_RAW = '1'; | ||
const ID_1_HASEHD = '4jMymK3Eq1k21pxLOJlv'; | ||
|
||
public function testEncode(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
'ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345', | ||
'd4768387-2f45-47cc-b581-7f66c5b724af', | ||
20 | ||
); | ||
|
||
$hasher = new Hasher($pluginSettings); | ||
$hashExpected = self::ID_1_HASEHD; | ||
$hashGot = $hasher->encode(self::ID_1_RAW); | ||
|
||
self::assertEquals($hashExpected, $hashGot); | ||
} | ||
|
||
public function testDecode(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
'ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345', | ||
'd4768387-2f45-47cc-b581-7f66c5b724af', | ||
20 | ||
); | ||
|
||
$hasher = new Hasher($pluginSettings); | ||
$idExpected = self::ID_1_RAW; | ||
$idGot = $hasher->decode(self::ID_1_HASEHD); | ||
|
||
self::assertEquals($idExpected, $idGot); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
* @copyright (c) 2024 Joubert RedRat | ||
* @author Joubert RedRat <[email protected]> | ||
* @license MIT | ||
* @category Matomo_Plugins | ||
* @package ProtectTrackID | ||
*/ | ||
|
||
namespace Piwik\Plugins\ProtectTrackID\tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Piwik\Plugins\ProtectTrackID\InvalidSettingValueException; | ||
|
||
/** | ||
* @group ProtectTrackID | ||
* @group InvalidSettingValueExceptionTest | ||
* @group Plugins | ||
*/ | ||
class InvalidSettingValueExceptionTest extends TestCase | ||
{ | ||
public function testHandleBase(): void | ||
{ | ||
$this->expectException(InvalidSettingValueException::class); | ||
$this->expectExceptionMessage('Invalid value on base, was filled foo.'); | ||
|
||
throw InvalidSettingValueException::handleBase('foo'); | ||
} | ||
|
||
public function testHandleSalt(): void | ||
{ | ||
$this->expectException(InvalidSettingValueException::class); | ||
$this->expectExceptionMessage('Invalid value on salt, was filled foo.'); | ||
|
||
throw InvalidSettingValueException::handleSalt('foo'); | ||
} | ||
|
||
public function testHandleLenght(): void | ||
{ | ||
$this->expectException(InvalidSettingValueException::class); | ||
$this->expectExceptionMessage('Invalid value on length, expected between 5 and 25, was filled 30.'); | ||
|
||
throw InvalidSettingValueException::handleLenght(5, 25, 30); | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
* @copyright (c) 2024 Joubert RedRat | ||
* @author Joubert RedRat <[email protected]> | ||
* @license MIT | ||
* @category Matomo_Plugins | ||
* @package ProtectTrackID | ||
*/ | ||
|
||
namespace Piwik\Plugins\ProtectTrackID\tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Piwik\Plugins\ProtectTrackID\PluginSettings; | ||
|
||
/** | ||
* @group ProtectTrackID | ||
* @group PluginSettingsTest | ||
* @group Plugins | ||
*/ | ||
class PluginSettingsTest extends TestCase | ||
{ | ||
public function testHasValidValues(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
'ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345', | ||
'd4768387-2f45-47cc-b581-7f66c5b724af', | ||
20 | ||
); | ||
|
||
self::assertTrue($pluginSettings->hasValidValues()); | ||
} | ||
|
||
public function testHasNotValidValuesByBase(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
null, | ||
'd4768387-2f45-47cc-b581-7f66c5b724af', | ||
20 | ||
); | ||
|
||
self::assertFalse($pluginSettings->hasValidValues()); | ||
} | ||
|
||
public function testHasNotValidValuesBySalt(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
'ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345', | ||
null, | ||
20 | ||
); | ||
|
||
self::assertFalse($pluginSettings->hasValidValues()); | ||
} | ||
|
||
public function testHasNotValidValuesByLength(): void | ||
{ | ||
$pluginSettings = new PluginSettings( | ||
'ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345', | ||
'd4768387-2f45-47cc-b581-7f66c5b724af', | ||
null | ||
); | ||
|
||
self::assertFalse($pluginSettings->hasValidValues()); | ||
} | ||
|
||
public function testIsValidBase(): void | ||
{ | ||
self::assertTrue(PluginSettings::isValidBase('ABCDEFGHIJKLMNOPijklmnopqrstuvxwyz12345')); | ||
} | ||
|
||
public function testIsNotValidBase(): void | ||
{ | ||
self::assertFalse(PluginSettings::isValidBase('ABCDEFGHIJKLMNO$Pijklm%nop#qrs@tu&vxwyz12345')); | ||
} | ||
|
||
public function testIsValidLenght(): void | ||
{ | ||
self::assertTrue(PluginSettings::isValidLenght(20)); | ||
} | ||
|
||
public function testIsNotValidLenght(): void | ||
{ | ||
self::assertFalse(PluginSettings::isValidLenght(2)); | ||
} | ||
} |