|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\XMLSchema\Type\Helper; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\Attributes\Group; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
| 12 | +use SimpleSAML\XMLSchema\Type\Helper\AnyURIListValue; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class \SimpleSAML\Test\XMLSchema\Type\Helper\AnyURIListTest |
| 16 | + * |
| 17 | + * @package simplesamlphp/xml-common |
| 18 | + */ |
| 19 | +#[Group('type')] |
| 20 | +#[CoversClass(AnyURIListValue::class)] |
| 21 | +final class AnyURIListValueTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @param boolean $shouldPass |
| 25 | + * @param string $anyURIList |
| 26 | + */ |
| 27 | + #[DataProvider('provideAnyURIList')] |
| 28 | + public function testAnyURIList(bool $shouldPass, string $anyURIList): void |
| 29 | + { |
| 30 | + try { |
| 31 | + AnyURIListValue::fromString($anyURIList); |
| 32 | + $this->assertTrue($shouldPass); |
| 33 | + } catch (SchemaViolationException $e) { |
| 34 | + $this->assertFalse($shouldPass); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + /** |
| 40 | + * Test the toArray function |
| 41 | + */ |
| 42 | + public function testToArray(): void |
| 43 | + { |
| 44 | + $anyURIList = AnyURIListValue::fromString("urn:x-simplesamlphp:namespace urn:x-ssp:ns"); |
| 45 | + $this->assertEquals(['urn:x-simplesamlphp:namespace', 'urn:x-ssp:ns'], $anyURIList->toArray()); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + /** |
| 50 | + * @return array<array{0: bool, 1: string}> |
| 51 | + */ |
| 52 | + public static function provideAnyURIList(): array |
| 53 | + { |
| 54 | + return [ |
| 55 | + 'single' => [true, "urn:x-simplesamlphp:namespace"], |
| 56 | + 'multiple' => [true, 'urn:x-simplesamlphp:namespace urn:x-ssp:ns'], |
| 57 | + 'normalization' => [true, "urn:x-simplesamlphp:namespace \n urn:x-ssp:ns"], |
| 58 | + 'empty' => [true, ''], |
| 59 | + ]; |
| 60 | + } |
| 61 | +} |
0 commit comments