From 60927523644f8855ef17f5e2661a0497bafa510e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 6 Jul 2022 20:15:14 -0700 Subject: [PATCH] mgd-php@1 - Add example+assertions for new case-type (but without a real `definition`) --- .../mgd-php@1/example/CRM/BunnyDance.mgd.php | 55 +++++++++++++++++ .../tests/mixin/ManagedCaseTypeTest.php | 59 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 mixin/mgd-php@1/example/CRM/BunnyDance.mgd.php create mode 100644 mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php diff --git a/mixin/mgd-php@1/example/CRM/BunnyDance.mgd.php b/mixin/mgd-php@1/example/CRM/BunnyDance.mgd.php new file mode 100644 index 0000000000..292b26373a --- /dev/null +++ b/mixin/mgd-php@1/example/CRM/BunnyDance.mgd.php @@ -0,0 +1,55 @@ + 'CaseType_BunnyDance', + 'entity' => 'CaseType', + 'cleanup' => 'unused', + 'update' => 'unmodified', + 'params' => [ + 'version' => 4, + 'values' => [ + 'name' => 'BunnyDance', + 'title' => 'Bunny Dance Case', + 'description' => 'The mysterious case of the dancing bunny', + 'is_active' => TRUE, + 'is_reserved' => TRUE, + 'weight' => 1, + // FIXME: At time of writing, if I create a full CaseType with a definition, then the system runs out of memory. + // 'definition' => [ + // 'activityTypes' => [ + // ['name' => 'Open Case', 'max_instances' => '1'], + // ['name' => 'Follow up'], + // ['name' => 'Change Case Type'], + // ['name' => 'Change Case Status'], + // ['name' => 'Change Case Start Date'], + // ['name' => 'Link Cases'], + // ['name' => 'Email'], + // ['name' => 'Meeting'], + // ['name' => 'Phone Call'], + // ['name' => 'Nibble'], + // ], + // 'activitySets' => [ + // [ + // 'name' => 'standard_timeline', + // 'label' => 'Standard Timeline', + // 'timeline' => 1, + // 'activityTypes' => [ + // ['name' => 'Open Case', 'status' => 'Completed'], + // ['name' => 'Phone Call', 'reference_offset' => '1', 'reference_select' => 'newest'], + // ['name' => 'Follow up', 'reference_offset' => '7', 'reference_select' => 'newest'], + // ], + // ], + // ], + // 'timelineActivityTypes' => [ + // ['name' => 'Open Case', 'status' => 'Completed'], + // ['name' => 'Phone Call', 'reference_offset' => '1', 'reference_select' => 'newest'], + // ['name' => 'Follow up', 'reference_offset' => '7', 'reference_select' => 'newest'], + // ], + // 'caseRoles' => [ + // ['name' => 'Case Coordinator', 'creator' => '1', 'manager' => '1'], + // ], + // ], + ], + ], + ], +]; diff --git a/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php b/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php new file mode 100644 index 0000000000..270a5faf7a --- /dev/null +++ b/mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php @@ -0,0 +1,59 @@ +assertFileExists(static::getPath('/CRM/BunnyDance.mgd.php'), 'The shimmy extension must have a Case MGD file.'); + } + + public function testInstalled($cv) { + $items = $cv->api4('CaseType', 'get', ['where' => [['name', '=', 'BunnyDance']]]); + $this->assertEquals('The mysterious case of the dancing bunny', $items[0]['description']); + $this->assertEquals('BunnyDance', $items[0]['name']); + $this->assertEquals('Bunny Dance Case', $items[0]['title']); + $this->assertEquals(TRUE, $items[0]['is_active']); + $this->assertEquals(1, count($items)); + + // FIXME: The example is partially disabled - because the full example causes a crash. + // Hence, these assertions don't yet pass. + // $actTypes = $cv->api4('OptionValue', 'get', [ + // 'where' => [['option_group_id:name', '=', 'activity_type'], ['name', '=', 'Nibble']], + // ]); + // $this->assertEquals('Nibble', $actTypes[0]['name'], 'ActivityType "Nibble" should be auto enabled. It\'s missing.'); + // $this->assertEquals(TRUE, $actTypes[0]['is_active'], 'ActivityType "Nibble" should be auto enabled. It\'s inactive.'); + } + + public function testDisabled($cv) { + $items = $cv->api4('CaseType', 'get', ['where' => [['name', '=', 'BunnyDance']]]); + $this->assertEquals('The mysterious case of the dancing bunny', $items[0]['description']); + $this->assertEquals('BunnyDance', $items[0]['name']); + $this->assertEquals('Bunny Dance Case', $items[0]['title']); + $this->assertEquals(FALSE, $items[0]['is_active']); + $this->assertEquals(1, count($items)); + } + + public function testUninstalled($cv) { + $items = $cv->api4('CaseType', 'get', ['where' => [['name', '=', 'BunnyDance']]]); + $this->assertEquals(0, count($items)); + + $actTypes = $cv->api4('OptionValue', 'get', [ + 'where' => [['option_group_id:name', '=', 'activity_type'], ['name', '=', 'Nibble']], + ]); + $this->assertEmpty($actTypes); + } + + protected static function getPath($suffix = ''): string { + return dirname(__DIR__, 2) . $suffix; + } + +} -- 2.25.1