-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assertions for xs:NMTOKEN and xs:NMTOKENS
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 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
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,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\Assert; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\Assert\AssertionFailedException; | ||
|
||
/** | ||
* Class \SimpleSAML\Assert\NMTokenTest | ||
* | ||
* @package simplesamlphp/assert | ||
*/ | ||
#[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'], | ||
]; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\Assert; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\Assert\AssertionFailedException; | ||
|
||
/** | ||
* Class \SimpleSAML\Assert\NMTokensTest | ||
* | ||
* @package simplesamlphp/assert | ||
*/ | ||
#[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'], | ||
]; | ||
} | ||
} |