From 8b605c8ddb7bd245d9133c1c67b87cbaef6e1726 Mon Sep 17 00:00:00 2001 From: turegjorup Date: Fri, 25 Oct 2024 08:28:03 +0200 Subject: [PATCH] Added test case --- tests/Api/ScreensTest.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/Api/ScreensTest.php b/tests/Api/ScreensTest.php index 19c3e9e4..65d5271b 100644 --- a/tests/Api/ScreensTest.php +++ b/tests/Api/ScreensTest.php @@ -7,12 +7,27 @@ use App\Entity\ScreenLayout; use App\Entity\ScreenLayoutRegions; use App\Entity\Tenant\Playlist; +use App\Entity\Tenant\PlaylistScreenRegion; use App\Entity\Tenant\Screen; use App\Entity\Tenant\ScreenGroup; use App\Tests\AbstractBaseApiTestCase; +use Doctrine\ORM\EntityManager; class ScreensTest extends AbstractBaseApiTestCase { + private ?EntityManager $entityManager; + + protected function setUp(): void + { + parent::setUp(); + + $kernel = self::bootKernel(); + + $this->entityManager = $kernel->getContainer() + ->get('doctrine') + ->getManager(); + } + public function testGetCollection(): void { $response = $this->getAuthenticatedClient('ROLE_ADMIN')->request('GET', '/v2/screens?itemsPerPage=5', ['headers' => ['Content-Type' => 'application/ld+json']]); @@ -168,12 +183,21 @@ public function testCreateInvalidScreen(): void public function testUpdateScreen(): void { + $playlistScreenRegionRepository = $this->entityManager->getRepository(PlaylistScreenRegion::class); + $playlistScreenRegionCountBefore = $playlistScreenRegionRepository->count([]); + + $playlistIri = $this->findIriBy(Playlist::class, ['title' => 'playlist_abc_3']); + $playlistUlid = $this->iriHelperUtils->getUlidFromIRI($playlistIri); + $regionIri = $this->findIriBy(ScreenLayoutRegions::class, ['title' => 'full']); + $regionUlid = $this->iriHelperUtils->getUlidFromIRI($regionIri); + $client = $this->getAuthenticatedClient('ROLE_ADMIN'); - $iri = $this->findIriBy(Screen::class, ['tenant' => $this->tenant]); + $iri = $this->findIriBy(Screen::class, ['title' => 'screen_abc_1']); - $client->request('PUT', $iri, [ + $response = $client->request('PUT', $iri, [ 'json' => [ 'title' => 'Updated title', + 'regions' => [['playlists' => [['id' => $playlistUlid, 'weight' => 0]], 'regionId' => $regionUlid]], ], 'headers' => [ 'Content-Type' => 'application/ld+json', @@ -185,7 +209,10 @@ public function testUpdateScreen(): void '@type' => 'Screen', '@id' => $iri, 'title' => 'Updated title', + 'regions' => ['/v2/screens/'.$response->toArray()['id'].'/regions/'.$regionUlid.'/playlists'], ]); + $playlistScreenRegionCountAfter = $playlistScreenRegionRepository->count([]); + $this->assertEquals($playlistScreenRegionCountBefore, $playlistScreenRegionCountAfter, 'PlaylistScreenRegion count should not change'); } public function testDeleteScreen(): void