diff --git a/lib/GaletteHelloasso/PluginGaletteHelloasso.php b/lib/GaletteHelloasso/PluginGaletteHelloasso.php index 031fff3..9176da8 100644 --- a/lib/GaletteHelloasso/PluginGaletteHelloasso.php +++ b/lib/GaletteHelloasso/PluginGaletteHelloasso.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; use Laminas\Db\Metadata\Source\Factory; @@ -26,7 +27,7 @@ * @author Guillaume AGNIERAY */ -class PluginGaletteHelloasso extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface +class PluginGaletteHelloasso extends GalettePlugin implements MenuProviderInterface, DashboardProviderInterface, PublicPagesProviderInterface { #[Inject] private readonly Db $zdb; //@phpstan-ignore-line injected from DI @@ -87,6 +88,28 @@ public function getPublicMenus(): array ]; } + /** + * Get the public pages the plugin declares + * + * @return array, default?: int}> + */ + public function getPublicPages(): array + { + return [ + 'form' => ['routes' => ['helloasso_form']], + ]; + } + + /** + * Get the label of a declared public page + * + * @param string $id Page identifier + */ + public function getPublicPageLabel(string $id): string + { + return _T("Payment form", "helloasso"); + } + /** * Get plugins dashboards * diff --git a/tests/GaletteHelloasso/tests/units/PluginGaletteHelloasso.php b/tests/GaletteHelloasso/tests/units/PluginGaletteHelloasso.php index 412d1e8..a003c1a 100644 --- a/tests/GaletteHelloasso/tests/units/PluginGaletteHelloasso.php +++ b/tests/GaletteHelloasso/tests/units/PluginGaletteHelloasso.php @@ -16,11 +16,91 @@ * Helloasso plugin tests * * @author Johan Cwiklinski + * @author Guillaume AGNIERAY */ class PluginGaletteHelloasso extends GaletteTestCase { protected int $seed = 20260928091512; + /** + * 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(\GaletteHelloasso\PluginGaletteHelloasso::class); + $menus = $plugin->getMenus(); + return array_map( + fn($item) => $item['route']['name'], + $menus['plugin_helloasso']['items'] ?? [] + ); + } + + /** + * Test menus by profile + */ + public function testGetMenus(): void + { + $this->logSuperAdmin(); + $this->assertSame( + [ + 'helloasso_history', + 'helloasso_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_helloasso_publicpages_visibility_form'; + $plugin = $this->container->get(\GaletteHelloasso\PluginGaletteHelloasso::class); + + $this->assertSame(['form' => ['routes' => ['helloasso_form']]], $plugin->getPublicPages()); + $this->assertSame('Payment form', $plugin->getPublicPageLabel('helloasso_form')); + $this->assertTrue(\Galette\Core\PreferencesSchema::isPublicPage($name)); + $this->assertSame($name, \Galette\Core\PreferencesSchema::getPublicPageRight('helloasso_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(['helloasso_form'], array_map( + fn($item) => $item['route']['name'], + $plugin->getPublicMenuItems() + )); + + $this->setRawPreference($name, \Galette\Enums\PublicPageVisibility::Inherit->value); + $this->assertSame([], $plugin->getPublicMenuItems()); + } + /** * Current tables are not legacy ones */