2024-06-10 20:23:36 +02:00
|
|
|
<?php declare(strict_types=1);
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
namespace App\Tests\Feature\Controller;
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 00:09:50 +01:00
|
|
|
use App\Controller\FoodVendorController;
|
|
|
|
use App\Entity\FoodOrder;
|
2024-06-10 20:22:44 +02:00
|
|
|
use App\Entity\FoodVendor;
|
2024-07-17 21:16:44 +02:00
|
|
|
use App\Entity\MenuItem;
|
2025-02-01 00:09:50 +01:00
|
|
|
use App\Entity\OrderItem;
|
|
|
|
use App\Form\FoodOrderType;
|
|
|
|
use App\Form\FoodVendorType;
|
|
|
|
use App\Repository\FoodOrderRepository;
|
|
|
|
use App\Repository\FoodVendorRepository;
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
use function describe;
|
|
|
|
use function pest;
|
2024-06-10 20:23:36 +02:00
|
|
|
use function sprintf;
|
2025-02-01 22:37:07 +01:00
|
|
|
use function test;
|
2024-06-10 20:23:36 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
pest()
|
|
|
|
->beforeEach(function (): void {
|
|
|
|
$this->setEntityClass(FoodVendor::class);
|
|
|
|
$this->setPath('/food/vendor/');
|
|
|
|
$this->repository = $this->manager->getRepository($this->entityClass);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(FoodVendorController::class, function (): void {
|
|
|
|
test('index', function (): void {
|
2024-06-10 20:23:36 +02:00
|
|
|
$this->client->request('GET', $this->path);
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
$this->assertResponseStatusCodeSame(200);
|
|
|
|
$this->assertPageTitleContains('FoodVendor index');
|
|
|
|
});
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
test('new', function (): void {
|
|
|
|
$this->assertSame(0, $this->repository->count([]));
|
2024-06-10 20:22:44 +02:00
|
|
|
$this->client->request('GET', sprintf('%snew', $this->path));
|
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
$this->assertResponseStatusCodeSame(200);
|
2024-06-10 20:22:44 +02:00
|
|
|
|
|
|
|
$this->client->submitForm('Save', [
|
2025-01-26 11:48:16 +01:00
|
|
|
'food_vendor[name]' => 'TestingNew',
|
2024-06-10 20:22:44 +02:00
|
|
|
]);
|
|
|
|
|
2025-01-26 10:50:50 +00:00
|
|
|
$newVendor = $this->repository->findOneBy([
|
|
|
|
'name' => 'TestingNew',
|
|
|
|
]);
|
2025-01-26 11:48:16 +01:00
|
|
|
$this->assertInstanceof(FoodVendor::class, $newVendor);
|
2025-02-01 22:37:07 +01:00
|
|
|
$this->assertSame(1, $this->repository->count([]));
|
2025-01-26 11:48:16 +01:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
});
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
test('show', function (): void {
|
2024-06-10 20:23:36 +02:00
|
|
|
$fixture = new FoodVendor;
|
2024-06-10 20:22:44 +02:00
|
|
|
$fixture->setName('My Title');
|
2024-08-16 21:52:53 +02:00
|
|
|
$fixture->setMenuLink('https://example.com/');
|
2024-06-10 20:22:44 +02:00
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
$this->manager->flush();
|
|
|
|
|
2024-06-14 20:21:16 +02:00
|
|
|
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2024-06-14 20:21:16 +02:00
|
|
|
$this->assertResponseIsSuccessful();
|
2024-08-16 21:52:53 +02:00
|
|
|
|
2024-06-14 20:21:16 +02:00
|
|
|
$nameNode = $crawler->filter('td')
|
|
|
|
->last();
|
2024-08-16 21:52:53 +02:00
|
|
|
$nameNode = $crawler->filter(
|
|
|
|
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
|
|
|
)->text();
|
|
|
|
$menuLinkNode = $crawler->filter(
|
|
|
|
'.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2) > a:nth-child(1)'
|
|
|
|
)->text();
|
|
|
|
$this->assertSame('My Title', $nameNode);
|
|
|
|
$this->assertSame('https://example.com/', $menuLinkNode);
|
2025-02-01 22:37:07 +01:00
|
|
|
});
|
2024-06-10 20:22:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
test('show with menu items', function (): void {
|
2024-07-17 21:16:44 +02:00
|
|
|
$fixture = new FoodVendor;
|
|
|
|
$fixture->setName('My Title');
|
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
|
|
|
|
$this->manager->flush();
|
|
|
|
|
|
|
|
$itemOne = new MenuItem;
|
|
|
|
$itemOne->setName('Item One');
|
|
|
|
|
|
|
|
$fixture->addMenuItem($itemOne);
|
|
|
|
$this->manager->persist($itemOne);
|
|
|
|
|
|
|
|
$itemTwo = new MenuItem;
|
|
|
|
$itemTwo->setName('Item Two');
|
|
|
|
$itemTwo->setFoodVendor($fixture);
|
|
|
|
|
|
|
|
$fixture->addMenuItem($itemTwo);
|
|
|
|
$this->manager->persist($itemTwo);
|
|
|
|
|
|
|
|
$itemThree = new MenuItem;
|
|
|
|
$itemThree->setName('Item Three');
|
|
|
|
$itemThree->setFoodVendor($fixture);
|
|
|
|
|
|
|
|
$fixture->addMenuItem($itemThree);
|
|
|
|
$this->manager->persist($itemThree);
|
|
|
|
|
|
|
|
$itemFour = new MenuItem;
|
|
|
|
$itemFour->setName('Item Four');
|
|
|
|
$itemFour->setFoodVendor($fixture);
|
|
|
|
|
|
|
|
$fixture->addMenuItem($itemFour);
|
|
|
|
$this->manager->persist($itemFour);
|
|
|
|
|
|
|
|
$this->manager->flush();
|
|
|
|
|
|
|
|
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
|
|
|
|
|
|
|
$this->assertResponseIsSuccessful();
|
2024-08-16 21:52:53 +02:00
|
|
|
$nameNode = $crawler->filter(
|
|
|
|
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
|
|
|
)->text();
|
|
|
|
$this->assertSame('My Title', $nameNode);
|
2024-07-17 21:16:44 +02:00
|
|
|
|
2024-07-29 13:04:57 +02:00
|
|
|
$itemNodes = $crawler->filter('li');
|
2024-07-17 21:16:44 +02:00
|
|
|
|
|
|
|
$this->assertCount(4, $itemNodes);
|
2025-02-01 22:37:07 +01:00
|
|
|
});
|
2024-07-17 21:16:44 +02:00
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
test('edit', function (): void {
|
2024-06-10 20:23:36 +02:00
|
|
|
$fixture = new FoodVendor;
|
2024-06-10 20:22:44 +02:00
|
|
|
$fixture->setName('Value');
|
2024-12-19 01:11:09 +01:00
|
|
|
$fixture->setMenuLink('Value');
|
|
|
|
$fixture->setPhone('Value');
|
2024-06-10 20:22:44 +02:00
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
$this->manager->flush();
|
|
|
|
|
2024-09-15 22:11:42 +02:00
|
|
|
$crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
|
|
|
$this->assertSame(
|
|
|
|
$crawler->filter('#food_vendor_name')
|
|
|
|
->last()
|
|
|
|
->attr('value', ''),
|
|
|
|
'Value'
|
|
|
|
);
|
2024-12-19 01:11:09 +01:00
|
|
|
$this->assertSame(
|
|
|
|
$crawler->filter('#food_vendor_menuLink')
|
|
|
|
->last()
|
|
|
|
->attr('value', ''),
|
|
|
|
'Value'
|
|
|
|
);
|
|
|
|
$this->assertSame(
|
|
|
|
$crawler->filter('#food_vendor_phone')
|
|
|
|
->last()
|
|
|
|
->attr('value', ''),
|
|
|
|
'Value'
|
|
|
|
);
|
2024-06-10 20:22:44 +02:00
|
|
|
|
|
|
|
$this->client->submitForm('Update', [
|
|
|
|
'food_vendor[name]' => 'Something New',
|
2024-08-16 21:52:53 +02:00
|
|
|
'food_vendor[menuLink]' => 'https://example.com/',
|
2024-12-19 01:11:09 +01:00
|
|
|
'food_vendor[phone]' => '1234567890',
|
2024-06-10 20:22:44 +02:00
|
|
|
]);
|
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
$this->assertResponseRedirects('/food/vendor/');
|
2024-06-10 20:22:44 +02:00
|
|
|
|
|
|
|
$fixture = $this->repository->findAll();
|
|
|
|
|
2025-02-01 22:37:07 +01:00
|
|
|
$this->assertSame('Something New', $fixture[0]->getName());
|
|
|
|
$this->assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
|
|
|
$this->assertSame('1234567890', $fixture[0]->getPhone());
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
->covers(
|
|
|
|
FoodOrder::class,
|
|
|
|
FoodVendor::class,
|
|
|
|
FoodOrderRepository::class,
|
|
|
|
MenuItem::class,
|
|
|
|
OrderItem::class,
|
|
|
|
FoodOrderType::class,
|
|
|
|
FoodVendorRepository::class,
|
|
|
|
FoodVendorController::class,
|
|
|
|
FoodVendorType::class
|
|
|
|
)
|
|
|
|
|
|
|
|
;
|