Skip to content

Commit

Permalink
CRM-19930: Test toArray() function with param
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendrapurohit committed Jan 25, 2017
1 parent 6ad5cf3 commit e1047fa
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/phpunit/CRM/Core/DAOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,35 @@ public function testMyISAMCheck() {
CRM_Core_DAO::executeQuery("DROP TABLE $tempName");
}

/**
* CRM-19930: Test toArray() function with $format param
*/
public function testDAOtoArray() {
$format = 'user[%s]';
$params = array(
'first_name' => 'Testy',
'last_name' => 'McScallion',
'contact_type' => 'Individual',
);

$dao = CRM_Contact_BAO_Contact::add($params);
$query = "SELECT contact_type, display_name FROM civicrm_contact WHERE id={$dao->id}";
$toArray = array(
'contact_type' => 'Individual',
'display_name' => 'Testy McScallion',
);
$modifiedKeyArray = array();
foreach ($toArray as $k => $v) {
$modifiedKeyArray[sprintf($format, $k)] = $v;
}

$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$daoToArray = $dao->toArray();
$this->checkArrayEquals($toArray, $daoToArray);
$daoToArray = $dao->toArray($format);
$this->checkArrayEquals($modifiedKeyArray, $daoToArray);
}
}

}

0 comments on commit e1047fa

Please sign in to comment.