Skip to content

add simple test cases #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: phpunit

on: [push]

jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- uses: php-actions/phpunit@v3
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# intentionally malformed files
# pre-commit automatically excludes submodules
exclude: |
(?x)^(
.*\.dist|
roles/ood-head/files/auto-copy/var/www/ood/apps/common/common_attributes.yml|
roles/ood-head/files/auto-copy/var/www/ood/apps/sys/dashboard/config/locales/en.yml|
inventory.d/ipv4.py|
files/shibboleth/filtered-incommon-metadata.xml.j2|
)$
repos:
# auto formatters (no work required) #############################################################
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v5.0.0
# hooks:
# - id: trailing-whitespace
# - id: end-of-file-fixer
- repo: local
hooks:
- id: phpcbf
name: PHP Code Beautifier and Fixer
entry: phpcbf
language: system
files: \.php$
args: [--standard=PSR2, --colors]

# linters (work required) ########################################################################
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v5.0.0
# hooks:
# - id: check-yaml
# - id: check-json
# - id: check-xml
# - id: check-added-large-files
# - id: check-executables-have-shebangs
# - repo: https://github.com/gitleaks/gitleaks
# rev: v8.23.1
# hooks:
# - id: gitleaks
- repo: local
hooks:
- id: phpcs
name: PHP CodeSniffer
entry: phpcs
language: system
files: \.php$
args: [--standard=PSR2, --colors]
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<phpunit
bootstrap="test/unit/bootstrap.php"
failOnWarning="true"
failOnDeprecation="true"
failOnNotice="true"
restrictWarnings="true"
>
<testsuites>
<testsuite name="unit">
<directory>test/unit</directory>
</testsuite>
</testsuites>
</phpunit>
18 changes: 8 additions & 10 deletions resources/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* init.php - Initialization script that is run on every page of Unity
*/

use UnityWebPortal\lib\{
UnityConfig,
UnityLDAP,
UnityMailer,
UnitySQL,
UnitySSO,
UnityUser,
UnityRedis,
UnityWebhook
};
use UnityWebPortal\lib\UnityConfig;
use UnityWebPortal\lib\UnityLDAP;
use UnityWebPortal\lib\UnityMailer;
use UnityWebPortal\lib\UnitySQL;
use UnityWebPortal\lib\UnitySSO;
use UnityWebPortal\lib\UnityUser;
use UnityWebPortal\lib\UnityRedis;
use UnityWebPortal\lib\UnityWebhook;

//
// Initialize Session
Expand Down
32 changes: 32 additions & 0 deletions test/unit/UnitySiteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace UnityWebPortal\lib;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class UnitySiteTest extends TestCase
{
public static function SSHKeyProvider()
{
return [
[false, ""],
[false, "foobar"],
[false, "1"],
[false, '{"key": "value"}'],
[true, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a"],
[true, " ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a "],
//phpcs:disable
[true, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJNqo8NKTfXgCsaE3ly0tDCfwFuFgJiftup0bIZnRi5b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L5djQYRit2druxBtw6Y+ylIg9CZJMTf1IBjveBUySF+gOonShB1nLmRZ9zX2hwJSXqYbGQCqzfwRWwPYSnQak0skh4J1p7OYFgZCuxkiSaEikpbuHJWAz1cpYsomXQ7l/m+F05JFfAm2LvNjVoeAblw+Tj7T/Fx7x63b1CU4Wy3L7Ho25i89fksFhsV/fBk9c3QqSkwpkiDVnvYeIhM349An75ncfBjToQT5o5Ayn0ritOUHh5NW+SS+955CFFM8ZQhxZaluWKcrvjwN/UCtBWjGTu7JpwOnHuTTj03ti2wcYsEKNpPB/Nm3kql+UbARmsq24j5foxjN6gmiKVtuho7SDMsu11UGgidKCiHAM3/o4Im53awfRJiqoouJNTisSuhxHp7b+4Z14+CUPfQcKkyYCSzrptrJhg2FO5vz1YZOuExIm3deDfcPsK5vg4LiLam6FJ3qqonXP6krCuH/crJYLTPBJn6eX3noL7TjCqiMWEtLmGj0431YbcrgG7Fy2a+VWwcB6w0nzyxbqg16AP+luuqHxfVsvP6Uyde4C7LPeB3r3GhAfuUNxnpz/bXGxbJu3+aCnbtaZMzGJ6UFBeJp8MtlmVajDnjx3oEuOGGmobTlaopHYVsQ3ySfQ=="],
//phpcs:enable
];
}

#[DataProvider("SSHKeyProvider")]
public function testTestValidSSHKey(bool $expected, string $key)
{
$SITE = new UnitySite();
$this->assertEquals($expected, $SITE->testValidSSHKey($key));
}
}
15 changes: 15 additions & 0 deletions test/unit/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once __DIR__ . "/../../vendor/autoload.php";

require_once __DIR__ . "/../../resources/lib/UnityLDAP.php";
require_once __DIR__ . "/../../resources/lib/UnityUser.php";
require_once __DIR__ . "/../../resources/lib/UnityGroup.php";
require_once __DIR__ . "/../../resources/lib/UnityOrg.php";
require_once __DIR__ . "/../../resources/lib/UnitySQL.php";
require_once __DIR__ . "/../../resources/lib/UnityMailer.php";
require_once __DIR__ . "/../../resources/lib/UnitySSO.php";
require_once __DIR__ . "/../../resources/lib/UnitySite.php";
require_once __DIR__ . "/../../resources/lib/UnityConfig.php";
require_once __DIR__ . "/../../resources/lib/UnityWebhook.php";
require_once __DIR__ . "/../../resources/lib/UnityRedis.php";
6 changes: 2 additions & 4 deletions webroot/panel/new_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

require_once "../../resources/autoload.php";

use UnityWebPortal\lib\{
UnitySite,
UnityGroup
};
use UnityWebPortal\lib\UnitySite;
use UnityWebPortal\lib\UnityGroup;

require_once $LOC_HEADER;

Expand Down
Loading