futtern/tests/Controller/MenuItemControllerTest.php
Continuous Integration ee5d515ac1
All checks were successful
/ ls (push) Successful in 2m17s
/ ls (release) Successful in 54s
Continuous Integration Fixes
2024-09-23 17:11:33 +00:00

113 lines
3.2 KiB
PHP

<?php declare(strict_types=1);
namespace App\Tests\Controller;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Tests\DbWebTest;
use Override;
use function sprintf;
final class MenuItemControllerTest extends DbWebTest
{
private string $path = '/menu/item/';
private FoodVendor $vendor;
#[Override]
public function setUp(): void
{
parent::setUp();
$this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor');
$this->manager->persist($this->vendor);
$this->manager->flush();
}
#[Override]
public function getEntityClass(): string
{
return MenuItem::class;
}
public function testShow(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}{$menuItem->getId()}");
$idValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
)->text();
$nameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)'
)->text();
self::assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $menuItem->getId());
$this->assertEquals($nameValue, $menuItem->getName());
}
public function testEdit(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$this->manager->flush();
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$this->client->submitForm('Update', [
'menu_item[name]' => 'Testing-1',
]);
self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId()));
}
public function testDelete(): void
{
$menuItem = new MenuItem;
$menuItem->setName('Testing 1 2');
$this->vendor->addMenuItem($menuItem);
$this->manager->persist($this->vendor);
$this->manager->persist($menuItem);
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($menuItem->getId());
$this->assertTrue($menuItem->isDeleted());
$crawler = $this->client->request('GET', '/order/item/new/' . $order->getId());
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
->children()
->count();
$this->assertSame(0, $count);
$this->assertResponseIsSuccessful();
}
}