CRM-13149 additional test on api array as filter syntax
authoreileen <eileen@fuzion.co.nz>
Fri, 2 Aug 2013 11:47:10 +0000 (23:47 +1200)
committereileen <eileen@fuzion.co.nz>
Fri, 2 Aug 2013 11:47:10 +0000 (23:47 +1200)
tests/phpunit/api/v3/RelationshipTest.php

index f3e31f18f9cc41a1165efa40dd1295380f683d67..c2c864b6ada7ca5adad10daa9eee0462a72cbbc0 100644 (file)
@@ -924,5 +924,43 @@ class api_v3_RelationshipTest extends CiviUnitTestCase {
       $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
     }
   }
+
+  /**
+   * Checks that passing in 'contact_id_b' + a relationship type
+   * will filter by relationship type for contact b
+   *
+   * We should get 1 result without or with correct relationship type id & 0 with
+   * an incorrect one
+   */
+  function testGetRelationshipByTypeArrayReciprocal() {
+    $created = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+    $org3 = $this->organizationCreate();
+    $relType2 = 5; // lets just assume built in ones aren't being messed with!
+    $relType3 = 6; // lets just assume built in ones aren't being messed with!
+
+    //relationshp 2
+    $this->callAPISuccess($this->_entity, 'create',
+      array_merge($this->_params, array(
+        'relationship_type_id' => $relType2,
+        'contact_id_b' => $this->_cId_b2))
+    );
+
+    //relationshp 3
+    $this->callAPISuccess($this->_entity, 'create',
+      array_merge($this->_params, array(
+        'relationship_type_id' => $relType3,
+        'contact_id_b' => $org3))
+    );
+
+    $result = $this->callAPISuccess($this->_entity, 'get', array(
+      'contact_id' => $this->_cId_a,
+      'relationship_type_id' => array('IN' => array($this->_relTypeID, $relType3)),
+    ));
+
+    $this->assertEquals(2, $result['count']);
+    foreach ($result['values'] as $key => $value) {
+      $this->assertTrue(in_array($value['relationship_type_id'], array($this->_relTypeID, $relType3)));
+    }
+  }
 }