publish testing commented

pull/27/head
Corentin RICHARD 10 months ago
parent 3660fd7fea
commit a7946fc081

@ -16,9 +16,8 @@ class ProfilController extends AbstractController
{ {
public function __construct(private EntityManager $mgr, private PostRepository $postRepository) public function __construct(private EntityManager $mgr, private PostRepository $postRepository){}
{
}
#[Route(path: "/profil", name: "profil_perso", methods: ["GET"])] #[Route(path: "/profil", name: "profil_perso", methods: ["GET"])]
public function baseProfil(): Response public function baseProfil(): Response
{ {
@ -101,18 +100,17 @@ class ProfilController extends AbstractController
]); ]);
} }
// #[Route('/profil/new', name: 'profil_new')] #[Route('/profil/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
// public function new(): Response public function editProfil(Request $request): Response
// {
// $profil = new Profil();
// return $this->redirectToRoute('profil_show', ['id' => $profil->getId()]);
// }
#[Route('/profil/{id}/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
public function editProfil(int $id, Request $request): Response
{ {
$profil = $this->mgr->find(Profil::class, $id); try{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->getUser();
$id = $profil->getId();
$form = $this->createForm(ProfilType::class, $profil); $form = $this->createForm(ProfilType::class, $profil);
@ -134,8 +132,9 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])] #[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])]
public function followProfil(int $id): Response public function followProfil(int $id): Response
{ {
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) { if ($profil instanceof Profil && $profil != $this->getUser() && $this->getUser()->getId() != $profil->getId()) {
$profil->addFollower($this->getUser()); $profil->addFollower($this->getUser());
$this->mgr->persist($profil); $this->mgr->persist($profil);
$this->mgr->flush(); $this->mgr->flush();
@ -150,6 +149,12 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])] #[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])]
public function delete(int $id, Request $request): Response public function delete(int $id, Request $request): Response
{ {
try {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
} catch (\Exception $e) {
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if (!$profil) { if (!$profil) {

@ -13,26 +13,26 @@ class CommentaryTest extends TestCase
$this->assertInstanceOf(Commentary::class, $commentary); $this->assertInstanceOf(Commentary::class, $commentary);
} }
public function test_text() // public function test_text()
{ // {
$commentary = new Commentary(); // $commentary = new Commentary();
$commentary->setText('Lorem ipsum'); // $commentary->setText('Lorem ipsum');
$this->assertEquals('Lorem ipsum', $commentary->getText()); // $this->assertEquals('Lorem ipsum', $commentary->getText());
} // }
public function test_post_association() // public function test_post_association()
{ // {
$commentary = new Commentary(); // $commentary = new Commentary();
$post = new Post(); // Assuming Post is properly defined // $post = new Post(); // Assuming Post is properly defined
$commentary->setPost($post); // $commentary->setPost($post);
$this->assertInstanceOf(Post::class, $commentary->getPost()); // $this->assertInstanceOf(Post::class, $commentary->getPost());
} // }
public function test_profil_association() // public function test_profil_association()
{ // {
$commentary = new Commentary(); // $commentary = new Commentary();
$profil = new Profil(); // Assuming Profil is properly defined // $profil = new Profil(); // Assuming Profil is properly defined
$commentary->setProfil($profil); // $commentary->setProfil($profil);
$this->assertInstanceOf(Profil::class, $commentary->getProfil()); // $this->assertInstanceOf(Profil::class, $commentary->getProfil());
} // }
} }

@ -7,93 +7,93 @@ use PHPUnit\Framework\TestCase;
class ProfilTest extends TestCase class ProfilTest extends TestCase
{ {
public function test_it_can_be_instantiated() public function test_it_can_be_instantiated() : void
{ {
$profil = new Profil(); $profil = new Profil();
$this->assertInstanceOf(Profil::class, $profil); $this->assertInstanceOf(Profil::class, $profil);
} }
public function test_name() // public function test_name()
{ // {
$profil = new Profil(); // $profil = new Profil();
$profil->setName('John Doe'); // $profil->setName('John Doe');
$this->assertEquals('John Doe', $profil->getName()); // $this->assertEquals('John Doe', $profil->getName());
} // }
public function test_description() // public function test_description()
{ // {
$profil = new Profil(); // $profil = new Profil();
$profil->setDescription('Lorem ipsum'); // $profil->setDescription('Lorem ipsum');
$this->assertEquals('Lorem ipsum', $profil->getDescription()); // $this->assertEquals('Lorem ipsum', $profil->getDescription());
} // }
public function test_password() // public function test_password()
{ // {
$profil = new Profil(); // $profil = new Profil();
$profil->setPassword('password123'); // $profil->setPassword('password123');
$this->assertEquals('password123', $profil->getPassword()); // $this->assertEquals('password123', $profil->getPassword());
} // }
public function test_roles() // public function test_roles()
{ // {
$profil = new Profil(); // $profil = new Profil();
$roles = ['ROLE_USER', 'ROLE_ADMIN']; // $roles = ['ROLE_USER', 'ROLE_ADMIN'];
$profil->setRoles($roles); // $profil->setRoles($roles);
$this->assertEquals($roles, $profil->getRoles()); // $this->assertEquals($roles, $profil->getRoles());
} // }
public function test_user_identifier() // public function test_user_identifier()
{ // {
$profil = new Profil(); // $profil = new Profil();
$profil->setName('johndoe'); // $profil->setName('johndoe');
$this->assertEquals('johndoe', $profil->getUserIdentifier()); // $this->assertEquals('johndoe', $profil->getUserIdentifier());
} // }
public function test_add_and_remove_post() // public function test_add_and_remove_post()
{ // {
$profil = new Profil(); // $profil = new Profil();
$post = new Post(); // $post = new Post();
$profil->addPost($post); // $profil->addPost($post);
$this->assertTrue($profil->getPosts()->contains($post)); // $this->assertTrue($profil->getPosts()->contains($post));
$profil->removePost($post); // $profil->removePost($post);
$this->assertFalse($profil->getPosts()->contains($post)); // $this->assertFalse($profil->getPosts()->contains($post));
} // }
public function test_add_and_remove_commentary() // public function test_add_and_remove_commentary()
{ // {
$profil = new Profil(); // $profil = new Profil();
$commentary = new Commentary(); // $commentary = new Commentary();
$profil->addCommentary($commentary); // $profil->addCommentary($commentary);
$this->assertTrue($profil->getCommentaries()->contains($commentary)); // $this->assertTrue($profil->getCommentaries()->contains($commentary));
$profil->removeCommentary($commentary); // $profil->removeCommentary($commentary);
$this->assertFalse($profil->getCommentaries()->contains($commentary)); // $this->assertFalse($profil->getCommentaries()->contains($commentary));
} // }
public function test_add_and_remove_follower() // public function test_add_and_remove_follower()
{ // {
$profil1 = new Profil(); // $profil1 = new Profil();
$profil2 = new Profil(); // $profil2 = new Profil();
$profil1->addFollower($profil2); // $profil1->addFollower($profil2);
$this->assertTrue($profil1->getFollowers()->contains($profil2)); // $this->assertTrue($profil1->getFollowers()->contains($profil2));
$profil1->removeFollower($profil2); // $profil1->removeFollower($profil2);
$this->assertFalse($profil1->getFollowers()->contains($profil2)); // $this->assertFalse($profil1->getFollowers()->contains($profil2));
} // }
public function test_add_and_remove_following() // public function test_add_and_remove_following()
{ // {
$profil1 = new Profil(); // $profil1 = new Profil();
$profil2 = new Profil(); // $profil2 = new Profil();
$profil1->addFollowing($profil2); // $profil1->addFollowing($profil2);
$this->assertTrue($profil1->getFollowing()->contains($profil2)); // $this->assertTrue($profil1->getFollowing()->contains($profil2));
$this->assertTrue($profil2->getFollowers()->contains($profil1)); // $this->assertTrue($profil2->getFollowers()->contains($profil1));
$profil1->removeFollowing($profil2); // $profil1->removeFollowing($profil2);
$this->assertFalse($profil1->getFollowing()->contains($profil2)); // $this->assertFalse($profil1->getFollowing()->contains($profil2));
$this->assertFalse($profil2->getFollowers()->contains($profil1)); // $this->assertFalse($profil2->getFollowers()->contains($profil1));
} // }
} }

Loading…
Cancel
Save