mgd-php@1 - Add example+assertions for new case-type (but without a real `definition`)
authorTim Otten <totten@civicrm.org>
Thu, 7 Jul 2022 03:15:14 +0000 (20:15 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 7 Jul 2022 04:07:08 +0000 (21:07 -0700)
mixin/mgd-php@1/example/CRM/BunnyDance.mgd.php [new file with mode: 0644]
mixin/mgd-php@1/example/tests/mixin/ManagedCaseTypeTest.php [new file with mode: 0644]

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 (file)
index 0000000..292b263
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+return [
+  [
+    'name' => '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 (file)
index 0000000..270a5fa
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+namespace Civi\Shimmy\Mixins;
+
+/**
+ * Assert that the mgd-php mixin is picking the case-type and all its related data.
+ *
+ * This class defines the assertions to run when installing or uninstalling the extension.
+ * It use called as part of E2E_Shimmy_LifecycleTest.
+ *
+ * @see E2E_Shimmy_LifecycleTest
+ */
+class ManagedCaseTypeTest extends \PHPUnit\Framework\Assert {
+
+  public function testPreConditions($cv) {
+    $this->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;
+  }
+
+}