Merge pull request #10393 from JMAConsulting/exportBatch
[civicrm-core.git] / tests / phpunit / api / v3 / NoteTest.php
index e0e6fd63b650bf7bb6af9aa89e6e5d8f5dc8321b..71c6f6f7fbe2c1166e9e8f21fced1ec3c85c8abe 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -137,10 +137,6 @@ class api_v3_NoteTest extends CiviUnitTestCase {
     $this->assertEquals(date('Y-m-d', strtotime($this->_params['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date'])));
 
     $this->assertArrayHasKey('id', $result);
-    $note = array(
-      'id' => $result['id'],
-    );
-    $this->noteDelete($note);
   }
 
   public function testCreateWithApostropheInString() {
@@ -158,12 +154,6 @@ class api_v3_NoteTest extends CiviUnitTestCase {
     $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note");
     $this->assertEquals($result['values'][0]['subject'], "With a '");
     $this->assertArrayHasKey('id', $result);
-
-    //CleanUP
-    $note = array(
-      'id' => $result['id'],
-    );
-    $this->noteDelete($note);
   }
 
   /**
@@ -174,9 +164,6 @@ class api_v3_NoteTest extends CiviUnitTestCase {
     $apiResult = $this->callAPISuccess('note', 'create', $this->_params);
     $this->assertAPISuccess($apiResult);
     $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
-    $this->noteDelete(array(
-      'id' => $apiResult['id'],
-    ));
   }
 
   /**
@@ -259,6 +246,32 @@ class api_v3_NoteTest extends CiviUnitTestCase {
     $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__);
   }
 
+  public function testNoteJoin() {
+    $org = $this->callAPISuccess('Contact', 'create', array(
+      'contact_type' => 'Organization',
+      'organization_name' => 'Org123',
+      'api.Note.create' => array(
+        'note' => 'Hello join',
+      ),
+    ));
+    // Fetch contact info via join
+    $result = $this->callAPISuccessGetSingle('Note', array(
+      'return' => array("entity_id.organization_name", "note"),
+      'entity_id' => $org['id'],
+      'entity_table' => "civicrm_contact",
+    ));
+    $this->assertEquals('Org123', $result['entity_id.organization_name']);
+    $this->assertEquals('Hello join', $result['note']);
+    // This should return no results by restricting contact_type
+    $result = $this->callAPISuccess('Note', 'get', array(
+      'return' => array("entity_id.organization_name"),
+      'entity_id' => $org['id'],
+      'entity_table' => "civicrm_contact",
+      'entity_id.contact_type' => "Individual",
+    ));
+    $this->assertEquals(0, $result['count']);
+  }
+
 }
 
 /**