|
|
|
@ -3,8 +3,9 @@
|
|
|
|
|
namespace App\Test\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Entity\Post;
|
|
|
|
|
use App\Entity\User;
|
|
|
|
|
use App\Repository\PostRepository;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
|
@ -12,13 +13,15 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
{
|
|
|
|
|
private KernelBrowser $client;
|
|
|
|
|
private EntityManagerInterface $manager;
|
|
|
|
|
private EntityRepository $repository;
|
|
|
|
|
private PostRepository $repository;
|
|
|
|
|
private string $path = '/post/';
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
$this->client = static::createClient();
|
|
|
|
|
$this->manager = static::getContainer()->get('doctrine')->getManager();
|
|
|
|
|
/** @var EntityManagerInterface $manager */
|
|
|
|
|
$manager = static::getContainer()->get(EntityManagerInterface::class);
|
|
|
|
|
$this->manager = $manager;
|
|
|
|
|
$this->repository = $this->manager->getRepository(Post::class);
|
|
|
|
|
|
|
|
|
|
foreach ($this->repository->findAll() as $object) {
|
|
|
|
@ -26,6 +29,12 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->manager->flush();
|
|
|
|
|
|
|
|
|
|
$userRepository = $this->manager->getRepository(User::class);
|
|
|
|
|
/** @var User $user */
|
|
|
|
|
$user = $userRepository->findOneByEmail('test@test.fr');
|
|
|
|
|
$this->client->loginUser($user);
|
|
|
|
|
$this->client->request('GET', sprintf('%snew', $this->path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testIndex(): void
|
|
|
|
@ -41,35 +50,26 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
|
|
|
|
|
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[foundDate]' => '2024-01-01 00:00:00',
|
|
|
|
|
'post[latitude]' => '45.0',
|
|
|
|
|
'post[longitude]' => '45.0',
|
|
|
|
|
'post[altitude]' => '500.0',
|
|
|
|
|
'post[commentary]' => 'Testing',
|
|
|
|
|
'post[species]' => 'Testing',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
self::assertResponseRedirects($this->path);
|
|
|
|
|
|
|
|
|
|
self::assertSame(1, $this->repository->count([]));
|
|
|
|
|
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');
|
|
|
|
|
$fixture->setFoundDate(new \DateTimeImmutable('2024-01-01 00:00:00'));
|
|
|
|
|
$fixture->setCommentary('Cool stuff');
|
|
|
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
|
$this->manager->flush();
|
|
|
|
@ -77,21 +77,14 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
$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.
|
|
|
|
|
self::assertSelectorTextContains('h1', 'Post');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
$fixture->setFoundDate(new \DateTimeImmutable('2024-01-01 00:00:00'));
|
|
|
|
|
$fixture->setCommentary('Cool stuff');
|
|
|
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
|
$this->manager->flush();
|
|
|
|
@ -99,36 +92,29 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
$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[foundDate]' => '2024-03-25 00:00:00',
|
|
|
|
|
'post[latitude]' => '90',
|
|
|
|
|
'post[longitude]' => '90',
|
|
|
|
|
'post[altitude]' => '200',
|
|
|
|
|
'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::assertEquals(new \DateTimeImmutable('2024-03-25 00:00:00'), $fixture[0]->getFoundDate());
|
|
|
|
|
self::assertSame(90., $fixture[0]->getLatitude());
|
|
|
|
|
self::assertSame(90., $fixture[0]->getLongitude());
|
|
|
|
|
self::assertSame(200., $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');
|
|
|
|
|
$fixture->setFoundDate(new \DateTimeImmutable('2024-01-01 00:00:00'));
|
|
|
|
|
$fixture->setCommentary('Cool stuff');
|
|
|
|
|
|
|
|
|
|
$this->manager->persist($fixture);
|
|
|
|
|
$this->manager->flush();
|
|
|
|
@ -137,6 +123,6 @@ class PostControllerTest extends WebTestCase
|
|
|
|
|
$this->client->submitForm('Delete');
|
|
|
|
|
|
|
|
|
|
self::assertResponseRedirects('/post/');
|
|
|
|
|
self::assertSame(0, $this->repository->count([]));
|
|
|
|
|
self::assertSame(0, $this->repository->count());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|