feat: rename admin screen, allow deleting a resource
This commit is contained in:
1 parent
dc1822b8cf
commit
5e5bf00f8f
7 files changed
+197
-9
No files matched your search
@@ -5,10 +5,13 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Controller\Admin;
|
||||
|
||||
use App\Entity\Booking;
|
||||
use App\Entity\BookingSeries;
|
||||
use App\Entity\Resource;
|
||||
use App\Entity\ResourceGroup;
|
||||
use App\Entity\User;
|
||||
use App\Enum\RecurrenceRule;
|
||||
use App\Enum\ResourceType;
|
||||
use App\Model\TimeRange;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
@@ -224,6 +227,67 @@ class ResourceAdminControllerTest extends WebTestCase
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
public function testAnEmployeeCannotDeleteAResource(): void
|
||||
{
|
||||
$desk = $this->resource('Schreibtisch 01');
|
||||
$this->client->loginUser($this->user('[email protected]'));
|
||||
|
||||
$this->client->request('POST', \sprintf('/admin/resources/%d/delete', $desk->getId()), ['_token' => 'whatever'], server: ['HTTP_HX-Request' => 'true']);
|
||||
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
||||
self::assertNotNull($this->reload($desk));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike retiring, deleting takes the bookings and series with it -- the foreign keys would
|
||||
* refuse otherwise -- and the confirmation says how many go.
|
||||
*/
|
||||
public function testDeletingAResourceTakesItsBookingsWithIt(): void
|
||||
{
|
||||
$desk = $this->resource('Schreibtisch 01');
|
||||
$other = $this->resource('Schreibtisch 02');
|
||||
$bea = $this->user('[email protected]');
|
||||
$series = new BookingSeries($bea, $desk, RecurrenceRule::DAILY, new \DateTimeImmutable('+1 day'), new \DateTimeImmutable('+2 days'), TimeRange::wholeDay());
|
||||
$this->em->persist($series);
|
||||
foreach ($series->occurrences() as $day) {
|
||||
$this->em->persist(new Booking($bea, $desk, $day, series: $series));
|
||||
}
|
||||
$this->em->persist(new Booking($bea, $desk, new \DateTimeImmutable('-3 days')));
|
||||
$this->em->persist(new Booking($bea, $other, new \DateTimeImmutable('+1 day')));
|
||||
$this->em->flush();
|
||||
$deskId = $desk->getId();
|
||||
$this->client->loginUser($this->admin());
|
||||
$uri = \sprintf('/admin/resources/%d/delete', $deskId);
|
||||
|
||||
$crawler = $this->client->request('GET', '/admin/resources');
|
||||
self::assertCount(1, $crawler->filter(\sprintf('[hx-get="%s"]', $uri)));
|
||||
|
||||
$modal = $this->client->request('GET', $uri, server: ['HTTP_HX-Request' => 'true']);
|
||||
self::assertStringContainsString('2 Buchungen ab heute und 1 vergangene', $modal->filter('[data-booking-count]')->text());
|
||||
|
||||
$this->client->request('POST', $uri, ['_token' => $this->confirmationToken($uri)], server: ['HTTP_HX-Request' => 'true']);
|
||||
|
||||
self::assertSame('/admin/resources', $this->client->getResponse()->headers->get('HX-Redirect'));
|
||||
$this->em->clear();
|
||||
self::assertNull($this->em->find(Resource::class, $deskId));
|
||||
self::assertCount(0, $this->em->getRepository(BookingSeries::class)->findAll());
|
||||
$remaining = $this->em->getRepository(Booking::class)->findAll();
|
||||
self::assertCount(1, $remaining);
|
||||
self::assertSame($other->getId(), $remaining[0]->getResource()->getId());
|
||||
}
|
||||
|
||||
public function testDeletingAResourceNeedsAValidToken(): void
|
||||
{
|
||||
$desk = $this->resource('Schreibtisch 01');
|
||||
$this->client->loginUser($this->admin());
|
||||
|
||||
$this->client->request('POST', \sprintf('/admin/resources/%d/delete', $desk->getId()), ['_token' => 'whatever'], server: ['HTTP_HX-Request' => 'true']);
|
||||
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
|
||||
$this->em->clear();
|
||||
self::assertNotNull($this->em->find(Resource::class, $desk->getId()));
|
||||
}
|
||||
|
||||
public function testTheDashboardLinksHereForAdminsOnly(): void
|
||||
{
|
||||
$this->client->loginUser($this->user('[email protected]'));
|
||||
|
||||
Reference in new issue
Block a user