Skip to content

Commit

Permalink
Attach member on activity group once subscribed
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Aug 24, 2024
1 parent b11bfe2 commit 478a5e5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/GaletteActivities/Entity/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ public function store(): bool
_T("Subscription added", "activities"),
$this->getActivity()->getName()
);

//link member to activity group, if any
$group = $this->activity->getGroup();
if ($group !== null) {
$group->addMember($this->member);
}
} else {
$hist->add(_T("Fail to add new subscription.", "activities"));
throw new \Exception(
Expand Down
38 changes: 38 additions & 0 deletions tests/GaletteActivities/Entity/tests/units/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function tearDown(): void
$delete = $this->zdb->delete(ACTIVITIES_PREFIX . \GaletteActivities\Entity\Activity::TABLE);
$this->zdb->execute($delete);

$delete = $this->zdb->delete(\Galette\Entity\Group::GROUPSUSERS_TABLE);
$this->zdb->execute($delete);

$delete = $this->zdb->delete(\Galette\Entity\Group::TABLE);
$this->zdb->execute($delete);

Expand Down Expand Up @@ -101,7 +104,22 @@ public function testCrud(): void
$this->assertTrue($activity->check($data));
$this->assertTrue($activity->store());

$group = new \Galette\Entity\Group();
$group->setName('Subscribed group');
$this->assertTrue($group->store());

$gactivity = new \GaletteActivities\Entity\Activity($this->zdb);
$data = [
'name' => 'Activity with a group',
'comment' => 'Comment for group/activity ' . $this->seed,
'price' => 5.0,
\Galette\Entity\Group::PK => $group->getId()
];
$this->assertTrue($gactivity->check($data));
$this->assertTrue($gactivity->store());

$activity_id = $activity->getId();
$gactivity_id = $gactivity->getId();
$member_one = $this->getMemberOne();

//Missing required data
Expand Down Expand Up @@ -170,6 +188,9 @@ public function testCrud(): void
$this->assertTrue($subscription->store());
$subscription_id = $subscription->getId();

//member is not part of any group
$this->assertCount(0,$member_one->getGroups());

$this->assertFalse($subscription->isPaid());
//by default, amount is set to activity price
$this->assertSame(42.0, $subscription->getAmount());
Expand Down Expand Up @@ -204,6 +225,23 @@ public function testCrud(): void
//remove subscription
$this->assertTrue($subscription->remove());
$this->assertFalse($activity->load($subscription_id));

//create a subscription with a group
$subscription = new \GaletteActivities\Entity\Subscription($this->zdb);
$data = [
'activity' => $gactivity_id,
'member' => $member_one->id,
'subscription_date' => (new \DateTime())->format('Y-m-d'),
'end_date' => (new \DateTime())->modify('+1 year')->format('Y-m-d'),
'comment' => 'Comment ' . $this->seed,
];
$this->assertTrue($subscription->check($data));
$this->assertTrue($subscription->store());

//member is part activity linked group
$member_one->loadGroups();
$groups = $member_one->getGroups();
$this->assertCount(1, $groups);
}

/**
Expand Down

0 comments on commit 478a5e5

Please sign in to comment.