_apiversion = 3; // Connect to the database. parent::setUp(); $this->useTransaction(TRUE); $this->_contactID = $this->organizationCreate(NULL); $this->_params = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactID, 'note' => 'Hello!!! m testing Note', 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => 'Test Note', ); $this->_note = $this->noteCreate($this->_contactID); $this->_noteID = $this->_note['id']; } ///////////////// civicrm_note_get methods /** * Check retrieve note with empty parameter array. * * Error expected */ public function testGetWithEmptyParams() { $this->callAPISuccess('note', 'get', array()); } /** * Check retrieve note with missing parameters. * * Error expected */ public function testGetWithoutEntityId() { $params = array( 'entity_table' => 'civicrm_contact', ); $this->callAPISuccess('note', 'get', $params); } /** * Check civicrm_note get. */ public function testGet() { $entityId = $this->_noteID; $params = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $entityId, ); $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); } /** * Check create with empty parameter array. * * Error Expected */ public function testCreateWithEmptyNoteField() { $this->_params['note'] = ""; $this->callAPIFailure('note', 'create', $this->_params, 'Mandatory key(s) missing from params array: note' ); } /** * Check create with partial params. * * Error expected */ public function testCreateWithoutEntityId() { unset($this->_params['entity_id']); $this->callAPIFailure('note', 'create', $this->_params, 'Mandatory key(s) missing from params array: entity_id'); } /** * Check create with partially empty params. * * Error expected */ public function testCreateWithEmptyEntityId() { $this->_params['entity_id'] = ""; $this->callAPIFailure('note', 'create', $this->_params, 'Mandatory key(s) missing from params array: entity_id'); } /** * Check civicrm note create. */ public function testCreate() { $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note'); $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); } public function testCreateWithApostropheInString() { $params = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactID, 'note' => "Hello!!! ' testing Note", 'contact_id' => $this->_contactID, 'modified_date' => '2011-01-31', 'subject' => "With a '", 'sequential' => 1, ); $result = $this->callAPISuccess('Note', 'Create', $params); $this->assertAPISuccess($result); $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note"); $this->assertEquals($result['values'][0]['subject'], "With a '"); $this->assertArrayHasKey('id', $result); } /** * Check civicrm_note_create - tests used of default set to . */ public function testCreateWithoutModifiedDate() { unset($this->_params['modified_date']); $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']))); } /** * Check update with empty parameter array. * * Please don't copy & paste this - is of marginal value * better to put time into the function on Syntax Conformance class that tests this */ public function testUpdateWithEmptyParams() { $this->callAPIFailure('note', 'create', array()); } /** * Check update with missing parameter (contact id). * * Error expected */ public function testUpdateWithoutContactId() { $params = array( 'entity_id' => $this->_contactID, 'entity_table' => 'civicrm_contact', ); $this->callAPIFailure('note', 'create', $params, 'Mandatory key(s) missing from params array: note' ); } /** * Check civicrm_note update. */ public function testUpdate() { $params = array( 'id' => $this->_noteID, 'contact_id' => $this->_contactID, 'note' => 'Note1', 'subject' => 'Hello World', ); // Update Note. $this->callAPISuccess('note', 'create', $params); $note = $this->callAPISuccess('Note', 'Get', array()); $this->assertEquals($note['id'], $this->_noteID); $this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID); $this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact'); $this->assertEquals('Hello World', $note['values'][$this->_noteID]['subject']); $this->assertEquals('Note1', $note['values'][$this->_noteID]['note']); } /** * Check delete with empty parameters array. * * Error expected. */ public function testDeleteWithEmptyParams() { $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); } /** * Check delete with wrong id. * * Error expected */ public function testDeleteWithWrongID() { $params = array( 'id' => 99999, ); $this->callAPIFailure('note', 'delete', $params, 'Error while deleting Note'); } /** * Check civicrm_note delete. */ public function testDelete() { $additionalNote = $this->noteCreate($this->_contactID); $params = array( 'id' => $additionalNote['id'], ); $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']); } } /** * Test civicrm note create() using example code. */ function testNoteCreateExample() { require_once 'api/v3/examples/Note/Create.php'; $result = Note_get_example(); $expectedResult = Note_get_expectedresult(); $this->assertEquals($result, $expectedResult); }