parent
541ec566d1
commit
b7a750604a
@ -0,0 +1,4 @@
|
||||
<form method="post" action="{{ path('app_post_delete', {'id': post.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ post.id) }}">
|
||||
<button class="btn">Delete</button>
|
||||
</form>
|
@ -0,0 +1,4 @@
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||
{{ form_end(form) }}
|
@ -1,11 +1,45 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Posts!{% endblock %}
|
||||
{% block title %}Post index{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{% for post in posts %}
|
||||
<div class="card">
|
||||
#{{ post.id }} trouvé le {{ post.foundDate | date("d/m/Y \\à H \\h") }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<h1>Post index</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>FoundDate</th>
|
||||
<th>PublicationDate</th>
|
||||
<th>Latitude</th>
|
||||
<th>Longitude</th>
|
||||
<th>Altitude</th>
|
||||
<th>Commentary</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for post in posts %}
|
||||
<tr>
|
||||
<td>{{ post.id }}</td>
|
||||
<td>{{ post.foundDate ? post.foundDate|date('Y-m-d H:i:s') : '' }}</td>
|
||||
<td>{{ post.publicationDate ? post.publicationDate|date('Y-m-d H:i:s') : '' }}</td>
|
||||
<td>{{ post.latitude }}</td>
|
||||
<td>{{ post.longitude }}</td>
|
||||
<td>{{ post.altitude }}</td>
|
||||
<td>{{ post.commentary }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_post_show', {'id': post.id}) }}">show</a>
|
||||
<a href="{{ path('app_post_edit', {'id': post.id}) }}">edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="8">no records found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_post_new') }}">Create new</a>
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}New Post{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Create new Post</h1>
|
||||
|
||||
{{ include('post/_form.html.twig') }}
|
||||
|
||||
<a href="{{ path('app_post_index') }}">back to list</a>
|
||||
{% endblock %}
|
@ -1,3 +0,0 @@
|
||||
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
|
||||
{{ form_widget(form) }}
|
||||
{{ form_end(form) }}
|
@ -0,0 +1,46 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Post{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Post</h1>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<td>{{ post.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>FoundDate</th>
|
||||
<td>{{ post.foundDate ? post.foundDate|date('Y-m-d H:i:s') : '' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>PublicationDate</th>
|
||||
<td>{{ post.publicationDate ? post.publicationDate|date('Y-m-d H:i:s') : '' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Latitude</th>
|
||||
<td>{{ post.latitude }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Longitude</th>
|
||||
<td>{{ post.longitude }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Altitude</th>
|
||||
<td>{{ post.altitude }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Commentary</th>
|
||||
<td>{{ post.commentary }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_post_index') }}">back to list</a>
|
||||
|
||||
<a href="{{ path('app_post_edit', {'id': post.id}) }}">edit</a>
|
||||
|
||||
{{ include('post/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
@ -0,0 +1,4 @@
|
||||
<form method="post" action="{{ path('app_species_delete', {'id': species.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ species.id) }}">
|
||||
<button class="btn">Delete</button>
|
||||
</form>
|
@ -0,0 +1,4 @@
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||
{{ form_end(form) }}
|
@ -0,0 +1,13 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit Species{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit Species</h1>
|
||||
|
||||
{{ include('species/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
|
||||
<a href="{{ path('app_species_index') }}">back to list</a>
|
||||
|
||||
{{ include('species/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
@ -0,0 +1,39 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Species index{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Species index</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Scientific_name</th>
|
||||
<th>Vernacular_name</th>
|
||||
<th>Region</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for species in species %}
|
||||
<tr>
|
||||
<td>{{ species.id }}</td>
|
||||
<td>{{ species.scientificName }}</td>
|
||||
<td>{{ species.vernacularName }}</td>
|
||||
<td>{{ species.region }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_species_show', {'id': species.id}) }}">show</a>
|
||||
<a href="{{ path('app_species_edit', {'id': species.id}) }}">edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="5">no records found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_species_new') }}">Create new</a>
|
||||
{% endblock %}
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}New Species{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Create new Species</h1>
|
||||
|
||||
{{ include('species/_form.html.twig') }}
|
||||
|
||||
<a href="{{ path('app_species_index') }}">back to list</a>
|
||||
{% endblock %}
|
@ -0,0 +1,34 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Species{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Species</h1>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<td>{{ species.id }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Scientific_name</th>
|
||||
<td>{{ species.scientificName }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Vernacular_name</th>
|
||||
<td>{{ species.vernacularName }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Region</th>
|
||||
<td>{{ species.region }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a href="{{ path('app_species_index') }}">back to list</a>
|
||||
|
||||
<a href="{{ path('app_species_edit', {'id': species.id}) }}">edit</a>
|
||||
|
||||
{{ include('species/_delete_form.html.twig') }}
|
||||
{% endblock %}
|
@ -1,3 +0,0 @@
|
||||
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
|
||||
{{ form_widget(form) }}
|
||||
{{ form_end(form) }}
|
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Test\Controller;
|
||||
|
||||
use App\Entity\Post;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class PostControllerTest extends WebTestCase
|
||||
{
|
||||
private KernelBrowser $client;
|
||||
private EntityManagerInterface $manager;
|
||||
private EntityRepository $repository;
|
||||
private string $path = '/post/';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = static::createClient();
|
||||
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
||||
$this->repository = $this->manager->getRepository(Post::class);
|
||||
|
||||
foreach ($this->repository->findAll() as $object) {
|
||||
$this->manager->remove($object);
|
||||
}
|
||||
|
||||
$this->manager->flush();
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->path);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('Post index');
|
||||
|
||||
// Use the $crawler to perform additional assertions e.g.
|
||||
// self::assertSame('Some text on the page', $crawler->filter('.p')->first());
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'post[foundDate]' => 'Testing',
|
||||
'post[latitude]' => 'Testing',
|
||||
'post[longitude]' => 'Testing',
|
||||
'post[altitude]' => 'Testing',
|
||||
'post[commentary]' => 'Testing',
|
||||
'post[species]' => 'Testing',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects($this->path);
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Post();
|
||||
$fixture->setFoundDate('My Title');
|
||||
$fixture->setLatitude('My Title');
|
||||
$fixture->setLongitude('My Title');
|
||||
$fixture->setAltitude('My Title');
|
||||
$fixture->setCommentary('My Title');
|
||||
$fixture->setSpecies('My Title');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('Post');
|
||||
|
||||
// Use assertions to check that the properties are properly displayed.
|
||||
}
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Post();
|
||||
$fixture->setFoundDate('Value');
|
||||
$fixture->setLatitude('Value');
|
||||
$fixture->setLongitude('Value');
|
||||
$fixture->setAltitude('Value');
|
||||
$fixture->setCommentary('Value');
|
||||
$fixture->setSpecies('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'post[foundDate]' => 'Something New',
|
||||
'post[latitude]' => 'Something New',
|
||||
'post[longitude]' => 'Something New',
|
||||
'post[altitude]' => 'Something New',
|
||||
'post[commentary]' => 'Something New',
|
||||
'post[species]' => 'Something New',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/post/');
|
||||
|
||||
$fixture = $this->repository->findAll();
|
||||
|
||||
self::assertSame('Something New', $fixture[0]->getFoundDate());
|
||||
self::assertSame('Something New', $fixture[0]->getLatitude());
|
||||
self::assertSame('Something New', $fixture[0]->getLongitude());
|
||||
self::assertSame('Something New', $fixture[0]->getAltitude());
|
||||
self::assertSame('Something New', $fixture[0]->getCommentary());
|
||||
self::assertSame('Something New', $fixture[0]->getSpecies());
|
||||
}
|
||||
|
||||
public function testRemove(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Post();
|
||||
$fixture->setFoundDate('Value');
|
||||
$fixture->setLatitude('Value');
|
||||
$fixture->setLongitude('Value');
|
||||
$fixture->setAltitude('Value');
|
||||
$fixture->setCommentary('Value');
|
||||
$fixture->setSpecies('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
$this->client->submitForm('Delete');
|
||||
|
||||
self::assertResponseRedirects('/post/');
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Test\Controller;
|
||||
|
||||
use App\Entity\Species;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class SpeciesControllerTest extends WebTestCase
|
||||
{
|
||||
private KernelBrowser $client;
|
||||
private EntityManagerInterface $manager;
|
||||
private EntityRepository $repository;
|
||||
private string $path = '/species/';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->client = static::createClient();
|
||||
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
||||
$this->repository = $this->manager->getRepository(Species::class);
|
||||
|
||||
foreach ($this->repository->findAll() as $object) {
|
||||
$this->manager->remove($object);
|
||||
}
|
||||
|
||||
$this->manager->flush();
|
||||
}
|
||||
|
||||
public function testIndex(): void
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->path);
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('Species index');
|
||||
|
||||
// Use the $crawler to perform additional assertions e.g.
|
||||
// self::assertSame('Some text on the page', $crawler->filter('.p')->first());
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
||||
$this->client->submitForm('Save', [
|
||||
'species[scientific_name]' => 'Testing',
|
||||
'species[vernacular_name]' => 'Testing',
|
||||
'species[region]' => 'Testing',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects($this->path);
|
||||
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Species();
|
||||
$fixture->setScientific_name('My Title');
|
||||
$fixture->setVernacular_name('My Title');
|
||||
$fixture->setRegion('My Title');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('Species');
|
||||
|
||||
// Use assertions to check that the properties are properly displayed.
|
||||
}
|
||||
|
||||
public function testEdit(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Species();
|
||||
$fixture->setScientific_name('Value');
|
||||
$fixture->setVernacular_name('Value');
|
||||
$fixture->setRegion('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId()));
|
||||
|
||||
$this->client->submitForm('Update', [
|
||||
'species[scientific_name]' => 'Something New',
|
||||
'species[vernacular_name]' => 'Something New',
|
||||
'species[region]' => 'Something New',
|
||||
]);
|
||||
|
||||
self::assertResponseRedirects('/species/');
|
||||
|
||||
$fixture = $this->repository->findAll();
|
||||
|
||||
self::assertSame('Something New', $fixture[0]->getScientific_name());
|
||||
self::assertSame('Something New', $fixture[0]->getVernacular_name());
|
||||
self::assertSame('Something New', $fixture[0]->getRegion());
|
||||
}
|
||||
|
||||
public function testRemove(): void
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$fixture = new Species();
|
||||
$fixture->setScientific_name('Value');
|
||||
$fixture->setVernacular_name('Value');
|
||||
$fixture->setRegion('Value');
|
||||
|
||||
$this->manager->persist($fixture);
|
||||
$this->manager->flush();
|
||||
|
||||
$this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId()));
|
||||
$this->client->submitForm('Delete');
|
||||
|
||||
self::assertResponseRedirects('/species/');
|
||||
self::assertSame(0, $this->repository->count([]));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue