first commit

This commit is contained in:
2025-07-18 16:20:14 +07:00
commit 98af45c018
16382 changed files with 3148096 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\DateTimeTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class DateTimeTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $dateTime
*/
#[DataProvider('provideDateTime')]
public function testValidDateTime(bool $shouldPass, string $dateTime): void
{
try {
Assert::validDateTime($dateTime);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideDateTime(): array
{
return [
[true, '2001-10-26T21:32:52'],
[true, '2001-10-26T21:32:52+02:00'],
[true, '2001-10-26T19:32:52Z'],
[true, '2001-10-26T19:32:52+00:00'],
[true, '-2001-10-26T21:32:52'],
[true, '2001-10-26T21:32:52.12679'],
[false, '2001-10-26'],
[false, '2001-10-26T21:32'],
[false, '2001-10-26T25:32:52+02:00'],
[false, '01-10-26T21:32'],
];
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\DurationTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class DurationTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $duration
*/
#[DataProvider('provideDuration')]
public function testValidDuration(bool $shouldPass, string $duration): void
{
try {
Assert::validDuration($duration);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideDuration(): array
{
return [
[true, 'P2Y6M5DT12H35M30S'],
[true, 'P1DT2H'],
[true, 'P1W'],
[true, 'P20M'],
[true, 'PT20M'],
[true, 'P0Y20M0D'],
[true, 'P0Y'],
[true, '-P60D'],
[true, 'PT1M30.5S'],
[true, 'P15.5Y'],
[true, 'P15,5Y'],
[false, 'P-20M'],
[false, 'P20MT'],
[false, 'P1YM5D'],
[false, 'P1D2H'],
[false, '1Y2M'],
[false, 'P2M1Y'],
[false, 'P'],
[false, 'PT15.S'],
// Trailing newlines are forbidden
[false, "P20M\n"],
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\Assert\HexBinaryTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class HexBinaryTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $name
*/
#[DataProvider('provideHexBinary')]
public function testHexBinary(bool $shouldPass, string $name): void
{
try {
Assert::validHexBinary($name);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<string, array{0: bool, 1: string}>
*/
public static function provideHexBinary(): array
{
return [
'empty' => [false, ''],
'base64' => [false, 'U2ltcGxlU0FNTHBocA=='],
'valid' => [true, '3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f'],
'invalid' => [false, '3f3r'],
'bogus' => [false, '&*$(#&^@!(^%$'],
'length not dividable by 4' => [false, '3f3'],
];
}
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\NCNameTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class NCNameTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $name
*/
#[DataProvider('provideNCName')]
public function testValidNCName(bool $shouldPass, string $name): void
{
try {
Assert::validNCName($name);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideNCName(): array
{
return [
[true, 'Test'],
[true, '_Test'],
// Prefixed v4 UUID
[true, '_5425e58e-e799-4884-92cc-ca64ecede32f'],
// An empty value is not valid, unless xsi:nil is used
[false, ''],
[false, 'Te*st'],
[false, '1Test'],
[false, 'Te:st'],
// Trailing newlines are forbidden
[false, "Test\n"],
];
}
}

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\NMTokenTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class NMTokenTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $nmtoken
*/
#[DataProvider('provideNMToken')]
public function testValidToken(bool $shouldPass, string $nmtoken): void
{
try {
Assert::validNMToken($nmtoken);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideNMToken(): array
{
return [
[true, 'Snoopy'],
[true, 'CMS'],
[true, 'fööbár'],
[true, '1950-10-04'],
[true, '0836217462'],
// Spaces are forbidden
[false, 'foo bar'],
// Commas are forbidden
[false, 'foo,bar'],
// Trailing newlines are forbidden
[false, "foobar\n"],
];
}
}

View File

@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\NMTokensTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class NMTokensTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $nmtokens
*/
#[DataProvider('provideNMTokens')]
public function testValidTokens(bool $shouldPass, string $nmtokens): void
{
try {
Assert::validNMTokens($nmtokens);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideNMTokens(): array
{
return [
[true, 'Snoopy'],
[true, 'CMS'],
[true, 'fööbár'],
[true, '1950-10-04'],
[true, '0836217462 0836217463'],
[true, 'foo bar'],
// Quotes are forbidden
[false, 'foo "bar" baz'],
// Commas are forbidden
[false, 'foo,bar'],
// Trailing newlines are forbidden
[false, "foobar\n"],
];
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\QNameTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class QNameTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $name
*/
#[DataProvider('provideQName')]
public function testValidQName(bool $shouldPass, string $name): void
{
try {
Assert::validQName($name);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<int, array{0: bool, 1: string}>
*/
public static function provideQName(): array
{
return [
[true, 'some:Test'],
[true, 'some:_Test'],
[true, '_some:_Test'],
[true, 'Test'],
// Cannot start with a colon
[false, ':test'],
// Cannot contain multiple colons
[false, 'test:test:test'],
// Cannot start with a number
[false, '1Test'],
// Cannot contain a wildcard character
[false, 'Te*st'],
// Prefixed newlines are forbidden
[false, "\nsome:Test"],
// Trailing newlines are forbidden
[false, "some:Test\n"],
];
}
}