|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\XMLSchema\Type; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DependsOnClass}; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use SimpleSAML\XML\Constants as C; |
| 10 | +use SimpleSAML\XML\Type\SpaceValue; |
| 11 | +use SimpleSAML\XML\XML\xml\SpaceEnum; |
| 12 | +use SimpleSAML\XMLSchema\Exception\SchemaViolationException; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class \SimpleSAML\Test\XML\Type\SpaceValueTest |
| 16 | + * |
| 17 | + * @package simplesamlphp/xml-common |
| 18 | + */ |
| 19 | +#[CoversClass(SpaceValue::class)] |
| 20 | +final class SpaceValueTest extends TestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @param string $space |
| 24 | + * @param bool $shouldPass |
| 25 | + */ |
| 26 | + #[DataProvider('provideSpace')] |
| 27 | + public function testSpaceValue(string $space, bool $shouldPass): void |
| 28 | + { |
| 29 | + try { |
| 30 | + SpaceValue::fromString($space); |
| 31 | + $this->assertTrue($shouldPass); |
| 32 | + } catch (SchemaViolationException $e) { |
| 33 | + $this->assertFalse($shouldPass); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * Test helpers |
| 40 | + */ |
| 41 | + public function testHelpers(): void |
| 42 | + { |
| 43 | + $lang = SpaceValue::fromString('default'); |
| 44 | + $attr = $lang->toAttribute(); |
| 45 | + |
| 46 | + $this->assertEquals($attr->getNamespaceURI(), C::NS_XML); |
| 47 | + $this->assertEquals($attr->getNamespacePrefix(), 'xml'); |
| 48 | + $this->assertEquals($attr->getAttrName(), 'space'); |
| 49 | + $this->assertEquals($attr->getAttrValue(), 'default'); |
| 50 | + |
| 51 | + // |
| 52 | + $x = SpaceValue::fromEnum(SpaceEnum::Default); |
| 53 | + $this->assertEquals(SpaceEnum::Default, $x->toEnum()); |
| 54 | + |
| 55 | + $y = SpaceValue::fromString('default'); |
| 56 | + $this->assertEquals(SpaceEnum::Default, $y->toEnum()); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * @return array<string, array{0: string, 1: bool}> |
| 62 | + */ |
| 63 | + public static function provideSpace(): array |
| 64 | + { |
| 65 | + return [ |
| 66 | + 'default' => ['default', true], |
| 67 | + 'preserve' => ['preserve', true], |
| 68 | + 'undefined' => ['undefined', false], |
| 69 | + 'empty' => ['', false], |
| 70 | + ]; |
| 71 | + } |
| 72 | +} |
0 commit comments