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
25 changes: 24 additions & 1 deletion lib/GaletteStripe/PluginGaletteStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Galette\Core\Login;
use Galette\Core\Plugins\DashboardProviderInterface;
use Galette\Core\Plugins\MenuProviderInterface;
use Galette\Core\Plugins\PublicPagesProviderInterface;
use Galette\Core\Preferences;
use Galette\Core\GalettePlugin;

Expand All @@ -27,7 +28,7 @@
* @author Guillaume AGNIERAY <dev@agnieray.net>
*/

class PluginGaletteStripe extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface
class PluginGaletteStripe extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface, PublicPagesProviderInterface
{
#[Inject]
private readonly Db $zdb; //@phpstan-ignore-line injected from DI
Expand Down Expand Up @@ -88,6 +89,28 @@ public function getPublicMenus(): array
];
}

/**
* Get the public pages the plugin declares
*
* @return array<string, array{routes: list<string>, default?: int}>
*/
public function getPublicPages(): array
{
return [
'form' => ['routes' => ['stripe_form']],
];
}

/**
* Get the label of a declared public page
*
* @param string $id Page identifier
*/
public function getPublicPageLabel(string $id): string
{
return _T("Payment form", "stripe");
}

/**
* Get plugins dashboards
*
Expand Down
80 changes: 80 additions & 0 deletions tests/GaletteStripe/tests/units/PluginGaletteStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,93 @@
* Stripe plugin tests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
* @author Guillaume AGNIERAY <dev@agnieray.net>
*/
class PluginGaletteStripe extends GaletteTestCase
{
protected int $seed = 20260928043512;
//tables are created: on MySQL, that would commit the test transaction
protected bool $db_transactions = false;

/**
* Cleanup after each test method
*/
public function tearDown(): void
{
$this->login->logout();
parent::tearDown();
}

/**
* Get menu items routes
*
* @return array<string>
*/
private function getMenuRoutes(): array
{
$plugin = $this->container->get(\GaletteStripe\PluginGaletteStripe::class);
$menus = $plugin->getMenus();
return array_map(
fn($item) => $item['route']['name'],
$menus['plugin_stripe']['items'] ?? []
);
}

/**
* Test menus by profile
*/
public function testGetMenus(): void
{
$this->logSuperAdmin();
$this->assertSame(
[
'stripe_history',
'stripe_preferences',
],
$this->getMenuRoutes()
);
$this->login->logout();

$member = $this->getMemberOne();
$mdata = $this->dataAdherentOne();
$this->assertTrue($this->login->login($mdata['login_adh'], $mdata['mdp_adh']));
$this->assertSame($mdata['login_adh'], $member->login);
$this->assertSame([], $this->getMenuRoutes());
}

/**
* The public form is declared to the core, with a visibility of its own
*/
public function testPublicPage(): void
{
$name = 'pref_stripe_publicpages_visibility_form';
$plugin = $this->container->get(\GaletteStripe\PluginGaletteStripe::class);

$this->assertSame(['form' => ['routes' => ['stripe_form']]], $plugin->getPublicPages());
$this->assertSame('Payment form', $plugin->getPublicPageLabel('stripe_form'));
$this->assertTrue(\Galette\Core\PreferencesSchema::isPublicPage($name));
$this->assertSame($name, \Galette\Core\PreferencesSchema::getPublicPageRight('stripe_form'));
$this->assertSame(
\Galette\Enums\PublicPageVisibility::Inherit->value,
\Galette\Core\PreferencesSchema::get($name)['default']
);

//the public menu entry follows it, not the default visibility
$this->setRawPreference('pref_bool_publicpages', true);
$this->setRawPreference(
'pref_publicpages_visibility_generic',
\Galette\Enums\PublicPageVisibility::Hidden->value
);
$this->setRawPreference($name, \Galette\Enums\PublicPageVisibility::Everyone->value);
$this->assertSame(['stripe_form'], array_map(
fn($item) => $item['route']['name'],
$plugin->getPublicMenuItems()
));

$this->setRawPreference($name, \Galette\Enums\PublicPageVisibility::Inherit->value);
$this->assertSame([], $plugin->getPublicMenuItems());
}

/**
* Get plugin instance
*/
Expand Down
Loading