diff --git a/lib/GaletteStripe/PluginGaletteStripe.php b/lib/GaletteStripe/PluginGaletteStripe.php index c0829ae..1078706 100644 --- a/lib/GaletteStripe/PluginGaletteStripe.php +++ b/lib/GaletteStripe/PluginGaletteStripe.php @@ -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; @@ -27,7 +28,7 @@ * @author Guillaume AGNIERAY */ -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 @@ -88,6 +89,28 @@ public function getPublicMenus(): array ]; } + /** + * Get the public pages the plugin declares + * + * @return array, 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 * diff --git a/tests/GaletteStripe/tests/units/PluginGaletteStripe.php b/tests/GaletteStripe/tests/units/PluginGaletteStripe.php index bef439a..94d787e 100644 --- a/tests/GaletteStripe/tests/units/PluginGaletteStripe.php +++ b/tests/GaletteStripe/tests/units/PluginGaletteStripe.php @@ -16,6 +16,7 @@ * Stripe plugin tests * * @author Johan Cwiklinski + * @author Guillaume AGNIERAY */ class PluginGaletteStripe extends GaletteTestCase { @@ -23,6 +24,85 @@ class PluginGaletteStripe extends GaletteTestCase //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 + */ + 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 */