|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\Controller\Admin; |
| 6 | + |
| 7 | +use App\Controller\Admin\SecurityContractCrudController; |
| 8 | +use App\Entity\Project; |
| 9 | +use App\Entity\SecurityContract; |
| 10 | +use App\Entity\User; |
| 11 | +use Doctrine\ORM\EntityManagerInterface; |
| 12 | +use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
| 13 | +use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; |
| 14 | +use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait; |
| 15 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * Service agreement amounts are Danish kroner, and the admin has to say so. |
| 19 | + * |
| 20 | + * The values come from Economics with no unit attached, and the CRUD has no |
| 21 | + * form pages — NEW and EDIT are disabled — so index and detail are the only |
| 22 | + * places a reader ever sees them. |
| 23 | + */ |
| 24 | +class SecurityContractCurrencyTest extends WebTestCase |
| 25 | +{ |
| 26 | + use RefreshDatabaseTrait; |
| 27 | + |
| 28 | + public function testAmountsRenderAsDanishKroner(): void |
| 29 | + { |
| 30 | + $client = static::createClient(); |
| 31 | + |
| 32 | + $entityManager = static::getContainer()->get(EntityManagerInterface::class); |
| 33 | + $client->loginUser($entityManager->getRepository(User::class)->findOneBy([])); |
| 34 | + |
| 35 | + $project = new Project(); |
| 36 | + $project->setEconomicsId(4711); |
| 37 | + $project->setName('Kroner probe'); |
| 38 | + |
| 39 | + $contract = new SecurityContract(); |
| 40 | + $contract->setEconomicsId(4711); |
| 41 | + $contract->setProject($project); |
| 42 | + $contract->setMonthlyPrice(12500.5); |
| 43 | + |
| 44 | + $entityManager->persist($project); |
| 45 | + $entityManager->persist($contract); |
| 46 | + $entityManager->flush(); |
| 47 | + |
| 48 | + $url = static::getContainer()->get(AdminUrlGenerator::class) |
| 49 | + ->setController(SecurityContractCrudController::class) |
| 50 | + ->setAction(Crud::PAGE_INDEX) |
| 51 | + ->generateUrl(); |
| 52 | + |
| 53 | + $client->request('GET', $url); |
| 54 | + |
| 55 | + $this->assertResponseIsSuccessful(); |
| 56 | + |
| 57 | + $content = (string) $client->getResponse()->getContent(); |
| 58 | + |
| 59 | + // Danish grouping and separator, not the application locale's 12,500.5. |
| 60 | + // Amount and unit are asserted apart because Intl joins them with a |
| 61 | + // non-breaking space. |
| 62 | + $this->assertStringContainsString('12.500,50', $content); |
| 63 | + $this->assertStringContainsString('kr.', $content); |
| 64 | + } |
| 65 | +} |
0 commit comments