Skip to content
Snippets Groups Projects
Commit c1028fd9 authored by DEMANGEL Mael's avatar DEMANGEL Mael
Browse files

ajout du test de poster une annonce

parent fcbd51b2
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
Date de début* Date de début*
{{ form_widget(form.date_debut, {'attr': {'required': true, 'class': 'form-control'}}) }} {{ form_widget(form.date_debut, {'attr': {'required': true, 'class': 'form-control'}}) }}
<button type="submit" class="creation_annonce">Créer</button> <button type="submit" id="creer_annonce" class="creation_annonce">Créer</button>
</div> </div>
{{ form_end(form) }} {{ form_end(form) }}
<a href="{{ path("app_home_page")}}"><button class="btn-connexion2">Retourner à l'accueil</button></a> <a href="{{ path("app_home_page")}}"><button class="btn-connexion2">Retourner à l'accueil</button></a>
......
<?php
namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use App\Repository\PersonneRepository;
class TestsPosterAnnonceTest extends WebTestCase
{
public function testPosterAnnonce(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(PersonneRepository::class);
$user = $userRepository->findOneByLogin('test');
$client->loginUser($user);
// Accéder à la page d'inscription
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'pret',
'annonce[titre]'=> 'testAnnonce',
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> 50,
]);
$this->assertResponseRedirects('/');
//On test si l'on peut créer deux fois la même annonce
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'pret',
'annonce[titre]'=> 'testAnnonce',
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> 50,
]);
$this->assertResponseRedirects('/');
//On test si le titre peut être vide
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'pret',
'annonce[titre]'=> null,
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> 50,
]);
$this->assertFalse($client->getResponse()->isRedirect());
//On test si le cout peut être nul
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'pret',
'annonce[titre]'=> '',
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> null,
]);
$this->assertFalse($client->getResponse()->isRedirect());
}
public function testVisualisationAnnonce(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(PersonneRepository::class);
$user = $userRepository->findOneByLogin('test');
$client->loginUser($user);
// Accéder à la page de création d'annonce
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'pret',
'annonce[titre]'=> 'testPretAnnonce',
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> 50,
]);
$this->assertResponseRedirects('/');
// Accéder à la page de création d'annonce
$client->request('GET', '/annonce/creation');
// Soumettre le formulaire de création avec des données valides
$client->submitForm('creer_annonce',[
'annonce[type_prestation]' => 'service',
'annonce[titre]'=> 'testServiceAnnonce',
'annonce[descr_prestation]' => 'ceci est une description',
'annonce[cout_prestation]'=> 100,
]);
$this->assertResponseRedirects('/');
$client->request('GET', '');
$this->assertSelectorExists('p','testPretAnnonce');
$this->assertSelectorExists('p','50 florains');
$this->assertSelectorExists('p','Prèt');
$this->assertSelectorExists('p','testServiceAnnonce');
$this->assertSelectorExists('p','100 florains');
$this->assertSelectorExists('p','Service');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment