|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\XML\Assert; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use SimpleSAML\Assert\AssertionFailedException; |
| 11 | +use SimpleSAML\XML\Assert\Assert; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class \SimpleSAML\Test\XML\Assert\EntitiesTest |
| 15 | + * |
| 16 | + * @package simplesamlphp/xml-common |
| 17 | + */ |
| 18 | +#[CoversClass(Assert::class)] |
| 19 | +final class EntitiesTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @param boolean $shouldPass |
| 23 | + * @param string $entities |
| 24 | + */ |
| 25 | + #[DataProvider('provideEntities')] |
| 26 | + public function testValidEntities(bool $shouldPass, string $entities): void |
| 27 | + { |
| 28 | + try { |
| 29 | + Assert::validEntities($entities); |
| 30 | + $this->assertTrue($shouldPass); |
| 31 | + } catch (AssertionFailedException $e) { |
| 32 | + $this->assertFalse($shouldPass); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + |
| 37 | + /** |
| 38 | + * @return array<int, array{0: bool, 1: string}> |
| 39 | + */ |
| 40 | + public static function provideEntities(): array |
| 41 | + { |
| 42 | + return [ |
| 43 | + [true, 'Snoopy'], |
| 44 | + [true, 'CMS'], |
| 45 | + [true, 'fööbár'], |
| 46 | + [true, '-1950-10-04'], |
| 47 | + [false, '0836217462 0836217463'], |
| 48 | + [true, 'foo bar'], |
| 49 | + // Quotes are forbidden |
| 50 | + [false, 'foo "bar" baz'], |
| 51 | + // Commas are forbidden |
| 52 | + [false, 'foo,bar'], |
| 53 | + // Trailing newlines are forbidden |
| 54 | + [false, "foobar\n"], |
| 55 | + ]; |
| 56 | + } |
| 57 | +} |
0 commit comments