From 148dab945c45e52861f4b9cdac9e49be32c886c7 Mon Sep 17 00:00:00 2001
From: Seamus Lee <seamuslee001@gmail.com>
Date: Tue, 19 Sep 2017 09:02:23 +1000
Subject: [PATCH] Migrate CiviTest Examples for two hooks that still reference
 them

---
 docs/hooks/hook_civicrm_dashboard.md          | 45 +++++++++++-------
 .../hook_civicrm_emailProcessorContact.md     | 46 ++++++++++++++++++-
 2 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/docs/hooks/hook_civicrm_dashboard.md b/docs/hooks/hook_civicrm_dashboard.md
index dff90e68..c958b056 100644
--- a/docs/hooks/hook_civicrm_dashboard.md
+++ b/docs/hooks/hook_civicrm_dashboard.md
@@ -25,20 +25,31 @@ used to add content to the dashboard page.
 -   the HTML to include in the dashboard
 
 ## Example
-
-    function civitest_civicrm_dashboard( $contactID, &$contentPlacement ) {
-        // REPLACE Activity Listing with custom content
-        $contentPlacement = 3;
-        return array( 'Custom Content' => "Here is some custom content: $contactID",
-                      'Custom Table' => "
-    <table>
-    <tr><th>Contact Name</th><th>Date</th></tr>
-    <tr><td>Foo</td><td>Bar</td></tr>
-    <tr><td>Goo</td><td>Tar</td></tr>
-    </table>
-    ",
-                      );
-    }
-
-Also check [Civitest Sample
-Module](http://svn.civicrm.org/civicrm/branches/v2.2/drupal/civitest.module.sample)
\ No newline at end of file
+```php
+function civitest_civicrm_dashboard($contactID, &$contentPlacement) {
+  // REPLACE Activity Listing with custom content
+  $contentPlacement = 3;
+  $content = array(
+    'Custom Content' => "Here is some custom content: $contactID",
+    'Custom Table' => "
+      <table>
+      <tr><th>Contact Name</th><th>Date</th></tr>
+      <tr><td>Foo</td><td>Bar</td></tr>
+      <tr><td>Goo</td><td>Tar</td></tr>
+      </table>",
+  );
+  return $content;
+}
+```
+### CiviTest example
+```php
+function civitest_civicrm_dashboard_defaults($availableDashlets, &$defaultDashlets){
+  $contactID = CRM_Core_Session::singleton()->get('userID');
+  $defaultDashlets[] = array(
+    'dashboard_id' => 3,
+    'is_active' => 1,
+    'column_no' => 1,
+    'contact_id' => $contactID,
+  );
+}
+```
diff --git a/docs/hooks/hook_civicrm_emailProcessorContact.md b/docs/hooks/hook_civicrm_emailProcessorContact.md
index c24ac96c..efe5feac 100644
--- a/docs/hooks/hook_civicrm_emailProcessorContact.md
+++ b/docs/hooks/hook_civicrm_emailProcessorContact.md
@@ -44,4 +44,48 @@ This hook was first available in CiviCRM 4.1.0
 
 ## Example
 
-See civitest.module.sample.
\ No newline at end of file
+```php
+function civitest_civicrm_emailProcessorContact( $email, $contactID, &$result ) {
+  require_once 'CRM/Utils/Mail/Incoming.php';
+
+  // first split the email into name and domain
+  // really simple, definitely wrong implementation
+  list($mailName, $mailDomain) = CRM_Utils_System::explode('@', $email, 2);
+
+  // we are doing all our checks based on mailDomain, so if empty
+  // return and let EmailProcessor do its own thing
+  if (empty($mailDomain)) {
+    return;
+  }
+
+  define('FILE_TO_ORG_ALWAYS_TAG', 'MyTag1');
+  $orgID = _civitest_find_org_with_tag(FILE_TO_ORG_ALWAYS_TAG, $mailDomain);
+  if ($orgID) {
+    $result = array(
+      'contactID' => $orgID,
+      'action' => CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE,
+    );
+    return;
+  }
+
+  // if we already have a match, we will
+  // return and let EmailProcessor do its own thing
+  if ($contactID) {
+    return;
+  }
+
+  // Orgs with this tag will have same-domain emails filed on them only if it
+  // passes through the ALWAYS tag check without finding a match, AND it does
+  // not match an individual.
+  define('FILE_TO_ORG_INDIVIDUAL_UNMATCHED_TAG', 'MyTag2');
+  $orgID = _civitest_find_org_with_tag(FILE_TO_ORG_INDIVIDUAL_UNMATCHED_TAG, $mailDomain);
+  if ($orgID) {
+    $result = array(
+      'contactID' => $orgID,
+      'action' => CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE);
+    return;
+  }
+
+  $result = array('action' => CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL);
+}
+```
-- 
GitLab