From 80262cf2bb1d6196f63ecd0673d6d8659fe51acd Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 30 Nov 2021 14:26:58 -0800 Subject: [PATCH] mixin/mgd-php - Import --- .../mgd-php@1/example/CRM/ShimmyGroup.mgd.php | 11 +++++ .../example/tests/mixin/ManagedTest.php | 40 ++++++++++++++++++ mixin/mgd-php@1/mixin.php | 42 +++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 mixin/mgd-php@1/example/CRM/ShimmyGroup.mgd.php create mode 100644 mixin/mgd-php@1/example/tests/mixin/ManagedTest.php create mode 100644 mixin/mgd-php@1/mixin.php diff --git a/mixin/mgd-php@1/example/CRM/ShimmyGroup.mgd.php b/mixin/mgd-php@1/example/CRM/ShimmyGroup.mgd.php new file mode 100644 index 0000000000..aa02376bdd --- /dev/null +++ b/mixin/mgd-php@1/example/CRM/ShimmyGroup.mgd.php @@ -0,0 +1,11 @@ + 'the_managed_group', + 'entity' => 'OptionGroup', + 'params' => [ + 'name' => 'shimmy_group', + 'title' => 'Shimmy Group', + ], + ], +]; diff --git a/mixin/mgd-php@1/example/tests/mixin/ManagedTest.php b/mixin/mgd-php@1/example/tests/mixin/ManagedTest.php new file mode 100644 index 0000000000..0ac5cc6579 --- /dev/null +++ b/mixin/mgd-php@1/example/tests/mixin/ManagedTest.php @@ -0,0 +1,40 @@ +assertFileExists(static::getPath('/CRM/ShimmyGroup.mgd.php'), 'The shimmy extension must have a Menu XML file.'); + } + + public function testInstalled($cv) { + $items = $cv->api4('OptionGroup', 'get', ['where' => [['name', '=', 'shimmy_group']]]); + $this->assertEquals('Shimmy Group', $items[0]['title']); + $this->assertEquals(TRUE, $items[0]['is_active']); + } + + public function testDisabled($cv) { + $items = $cv->api4('OptionGroup', 'get', ['where' => [['name', '=', 'shimmy_group']]]); + $this->assertEquals('Shimmy Group', $items[0]['title']); + $this->assertEquals(FALSE, $items[0]['is_active']); + } + + public function testUninstalled($cv) { + $items = $cv->api4('OptionGroup', 'get', ['where' => [['name', '=', 'shimmy_group']]]); + $this->assertEmpty($items); + } + + protected static function getPath($suffix = ''): string { + return dirname(__DIR__, 2) . $suffix; + } + +} diff --git a/mixin/mgd-php@1/mixin.php b/mixin/mgd-php@1/mixin.php new file mode 100644 index 0000000000..39d45b14ab --- /dev/null +++ b/mixin/mgd-php@1/mixin.php @@ -0,0 +1,42 @@ +addListener('hook_civicrm_managed', function ($event) use ($mixInfo) { + // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically. + if (!$mixInfo->isActive()) { + return; + } + + $mgdFiles = CRM_Utils_File::findFiles($mixInfo->getPath(), '*.mgd.php'); + sort($mgdFiles); + foreach ($mgdFiles as $file) { + $es = include $file; + foreach ($es as $e) { + if (empty($e['module'])) { + $e['module'] = $mixInfo->longName; + } + if (empty($e['params']['version'])) { + $e['params']['version'] = '3'; + } + $event->entities[] = $e; + } + } + }); + +}; -- 2.25.1