Skip to content

Commit

Permalink
Merge pull request #683 from eerison/bug/Remove_data
Browse files Browse the repository at this point in the history
Bug/Remove data in user profile
  • Loading branch information
eerison authored Aug 13, 2022
2 parents 8a2e60e + 5ef893d commit 42a176d
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 66 deletions.
7 changes: 6 additions & 1 deletion fixtures/certification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ App\Entity\Certification:
title: <firstName()>
institution: <lastName()>
periodStart: <dateTimeBetween("-200 days", "now")>
user: '@user_test_2'
user: '@user_test_2'
certification{4..8}):
title: <firstName()>
institution: <lastName()>
periodStart: <dateTimeBetween("-200 days", "now")>
user: '@user_profile'
6 changes: 5 additions & 1 deletion fixtures/social_network.html.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ App\Entity\SocialNetworking:

social_network_2:
name: Github
icon: fa-brands fa-github
icon: fa-brands fa-github

social_network_3:
name: Linkedin
icon: fab fa-linkedin-in
5 changes: 5 additions & 0 deletions fixtures/user_social_network.html.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ App\Entity\UserSocialNetworking:
user_social_network_1:
link: <url()>
socialNetworking: '@social_network_2'
user: '@user_profile'

user_social_network_3:
link: <url()>
socialNetworking: '@social_network_3'
user: '@user_profile'
6 changes: 3 additions & 3 deletions src/Controller/Profile/AbstractCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function index(OwnerDataRepositoryInterface $repository): Response
$user = $this->getUser();

return $this->render(sprintf('profile/%s.html.twig', static::PREFIX), [
'data' => $repository->getOwnerData($user),
'data' => $repository->getOwnerData($user)
]);
}

Expand Down Expand Up @@ -59,8 +59,8 @@ public function delete(Request $request, EntityInterface $entity): Response
/** @var string $token */
$token = $request->request->get('_token');

if ($this->isCsrfTokenValid('delete' . $entity->getId(), $token)) {
$this->entityManager->persist($entity);
if ($this->isCsrfTokenValid('delete_' . $entity->getId(), $token)) {
$this->entityManager->remove($entity);
$this->entityManager->flush();

$this->addFlash('success', 'messages.item_removed');
Expand Down
5 changes: 4 additions & 1 deletion templates/profile/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
<div class="section">
<div class="columns is-centered">
<div class="column is-10">
{% include 'profile/partial/form/delete_modal.html.twig' %}
{% include 'profile/partial/flashmessages.html.twig' with { 'auto_hide': true } %}
{% block body %}{% endblock body %}
<div id="content-page">
{% block body %}{% endblock body %}
</div>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions templates/profile/certification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
{% for certification in data %}
{% set path = path('profile_certification_edit', { 'id': certification.id }) %}
<tr>
<td class="identify is-hidden">{{ certification.id }}</td>
<td>{{ certification.title }}</td>
<td class="is-hidden-touch">{{ certification.institution }}</td>
<td class="is-hidden-touch">{% if certification.periodStart %}{{ certification.periodStart|date('d/m/Y') }}{% endif %}</td>
Expand Down
1 change: 1 addition & 0 deletions templates/profile/education.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% for education in data %}
{% set path = path('profile_education_edit', { 'id': education.id }) %}
<tr>
<td class="identify is-hidden">{{ education.id }}</td>
<td>{{ education.title }}</td>
<td class="is-hidden-touch">{{ education.institution }}</td>
<td class="is-hidden-touch">
Expand Down
1 change: 1 addition & 0 deletions templates/profile/experience.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% for experience in data %}
{% set path = path('profile_experience_edit', { 'id': experience.id }) %}
<tr>
<td class="identify is-hidden">{{ experience.id }}</td>
<td>{{ experience.title }}</td>
<td class="is-hidden-touch">{{ experience.company }}</td>
<td class="is-hidden-touch">
Expand Down
52 changes: 2 additions & 50 deletions templates/profile/partial/form/delete_button.html.twig
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
{% trans_default_domain 'MyProfile' %}

<div class="modal" id="model_remove_item">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">{{'form.modal.delete_item.title'|trans}}</p>
</header>
<section class="modal-card-body">
{{'form.modal.delete_item.message'|trans}}
</section>
<footer class="modal-card-foot">
<form method="post" action="" id="form_remove_item">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" id="input_token_remove_item" value="">
<button class="button is-primary" type="submit">
<span class="icon">
<i class="fa fa-check"></i>
</span>
<span>{{'form.modal.delete_item.button.yes'|trans}}</span>
</button>

<div class="button is-danger is-spacing" onclick="closeModalRemoveItem()">
<span class="icon">
<i class="fa fa-close"></i>
</span>
<span>{{'form.modal.delete_item.button.no'|trans}}</span>
</div>
</form>
</footer>
</div>
</div>

<a href="#" class="button is-text has-text-danger delete-button" onclick="openModalRemoveItem('{{ path(router, {'id': id}) }}', '{{ csrf_token('delete' ~ id) }}')">
<a href="#" class="button is-text has-text-danger delete-button" onclick="openModalRemoveItem('{{ path(router, {'id': id}) }}', '{{ csrf_token('delete_' ~ id) }}')">
<span class="icon is-small">
<i class="fa fa-trash"></i>
</span>
<span class="csrf_token is-hidden">{{ csrf_token('delete_' ~ id) }}</span>
</a>

<script>
function openModalRemoveItem(path, csrf_token) {
$modal = document.getElementById("model_remove_item");
$form = document.getElementById("form_remove_item");
$formToken = document.getElementById('input_token_remove_item');
$modal.classList.add("is-active");
$form.action = path;
$formToken.value = csrf_token;
}
function closeModalRemoveItem() {
document.getElementById("model_remove_item").classList.remove("is-active");
}
</script>
47 changes: 47 additions & 0 deletions templates/profile/partial/form/delete_modal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% trans_default_domain 'MyProfile' %}

<script>
function openModalRemoveItem(path, csrf_token) {
$modal = document.getElementById("model_remove_item");
$form = document.getElementById("form_remove_item");
$formToken = document.getElementById('input_token_remove_item');
$modal.classList.add("is-active");
$form.action = path;
$formToken.value = csrf_token;
}
function closeModalRemoveItem() {
document.getElementById("model_remove_item").classList.remove("is-active");
}
</script>

<div class="modal" id="model_remove_item">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">{{'form.modal.delete_item.title'|trans}}</p>
</header>
<section class="modal-card-body">
{{'form.modal.delete_item.message'|trans}}
</section>
<footer class="modal-card-foot">
<form method="post" action="" id="form_remove_item">
<input type="hidden" name="_token" id="input_token_remove_item" value="">
<button class="button is-primary" type="submit" id="confirm-delete">
<span class="icon">
<i class="fa fa-check"></i>
</span>
<span>{{'form.modal.delete_item.button.yes'|trans}}</span>
</button>

<div class="button is-danger is-spacing" onclick="closeModalRemoveItem()">
<span class="icon">
<i class="fa fa-close"></i>
</span>
<span>{{'form.modal.delete_item.button.no'|trans}}</span>
</div>
</form>
</footer>
</div>
</div>
1 change: 1 addition & 0 deletions templates/profile/skill.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% for skill in data %}
{% set path = path('profile_skill_edit', { 'id': skill.id }) %}
<tr>
<td class="identify is-hidden">{{ skill.id }}</td>
<td>{{ skill.priority }}</td>
<td>{{ skill.name }}</td>
<td class="is-hidden-touch">{{ skill.levelExperience }}</td>
Expand Down
1 change: 1 addition & 0 deletions templates/profile/user-social-network.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{% for userSocialNetworking in data %}
{% set path = path('profile_user-social-network_edit', { 'id': userSocialNetworking.id }) %}
<tr>
<td class="identify is-hidden">{{ userSocialNetworking.id }}</td>
<td>
<a href="{{path}}">
<i class="{{ userSocialNetworking.socialNetworking.icon }}"></i>
Expand Down
1 change: 1 addition & 0 deletions templates/profile/user_language.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% for language in data %}
{% set path = path('profile_user_language_edit', { 'id': language.id }) %}
<tr>
<td class="identify is-hidden">{{ language.id }}</td>
<td>{{ language.name }}</td>
<td>{{ language.level }}</td>
<td class="table-list-actions">
Expand Down
20 changes: 20 additions & 0 deletions tests/Functional/Controller/Profile/SmokeCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,24 @@
$this->client->submitForm('Save', $formFields);

$this->assertResponseRedirects($listUrl);
})->with('page_list');

it('is removing the item', function (string $listUrl) {
$crawler = $this->client->request(Request::METHOD_GET, $listUrl);
$rows = $crawler->filter('#table-list tbody tr');
$quantityOfRows = $rows->count();
$identity = $rows->first()->filter('.identify')->text();
$csrfToken = $rows->first()->filter('.csrf_token')->text();

expect($quantityOfRows)->toBeGreaterThan(0);

//Check if the register is in the list after remove.
$this->client->request(Request::METHOD_POST, sprintf('%s/%s/del', $listUrl, $identity), [
'_token' => $csrfToken,
]);
$this->assertResponseRedirects($listUrl);

$crawler = $this->client->request(Request::METHOD_GET, $listUrl);
$rows = $crawler->filter('#table-list tbody tr');
expect($rows->count())->toBeLessThan($quantityOfRows);
})->with('page_list');
4 changes: 2 additions & 2 deletions tests/Functional/Controller/Profile/SmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$this->assertResponseIsSuccessful();

if ($field) {
$this->assertEquals($value, $crawler->filter('form')->form()->get($field)->getValue());
$this->assertEquals($value, $crawler->filter('#content-page form')->form()->get($field)->getValue());
}
})->with(function () {
#main
Expand Down Expand Up @@ -77,7 +77,7 @@
$container = $this->getContainer();

$userRepository = $container->get(UserRepository::class);
$user1 = $userRepository->findOneBy(['email' => '[email protected]']);
$user1 = $userRepository->findOneBy(['email' => 'test-profile@myprofile.pro']);
$user2 = $userRepository->findOneBy(['email' => '[email protected]']);

$client->loginUser($user1);
Expand Down
12 changes: 6 additions & 6 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

dataset('page_list', [
//TODO this test requires that refresh database.
// 'User social network' => [
// '/profile/en/user-social-network',
// [
// 'user_social_networking[link]' => faker()->url(),
// ],
// ],
'User social network' => [
'/profile/en/user-social-network',
[
'user_social_networking[link]' => faker()->url(),
],
],
'Education' => [
'/profile/en/education',
[
Expand Down
2 changes: 1 addition & 1 deletion translations/MyProfile.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ form:
summary: Summary
key_words: Keywords (separated by commas)

social_network:
user-social-network:
head:
title: Social network
socialNetwork: Social network
Expand Down
2 changes: 1 addition & 1 deletion translations/MyProfile.pt_BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ form:
summary: Resumo
key_words: Palavras chaves (separado por vírgulas)

social_network:
user-social-network:
head:
title: Rede social
socialNetwork: Rede social
Expand Down

0 comments on commit 42a176d

Please sign in to comment.