Eileen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249956

Change subject: Add test for Fix thank_you to not use ported 4.2 custom api
......................................................................

Add test for Fix thank_you to not use ported 4.2 custom api

T117143

Change-Id: Ic5db39ce9828809d26a3f8b1394b7b8a4106573d
---
M sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
1 file changed, 52 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/56/249956/1

diff --git 
a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php 
b/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
index cca3ad1..7c202ad 100644
--- a/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
+++ b/sites/all/modules/wmf_civicrm/tests/phpunit/HelperFunctionsTest.php
@@ -46,4 +46,56 @@
         $this->assertEquals(1, $languages['count']);
     }
 
+    /**
+     * Test wmf custom api entity get detail.
+     *
+     * @todo consider moving test to thank_you module or helper function out 
of there.
+     *
+     * @throws \CiviCRM_API3_Exception
+     */
+    public function testGetEntityTagDetail() {
+        civicrm_initialize();
+        $contact = $this->callAPISuccess('Contact', 'create', array(
+            'first_name' => 'Papa',
+            'last_name' => 'Smurf',
+            'contact_type' => 'Individual',
+        ));
+        $contribution = $this->callAPISuccess('Contribution', 'create', array(
+            'contact_id' => $contact['id'],
+            'total_amount' => 40,
+            'financial_type_id' => 'Donation',
+        ));
+
+        $tag1 = $this->ensureTagExists('smurfy');
+        $tag2 = $this->ensureTagExists('smurfalicious');
+
+        $this->callAPISuccess('EntityTag', 'create', array('entity_id' => 
$contribution['id'], 'entity_table' => 'civicrm_contribution', 'tag_id' => 
'smurfy'));
+        $this->callAPISuccess('EntityTag', 'create', array('entity_id' => 
$contribution['id'], 'entity_table' => 'civicrm_contribution', 'tag_id' => 
'smurfalicious'));
+
+        $smurfiestTags = wmf_thank_you_get_tag_names($contribution['id']);
+        $this->assertEquals(array('smurfy', 'smurfalicious'), $smurfiestTags);
+
+        $this->callAPISuccess('Tag', 'delete', array('id' => $tag1));
+        $this->callAPISuccess('Tag', 'delete', array('id' => $tag2));
+    }
+
+    /**
+     * Helper function to protect test against cleanup issues.
+     *
+     * @param string $name
+     * @return int
+     */
+    public function ensureTagExists($name) {
+        $tags = $this->callAPISuccess('EntityTag', 'getoptions', array('field' 
=> 'tag_id'));
+        if (in_array($name, $tags['values'])) {
+            return array_search($name, $tags['values']);
+        }
+        $tag = $this->callAPISuccess('Tag', 'create', array(
+            'used_for' => 'civicrm_contribution',
+            'name' => $name
+        ));
+
+        return $tag['id'];
+    }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/249956
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5db39ce9828809d26a3f8b1394b7b8a4106573d
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master-plus-4.6.9
Gerrit-Owner: Eileen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to