mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into issue565_document_storedObject
This commit is contained in:
@@ -233,11 +233,22 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
{
|
||||
if (!$this->socialActions->contains($socialAction)) {
|
||||
$this->socialActions[] = $socialAction;
|
||||
$this->ensureSocialActionConsistency();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a social issue.
|
||||
*
|
||||
* Note: the social issue consistency (the fact that only yougest social issues
|
||||
* are kept) is processed by an entity listener:
|
||||
*
|
||||
* @see{\Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener}
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addSocialIssue(SocialIssue $socialIssue): self
|
||||
{
|
||||
if (!$this->socialIssues->contains($socialIssue)) {
|
||||
@@ -633,4 +644,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function ensureSocialActionConsistency(): void
|
||||
{
|
||||
$ancestors = SocialAction::findAncestorSocialActions($this->getSocialActions());
|
||||
|
||||
foreach ($ancestors as $ancestor) {
|
||||
$this->removeSocialAction($ancestor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -54,19 +54,19 @@
|
||||
{{ $t('activity.select_first_a_social_issue') }}
|
||||
</span>
|
||||
|
||||
<template v-else-if="socialActionsList.length > 0">
|
||||
<check-social-action
|
||||
v-if="socialIssuesSelected.length || socialActionsSelected.length"
|
||||
v-for="action in socialActionsList"
|
||||
:key="action.id"
|
||||
:action="action"
|
||||
:selection="socialActionsSelected"
|
||||
@updateSelected="updateActionsSelected">
|
||||
</check-social-action>
|
||||
</template>
|
||||
<template v-else-if="socialActionsList.length > 0">
|
||||
<check-social-action
|
||||
v-if="socialIssuesSelected.length || socialActionsSelected.length"
|
||||
v-for="action in socialActionsList"
|
||||
:key="action.id"
|
||||
:action="action"
|
||||
:selection="socialActionsSelected"
|
||||
@updateSelected="updateActionsSelected">
|
||||
</check-social-action>
|
||||
</template>
|
||||
|
||||
<span v-else-if="actionAreLoaded && socialActionsList.length === 0" class="inline-choice chill-no-data-statement mt-3">
|
||||
{{ $t('activity.social_action_list_empty') }}
|
||||
{{ $t('activity.social_action_list_empty') }}
|
||||
</span>
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ export default {
|
||||
return this.$store.state.socialIssuesOther;
|
||||
},
|
||||
socialActionsList() {
|
||||
return this.$store.state.socialActionsList;
|
||||
return this.$store.getters.socialActionsListSorted;
|
||||
},
|
||||
socialActionsSelected() {
|
||||
return this.$store.state.activity.socialActions;
|
||||
|
@@ -101,6 +101,9 @@ const store = createStore({
|
||||
state.activity.activityType.thirdPartiesVisible !== 0)
|
||||
);
|
||||
},
|
||||
socialActionsListSorted(state) {
|
||||
return [ ...state.socialActionsList].sort((a, b) => a.ordering - b.ordering);
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
// SocialIssueAcc
|
||||
@@ -131,7 +134,6 @@ const store = createStore({
|
||||
state.socialActionsList = [];
|
||||
},
|
||||
addActionInList(state, action) {
|
||||
//console.log('add action list', action.id);
|
||||
state.socialActionsList.push(action);
|
||||
},
|
||||
updateActionsSelected(state, actions) {
|
||||
|
114
src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php
Normal file
114
src/Bundle/ChillActivityBundle/Tests/Entity/ActivityTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\ActivityBundle\Tests\Entity;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ActivityTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testHierarchySocialActions(): void
|
||||
{
|
||||
$parent = new SocialAction();
|
||||
$child = new SocialAction();
|
||||
|
||||
$parent->addChild($child);
|
||||
$grandChild = new SocialAction();
|
||||
$child->addChild($grandChild);
|
||||
|
||||
$activity = new Activity();
|
||||
|
||||
$activity->addSocialAction($parent);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialActions());
|
||||
$this->assertContains($parent, $activity->getSocialActions());
|
||||
|
||||
$activity->addSocialAction($grandChild);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialActions());
|
||||
$this->assertContains($grandChild, $activity->getSocialActions());
|
||||
$this->assertNotContains($parent, $activity->getSocialActions());
|
||||
|
||||
$activity->addSocialAction($child);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialActions());
|
||||
$this->assertContains($grandChild, $activity->getSocialActions());
|
||||
$this->assertNotContains($parent, $activity->getSocialActions());
|
||||
$this->assertNotContains($child, $activity->getSocialActions());
|
||||
|
||||
$activity->addSocialAction($another = new SocialAction());
|
||||
|
||||
$this->assertCount(2, $activity->getSocialActions());
|
||||
$this->assertContains($grandChild, $activity->getSocialActions());
|
||||
$this->assertContains($another, $activity->getSocialActions());
|
||||
$this->assertNotContains($parent, $activity->getSocialActions());
|
||||
$this->assertNotContains($child, $activity->getSocialActions());
|
||||
}
|
||||
|
||||
public function testHierarchySocialIssues(): void
|
||||
{
|
||||
$listener = new AccompanyingPeriodSocialIssueConsistencyEntityListener();
|
||||
$event = $this->prophesize(LifecycleEventArgs::class)->reveal();
|
||||
|
||||
$parent = new SocialIssue();
|
||||
$child = new SocialIssue();
|
||||
|
||||
$parent->addChild($child);
|
||||
$grandChild = new SocialIssue();
|
||||
$child->addChild($grandChild);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setAccompanyingPeriod(new AccompanyingPeriod());
|
||||
|
||||
$activity->addSocialIssue($parent);
|
||||
$listener->preUpdate($activity, $event);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialIssues());
|
||||
$this->assertContains($parent, $activity->getSocialIssues());
|
||||
|
||||
$activity->addSocialIssue($grandChild);
|
||||
$listener->preUpdate($activity, $event);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialIssues());
|
||||
$this->assertContains($grandChild, $activity->getSocialIssues());
|
||||
$this->assertNotContains($parent, $activity->getSocialIssues());
|
||||
|
||||
$activity->addSocialIssue($child);
|
||||
$listener->preUpdate($activity, $event);
|
||||
|
||||
$this->assertCount(1, $activity->getSocialIssues());
|
||||
$this->assertContains($grandChild, $activity->getSocialIssues());
|
||||
$this->assertNotContains($parent, $activity->getSocialIssues());
|
||||
$this->assertNotContains($child, $activity->getSocialIssues());
|
||||
|
||||
$activity->addSocialIssue($another = new SocialIssue());
|
||||
$listener->preUpdate($activity, $event);
|
||||
|
||||
$this->assertCount(2, $activity->getSocialIssues());
|
||||
$this->assertContains($grandChild, $activity->getSocialIssues());
|
||||
$this->assertContains($another, $activity->getSocialIssues());
|
||||
$this->assertNotContains($parent, $activity->getSocialIssues());
|
||||
$this->assertNotContains($child, $activity->getSocialIssues());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user