add price feature
All checks were successful
/ ls (pull_request) Successful in 1m37s

This commit is contained in:
lubiana 2025-06-29 23:18:23 +02:00
parent 15f8db46a0
commit 64f5341371
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
18 changed files with 484 additions and 157 deletions

View file

@ -13,7 +13,8 @@ use App\Form\OrderItemType;
use App\Repository\FoodOrderRepository;
use App\Repository\MenuItemRepository;
use function describe;
use function covers;
use function it;
use function pest;
use function sprintf;
use function test;
@ -55,105 +56,105 @@ pest()
$this->manager->flush();
});
covers(
MenuItemController::class,
OrderItemController::class,
OrderItemType::class,
MenuItemRepository::class,
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
MenuItemType::class,
);
describe(MenuItemController::class, function (): void {
test('show', function (): void {
it('show', function (): void {
$crawler = $this->client->request('GET', "{$this->path}{$this->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();
$crawler = $this->client->request('GET', "{$this->path}{$this->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();
$aliasTwoNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(1)'
)->text();
$aliasOneNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(2)'
)->text();
$this->assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $this->menuItem->getId());
$this->assertEquals($nameValue, $this->menuItem->getName());
$this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName());
$this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName());
});
$aliasTwoNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(1)'
)->text();
$aliasOneNameValue = $crawler->filter(
'.table > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(2)'
)->text();
$this->assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $this->menuItem->getId());
$this->assertEquals($nameValue, $this->menuItem->getName());
$this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName());
$this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName());
});
test('edit', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'Testing-1';
$form['menu_item[aliases]'][0]->untick();
$this->client->submit($form);
$this->assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
$menuItem = $this->repository->find($this->menuItem->getId());
$this->assertEquals('Testing-1', $menuItem->getName());
$this->assertEquals(1, $menuItem->getAliases()->count());
$aliasOne = $this->repository->find($this->aliasOne->getId());
$this->assertNull($aliasOne->getAliasOf());
});
test('edit invalid', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'a';
$this->client->submit($form);
$this->assertResponseStatusCodeSame(422);
});
test('delete', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($this->menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($this->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(2, $count);
$this->assertResponseIsSuccessful();
});
})
->covers(
MenuItemController::class,
OrderItemController::class,
OrderItemType::class,
MenuItemRepository::class,
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
MenuItemType::class,
test('edit', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'Testing-1';
$form['menu_item[priceCents]'] = '1.23';
$form['menu_item[aliases]'][0]->untick();
$this->client->submit($form);
$this->assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId()));
$menuItem = $this->repository->find($this->menuItem->getId());
$this->assertEquals('Testing-1', $menuItem->getName());
$this->assertEquals(123, $menuItem->getPriceCents());
$this->assertEquals(1, $menuItem->getAliases()->count());
$aliasOne = $this->repository->find($this->aliasOne->getId());
$this->assertNull($aliasOne->getAliasOf());
});
test('edit invalid', function (): void {
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$form = $crawler->selectButton('Update')
->form();
$form['menu_item[name]'] = 'a';
$this->client->submit($form);
$this->assertResponseStatusCodeSame(422);
});
test('delete', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($this->menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($this->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(2, $count);
$this->assertResponseIsSuccessful();
});