|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Acsiomatic\DeviceDetectorBundle\Tests; |
| 4 | + |
| 5 | +use Acsiomatic\DeviceDetectorBundle\AcsiomaticDeviceDetectorBundle; |
| 6 | +use Acsiomatic\DeviceDetectorBundle\Tests\Util\Compiler\CallbackContainerPass; |
| 7 | +use Acsiomatic\DeviceDetectorBundle\Tests\Util\HttpKernel\Kernel; |
| 8 | +use DeviceDetector\DeviceDetector; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
| 11 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 12 | + |
| 13 | +class RoutingConditionServiceTest extends TestCase |
| 14 | +{ |
| 15 | + public function testDeviceDetectorIsTaggedAsRoutingConditionService(): void |
| 16 | + { |
| 17 | + $kernel = new Kernel('test', true); |
| 18 | + $kernel->appendBundle(new FrameworkBundle()); |
| 19 | + $kernel->appendBundle(new AcsiomaticDeviceDetectorBundle()); |
| 20 | + $kernel->appendExtensionConfiguration('framework', ['test' => true, 'secret' => '53CR37']); |
| 21 | + $kernel->appendCompilerPass( |
| 22 | + new CallbackContainerPass( |
| 23 | + static function (ContainerBuilder $containerBuilder): void { |
| 24 | + self::assertTrue($containerBuilder->hasDefinition(DeviceDetector::class)); |
| 25 | + |
| 26 | + $definition = $containerBuilder->getDefinition(DeviceDetector::class); |
| 27 | + |
| 28 | + self::assertTrue($definition->hasTag('routing.condition_service')); |
| 29 | + self::assertSame([['alias' => 'device']], $definition->getTag('routing.condition_service')); |
| 30 | + } |
| 31 | + ) |
| 32 | + ); |
| 33 | + |
| 34 | + $kernel->boot(); |
| 35 | + } |
| 36 | + |
| 37 | + public function testHonorCustomAlias(): void |
| 38 | + { |
| 39 | + $kernel = new Kernel('test', true); |
| 40 | + $kernel->appendBundle(new FrameworkBundle()); |
| 41 | + $kernel->appendBundle(new AcsiomaticDeviceDetectorBundle()); |
| 42 | + $kernel->appendExtensionConfiguration('framework', ['test' => true, 'secret' => '53CR37']); |
| 43 | + $kernel->appendExtensionConfiguration('acsiomatic_device_detector', ['routing' => ['condition_service_alias' => 'custom']]); |
| 44 | + $kernel->appendCompilerPass( |
| 45 | + new CallbackContainerPass( |
| 46 | + static function (ContainerBuilder $containerBuilder): void { |
| 47 | + self::assertTrue($containerBuilder->hasDefinition(DeviceDetector::class)); |
| 48 | + |
| 49 | + $definition = $containerBuilder->getDefinition(DeviceDetector::class); |
| 50 | + |
| 51 | + self::assertTrue($definition->hasTag('routing.condition_service')); |
| 52 | + self::assertSame([['alias' => 'custom']], $definition->getTag('routing.condition_service')); |
| 53 | + } |
| 54 | + ) |
| 55 | + ); |
| 56 | + |
| 57 | + $kernel->boot(); |
| 58 | + } |
| 59 | + |
| 60 | + public function testDisabling(): void |
| 61 | + { |
| 62 | + $kernel = new Kernel('test', true); |
| 63 | + $kernel->appendBundle(new FrameworkBundle()); |
| 64 | + $kernel->appendBundle(new AcsiomaticDeviceDetectorBundle()); |
| 65 | + $kernel->appendExtensionConfiguration('framework', ['test' => true, 'secret' => '53CR37']); |
| 66 | + $kernel->appendExtensionConfiguration('acsiomatic_device_detector', ['routing' => ['condition_service_alias' => null]]); |
| 67 | + $kernel->appendCompilerPass( |
| 68 | + new CallbackContainerPass( |
| 69 | + static function (ContainerBuilder $containerBuilder): void { |
| 70 | + self::assertTrue($containerBuilder->hasDefinition(DeviceDetector::class)); |
| 71 | + self::assertFalse($containerBuilder->getDefinition(DeviceDetector::class)->hasTag('routing.condition_service')); |
| 72 | + } |
| 73 | + ) |
| 74 | + ); |
| 75 | + |
| 76 | + $kernel->boot(); |
| 77 | + } |
| 78 | +} |
0 commit comments