Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- name: CS
run: |
cd galette-core/galette/plugins/plugin-activities
../../vendor/bin/phpcs lib/ ./*.php
../../vendor/bin/phpcs lib/ tests/ ./*.php

- name: CS Fixer
if: matrix.php-is-min
Expand Down
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
'cast_spaces' => ['space' => 'none'],
'single_line_empty_body' => false,
'no_unused_imports' => true,
// spaces around multiple catch types only, as phpcs expects - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:types_spaces
'types_spaces' => ['space' => 'none', 'space_multiple_catch' => 'single'],
// rules for phpdoc
// Removes @param, @return and @var tags that don't provide any useful information - https://mlocati.github.io/php-cs-fixer-configurator/#version:3.90|fixer:no_superfluous_phpdoc_tags
'no_superfluous_phpdoc_tags' => [
Expand Down
28 changes: 14 additions & 14 deletions lib/GaletteActivities/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Activity
/**
* Default constructor
*
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific activity, or null to just
* instanciate object
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string, mixed> $args Either a ResultSet row or its id for to load
* a specific activity, or null to just
* instanciate object
*/
public function __construct(Db $zdb, int|ArrayObject|null $args = null)
{
Expand Down Expand Up @@ -92,22 +92,22 @@ public function load(int $id): bool
/**
* Populate object from a resultset row
*
* @param ArrayObject<string, string|int> $r the resultset row
* @param ArrayObject<string, mixed> $r the resultset row
*/
private function loadFromRS(ArrayObject $r): void
{
$this->id = (int)$r->id_activity;
$this->name = $r->name;
$this->type = $r->type ?? '';
if ($r->price !== null) {
$this->price = (float)$r->price;
$this->id = (int)$r['id_activity'];
$this->name = $r['name'];
$this->type = $r['type'] ?? '';
if ($r['price'] !== null) {
$this->price = (float)$r['price'];
}
if ($r->id_group !== null) {
$this->id_group = (int)$r->id_group;
if ($r['id_group'] !== null) {
$this->id_group = (int)$r['id_group'];
$this->group = new Group($this->id_group);
}
$this->creation_date = $r->creation_date;
$this->comment = $r->comment;
$this->creation_date = $r['creation_date'];
$this->comment = $r['comment'];
}

/**
Expand Down
32 changes: 16 additions & 16 deletions lib/GaletteActivities/Entity/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class Subscription
/**
* Default constructor
*
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string,int|string> $args Either a ResultSet row or its id for to load
* a specific subscription, or null to just
* instanciate object
* @param Db $zdb Database instance
* @param null|int|ArrayObject<string, mixed> $args Either a ResultSet row or its id for to load
* a specific subscription, or null to just
* instanciate object
*/
public function __construct(Db $zdb, int|ArrayObject|null $args = null)
{
Expand Down Expand Up @@ -102,24 +102,24 @@ public function load(int $id): bool
/**
* Populate object from a resultset row
*
* @param ArrayObject<string, int|string> $r the resultset row
* @param ArrayObject<string, mixed> $r the resultset row
*/
private function loadFromRS(ArrayObject $r): void
{
$this->id = (int)$r->id_subscription;
$this->setActivity((int)$r->{Activity::PK});
$this->setMember((int)$r->{Adherent::PK});
$this->id = (int)$r['id_subscription'];
$this->setActivity((int)$r[Activity::PK]);
$this->setMember((int)$r[Adherent::PK]);
$this->stored_activity = $this->id_activity;
$this->stored_member = $this->id_member;
$this->paid = (bool)$r->is_paid;
if ($r->payment_amount !== null) {
$this->payment_amount = (float)$r->payment_amount;
$this->paid = (bool)$r['is_paid'];
if ($r['payment_amount'] !== null) {
$this->payment_amount = (float)$r['payment_amount'];
}
$this->payment_method = (int)$r->payment_method;
$this->creation_date = $r->creation_date;
$this->subscription_date = $r->subscription_date;
$this->end_date = $r->end_date;
$this->comment = $r->comment ?? '';
$this->payment_method = (int)$r['payment_method'];
$this->creation_date = $r['creation_date'];
$this->subscription_date = $r['subscription_date'];
$this->end_date = $r['end_date'];
$this->comment = $r['comment'] ?? '';
}

/**
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
level: 6
paths:
- lib/
- tests/
scanFiles:
- _config.inc.php
- ../../includes/sys_config/paths.inc.php
Expand All @@ -14,5 +15,3 @@ parameters:
- ../../lib/
universalObjectCratesClasses:
- RKA\Session
ignoreErrors:
- '/Access to an undefined property ArrayObject.*/'
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,123 @@ public function testConfirmRemovalCountsSubscriptions(): void
$this->assertStringContainsString('2 subscriptions to this activity will be removed as well.', $body);
$this->expectNoLogEntry();
}

/**
* Activities list
*/
public function testList(): void
{
$this->logSuperAdmin();
$group = $this->createGroup('Climbers');
$this->insertActivity('Climbing', $group->getId(), ['price' => 12.5]);
$this->insertActivity('Hiking', null, ['price' => null]);

$test_response = $this->app->handle($this->createRequest('activities_activities'));
$this->assertSame(200, $test_response->getStatusCode());
$body = (string)$test_response->getBody();
$this->assertStringContainsString('2 activities', $body);
$this->assertStringContainsString('Climbing', $body);
$this->assertStringContainsString('12.50', $body);
$this->assertStringContainsString('Climbers', $body);
$this->assertStringContainsString('Hiking', $body);
$this->expectNoLogEntry();
}

/**
* Creation and edition forms
*/
public function testForms(): void
{
$this->logSuperAdmin();
$group = $this->createGroup('Climbers');
$id = $this->insertActivity('Climbing', $group->getId(), ['type' => 'ESC', 'comment' => 'Indoor']);

$test_response = $this->app->handle($this->createRequest('activities_activity_add'));
$this->assertSame(200, $test_response->getStatusCode());
$body = (string)$test_response->getBody();
$this->assertStringContainsString('action="' . $this->routeparser->urlFor('activities_storeactivity_add') . '"', $body);
$this->assertStringContainsString('Climbers', $body);
$this->expectNoLogEntry();

$test_response = $this->app->handle($this->createRequest('activities_activity_edit', ['id' => (string)$id]));
$this->assertSame(200, $test_response->getStatusCode());
$body = (string)$test_response->getBody();
$this->assertStringContainsString(
'action="' . $this->routeparser->urlFor('activities_storeactivity_edit', ['id' => (string)$id]) . '"',
$body
);
$this->assertStringContainsString('value="Climbing"', $body);
$this->assertStringContainsString('value="ESC"', $body);
$this->assertStringContainsString('Indoor', $body);
$this->assertMatchesRegularExpression('/<option\s+value="' . $group->getId() . '"\s+selected="selected"/', $body);
$this->expectNoLogEntry();
}

/**
* Activities are changed, invalid values are displayed again
*/
public function testEdit(): void
{
$this->logSuperAdmin();
$id = $this->insertActivity('Climbing');
$post = function (array $data) use ($id): \Psr\Http\Message\ResponseInterface {
$request = $this->createRequest('activities_storeactivity_edit', ['id' => (string)$id], 'POST')
->withParsedBody($data + ['id' => (string)$id, 'comment' => '']);
return $this->app->handle($request);
};

$test_response = $post(['name' => 'Bouldering', 'price' => '8']);
$this->assertSame(
['Location' => [$this->routeparser->urlFor('activities_activities')]],
$test_response->getHeaders()
);
$this->expectNoLogEntry();
$this->expectFlashData(['success_detected' => ['Activity has been modified.']]);
$activity = new \GaletteActivities\Entity\Activity($this->zdb, $id);
$this->assertSame('Bouldering', $activity->getName());
$this->assertSame(8.0, $activity->getPrice());

$test_response = $post(['name' => 'Bouldering', 'type' => 'TOOLONG']);
$edit_url = $this->routeparser->urlFor('activities_activity_edit', ['id' => (string)$id]);
$this->assertSame(['Location' => [$edit_url]], $test_response->getHeaders());
$this->assertSame(303, $test_response->getStatusCode());
$this->expectLogEntry(\Analog\Analog::ERROR, 'Type is too long');
$this->expectNoLogEntry();
$this->expectFlashData(['error_detected' => ['Type is too long']]);
$this->assertSame('', (new \GaletteActivities\Entity\Activity($this->zdb, $id))->getType());

//form is displayed again from session
$this->assertNotNull($this->session->plugin_activities_activity);
$test_response = $this->app->handle($this->createRequest('activities_activity_edit', ['id' => (string)$id]));
$this->assertSame(200, $test_response->getStatusCode());
$this->assertStringContainsString('value="Bouldering"', (string)$test_response->getBody());
$this->assertFalse(isset($this->session->plugin_activities_activity));
$this->expectNoLogEntry();
}

/**
* Activities are removed with their subscriptions
*/
public function testRemove(): void
{
$this->logSuperAdmin();
$id = $this->insertActivity('Climbing');
$this->insertSubscription($id, $this->getMemberOne()->id);

//not confirmed
$request = $this->createRequest('activities_do_remove_activity', ['id' => (string)$id], 'POST');
$this->app->handle($request->withParsedBody([]));
$this->expectFlashData(['error_detected' => ['Removal has not been confirmed!']]);
$this->assertSame(1, $this->countSubscriptions($id));

$test_response = $this->app->handle($request->withParsedBody(['confirm' => '1']));
$this->assertSame(
['Location' => [$this->routeparser->urlFor('activities_activities')]],
$test_response->getHeaders()
);
$this->expectNoLogEntry();
$this->expectFlashData(['success_detected' => ['Successfully deleted!']]);
$this->assertFalse((new \GaletteActivities\Entity\Activity($this->zdb))->load($id));
$this->assertSame(0, $this->countSubscriptions($id));
}
}
Loading
Loading