#37 add external link to foodvendor
This commit is contained in:
parent
34171d6c2b
commit
56206acd8a
6 changed files with 79 additions and 4 deletions
35
migrations/Version20240816193410.php
Normal file
35
migrations/Version20240816193410.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20240816193410 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE food_vendor ADD COLUMN menu_link VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, id FROM food_vendor');
|
||||
$this->addSql('DROP TABLE food_vendor');
|
||||
$this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, id BLOB NOT NULL, PRIMARY KEY(id))');
|
||||
$this->addSql('INSERT INTO food_vendor (name, id) SELECT name, id FROM __temp__food_vendor');
|
||||
$this->addSql('DROP TABLE __temp__food_vendor');
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@ class FoodVendor
|
|||
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'foodVendor', orphanRemoval: true)]
|
||||
private Collection $menuItems;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private string|null $menuLink = null;
|
||||
|
||||
public function __construct(
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
|
||||
|
@ -116,4 +119,16 @@ class FoodVendor
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMenuLink(): string|null
|
||||
{
|
||||
return $this->menuLink;
|
||||
}
|
||||
|
||||
public function setMenuLink(string|null $menuLink): static
|
||||
{
|
||||
$this->menuLink = $menuLink;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ final class FoodVendorType extends AbstractType
|
|||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('menuLink')
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
<th>Name</th>
|
||||
<td>{{ food_vendor.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Menu</th>
|
||||
<td><a href="{{ food_vendor.menuLink }}" target="_blank">{{ food_vendor.menuLink }}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
|
||||
{{ include('order_item/_form.html.twig') }}
|
||||
|
||||
<hr />
|
||||
|
||||
{% if food_order.foodVendor.menuLink != '' %}
|
||||
<a href="{{ food_order.foodVendor.menuLink }}" target="_blank">
|
||||
External link to Menu
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<b>click a button to select a given menuitem</b>
|
||||
</div>
|
||||
|
|
|
@ -38,6 +38,7 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
{
|
||||
$fixture = new FoodVendor;
|
||||
$fixture->setName('My Title');
|
||||
$fixture->setMenuLink('https://example.com/');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
@ -45,9 +46,17 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$nameNode = $crawler->filter('td')
|
||||
->last();
|
||||
$this->assertSame('My Title', $nameNode->text());
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testShowMenuItems(): void
|
||||
|
@ -91,9 +100,10 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
$crawler = $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$nameNode = $crawler->filter('td')
|
||||
->last();
|
||||
$this->assertSame('My Title', $nameNode->text());
|
||||
$nameNode = $crawler->filter(
|
||||
'.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
|
||||
)->text();
|
||||
$this->assertSame('My Title', $nameNode);
|
||||
|
||||
$itemNodes = $crawler->filter('li');
|
||||
|
||||
|
@ -112,6 +122,7 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
|
||||
$this->client->submitForm('Update', [
|
||||
'food_vendor[name]' => 'Something New',
|
||||
'food_vendor[menuLink]' => 'https://example.com/',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/food/vendor/');
|
||||
|
@ -119,6 +130,7 @@ final class FoodVendorControllerTest extends DbWebTest
|
|||
$fixture = $this->repository->findAll();
|
||||
|
||||
self::assertSame('Something New', $fixture[0]->getName());
|
||||
self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
|
||||
}
|
||||
|
||||
#[Override]
|
||||
|
|
Loading…
Reference in a new issue