|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\XML\Type; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use SimpleSAML\Test\XML\Assert\IDTest; |
| 10 | +use SimpleSAML\XML\Constants as C; |
| 11 | +use SimpleSAML\XML\Type\IDValue; |
| 12 | +use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
| 13 | +use SimpleSAML\XMLSchema\Type\Builtin\{IDValue as BaseIDValue, StringValue}; |
| 14 | + |
| 15 | +/** |
| 16 | + * Class \SimpleSAML\Test\XML\Type\IDValueTest |
| 17 | + * |
| 18 | + * @package simplesamlphp/xml-common |
| 19 | + */ |
| 20 | +#[CoversClass(IDValue::class)] |
| 21 | +final class IDValueTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @param boolean $shouldPass |
| 25 | + * @param string $id |
| 26 | + */ |
| 27 | + #[DataProviderExternal(IDTest::class, 'provideValidID')] |
| 28 | + #[DependsOnClass(IDTest::class)] |
| 29 | + public function testID(bool $shouldPass, string $id): void |
| 30 | + { |
| 31 | + try { |
| 32 | + IDValue::fromString($id); |
| 33 | + $this->assertTrue($shouldPass); |
| 34 | + } catch (SchemaViolationException $e) { |
| 35 | + $this->assertFalse($shouldPass); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + /** |
| 41 | + * Test helpers |
| 42 | + */ |
| 43 | + public function testHelpers(): void |
| 44 | + { |
| 45 | + $id = IDValue::fromString('phpunit'); |
| 46 | + $attr = $id->toAttribute(); |
| 47 | + |
| 48 | + $this->assertEquals($attr->getNamespaceURI(), C::NS_XML); |
| 49 | + $this->assertEquals($attr->getNamespacePrefix(), 'xml'); |
| 50 | + $this->assertEquals($attr->getAttrName(), 'id'); |
| 51 | + $this->assertEquals($attr->getAttrValue(), 'phpunit'); |
| 52 | + } |
| 53 | +} |
0 commit comments