From 7d0c4217b44d587e42a09b06718764133392f610 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 20 Apr 2019 13:50:28 +1000 Subject: [PATCH] (NFC) Add tests of retreiving notes for display on a contact record and returning DedupeExecptions for output on page Update Unit test to check output of note browse as well --- CRM/Contact/Page/DedupeException.php | 5 +- CRM/Contact/Page/View/Note.php | 29 ++++--- .../CRM/Contact/Page/DedupeExceptionTest.php | 84 +++++++++++++++++++ .../CRM/Contact/Page/View/NoteTest.php | 80 ++++++++++++++++++ 4 files changed, 182 insertions(+), 16 deletions(-) create mode 100644 tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php create mode 100644 tests/phpunit/CRM/Contact/Page/View/NoteTest.php diff --git a/CRM/Contact/Page/DedupeException.php b/CRM/Contact/Page/DedupeException.php index cb73cb3c20..48452d215d 100644 --- a/CRM/Contact/Page/DedupeException.php +++ b/CRM/Contact/Page/DedupeException.php @@ -81,10 +81,9 @@ class CRM_Contact_Page_DedupeException extends CRM_Core_Page { /** * Function to get the exceptions * - * @return array $exceptions - * @access protected + * @return array $exceptionsd */ - protected function getExceptions() { + public function getExceptions() { list($offset, $limit) = $this->_pager->getOffsetAndRowCount(); $contactOneQ = CRM_Utils_Request::retrieve('crmContact1Q', 'String'); diff --git a/CRM/Contact/Page/View/Note.php b/CRM/Contact/Page/View/Note.php index 2930341be7..9fe30dc03b 100644 --- a/CRM/Contact/Page/View/Note.php +++ b/CRM/Contact/Page/View/Note.php @@ -50,6 +50,12 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page { */ public static $_commentLinks = NULL; + /** + * Notes found running the browse function + * @var array + */ + public $values = []; + /** * View details of a note. */ @@ -57,14 +63,13 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page { $note = new CRM_Core_DAO_Note(); $note->id = $this->_id; if ($note->find(TRUE)) { - $values = []; - CRM_Core_DAO::storeValues($note, $values); - $values['privacy'] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Note', 'privacy', $values['privacy']); - $this->assign('note', $values); + CRM_Core_DAO::storeValues($note, $this->values); + $this->values['privacy'] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Note', 'privacy', $this->values['privacy']); + $this->assign('note', $this->values); } - $comments = CRM_Core_BAO_Note::getNoteTree($values['id'], 1); + $comments = CRM_Core_BAO_Note::getNoteTree($this->values['id'], 1); if (!empty($comments)) { $this->assign('comments', $comments); } @@ -96,16 +101,15 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page { $this->assign('canAddNotes', CRM_Core_Permission::check('add contact notes')); - $values = []; $links = self::links(); $action = array_sum(array_keys($links)) & $mask; $note->find(); while ($note->fetch()) { if (!CRM_Core_BAO_Note::getNotePrivacyHidden($note)) { - CRM_Core_DAO::storeValues($note, $values[$note->id]); + CRM_Core_DAO::storeValues($note, $this->values[$note->id]); - $values[$note->id]['action'] = CRM_Core_Action::formLink($links, + $this->values[$note->id]['action'] = CRM_Core_Action::formLink($links, $action, [ 'id' => $note->id, @@ -122,17 +126,16 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page { $contact->id = $note->contact_id; $contact->find(); $contact->fetch(); - $values[$note->id]['createdBy'] = $contact->display_name; + $this->values[$note->id]['createdBy'] = $contact->display_name; } - $values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id); + $this->values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id); // paper icon view for attachments part $paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id); - $values[$note->id]['attachment'] = $paperIconAttachmentInfo; + $this->values[$note->id]['attachment'] = $paperIconAttachmentInfo; } } - - $this->assign('notes', $values); + $this->assign('notes', $this->values); $commentLinks = self::commentLinks(); diff --git a/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php new file mode 100644 index 0000000000..c67b49bcf4 --- /dev/null +++ b/tests/phpunit/CRM/Contact/Page/DedupeExceptionTest.php @@ -0,0 +1,84 @@ +individualCreate(); + $contact2 = $this->individualCreate(); + $exception = $this->callAPISuccess('Exception', 'create', [ + 'contact_id1' => $contact1, + 'contact_id2' => $contact2, + ]); + $page = new CRM_Contact_Page_DedupeException(); + $totalitems = civicrm_api3('Exception', "getcount", []); + $params = array( + 'total' => $totalitems, + 'rowCount' => CRM_Utils_Pager::ROWCOUNT, + 'status' => ts('Dedupe Exceptions %%StatusMessage%%'), + 'buttonBottom' => 'PagerBottomButton', + 'buttonTop' => 'PagerTopButton', + 'pageID' => $page->get(CRM_Utils_Pager::PAGE_ID), + ); + $page->_pager = new CRM_Utils_Pager($params); + $exceptions = $page->getExceptions(); + $expectedArray = [ + $exception['id'] => [ + 'id' => $exception['id'], + 'contact_id1.display_name' => 'Mr. Anthony Anderson II', + 'contact_id2.display_name' => 'Mr. Anthony Anderson II', + 'contact_id1' => $contact1, + 'contact_id2' => $contact2, + ], + ]; + $this->assertEquals($expectedArray, $exceptions); + } + +} diff --git a/tests/phpunit/CRM/Contact/Page/View/NoteTest.php b/tests/phpunit/CRM/Contact/Page/View/NoteTest.php new file mode 100644 index 0000000000..4a3943641e --- /dev/null +++ b/tests/phpunit/CRM/Contact/Page/View/NoteTest.php @@ -0,0 +1,80 @@ +individualCreate(); + foreach ([1, 2, 3, 4, 5] as $noteID) { + $note = new CRM_Core_DAO_Note(); + $note->entity_id = $contactId; + $note->subject = 'Test Note ' . $noteID; + $note->note = 'Test Note from Tests'; + $note->entity_table = 'civicrm_contact'; + if ($noteID == 5) { + $note->contact_id = $contactId; + } + $note->save(); + } + $page = new CRM_Contact_Page_View_Note(); + $page->_contactId = $contactId; + $page->_permission = CRM_Core_PERMISSION::EDIT; + $page->browse(); + $this->assertEquals(count($page->values), 5); + foreach ($page->values as $note) { + $this->assertEquals($note['entity_id'], $contactId); + if ($note['id'] == 5) { + $this->assertEquals($note['createdBy'], 'Mr. Anthony Anderson II'); + } + } + } + +} -- 2.25.1