Skip to content

Commit

Permalink
update test to check all directives
Browse files Browse the repository at this point in the history
Signed-off-by: Tonko Mulder <[email protected]>
  • Loading branch information
Treggats committed Oct 26, 2024
1 parent 5ea6b94 commit 4d81967
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions tests/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

namespace Mazedlx\FeaturePolicy\Tests;

use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Mazedlx\FeaturePolicy\Directive;
use Mazedlx\FeaturePolicy\Exceptions\UnsupportedPermissionException;
use Mazedlx\FeaturePolicy\Value;
use ReflectionClass;

final class DirectiveTest extends TestCase
{
#[Test]
public function it_can_make_an_directive_from_name(): void
#[DataProvider('provide_directives')]
public function it_can_make_an_directive_from_name(string $constant, string $value): void
{
$directive = Directive::make(Directive::GEOLOCATION);
$directive = Directive::make($value);

$this->assertSame(Directive::GEOLOCATION, $directive->name());
$this->assertSame(constant(Directive::class . '::' . $constant), $directive->name());
$this->assertSame($value, $directive->name());
$this->assertIsArray($directive->rules());
$this->assertEmpty($directive->rules());
}
Expand Down Expand Up @@ -44,6 +49,21 @@ public function xr_spatial_tracking_adds_the_correct_header_directive_instead_of
$this->assertSame(Directive::XR_SPATIAL_TRACKING, $directive->name());
}

public static function provide_directives(): Generator
{
$directiveClass = new ReflectionClass(Directive::class);
$constants = array_filter($directiveClass->getConstants(), static function ($constant) {
return ! in_array($constant, [Directive::VR, Directive::XR, Directive::XR_SPATIAL_TRACKING], strict: true);
});

foreach ($constants as $const => $constantValue) {
yield $const => [
$const,
$constantValue,
];
}
}

#[Test]
public function floc_is_disabled_by_default()
{
Expand Down

0 comments on commit 4d81967

Please sign in to comment.