public function test_array_search_insensitive() { $arrayLowerCase = array("alpha", "bravo", "charlie", "delta", "echo"); $arrayUpperCase = array("ALPHA", "BRAVO", "CHARLIE", "DELTA", "ECHO"); $arrayMixed = array("Alpha", "Bravo", "Charlie", "Delta", "Echo"); $arrayEmpty = array(); $this->assertTrue(array_search_insensitive("delta", $arrayLowerCase)); $this->assertTrue(array_search_insensitive("delta", $arrayUpperCase)); $this->assertTrue(array_search_insensitive("delta", $arrayMixed)); $this->assertFalse(array_search_insensitive("delta", $arrayEmpty)); }
/** * This function will return all the accounts this user has access to based on the * match of the emailId passed in as a parameter * * @param unknown_type $ie * @return unknown */ function getFromAllAccountsArray($ie, $ret) { global $current_user; global $app_strings; $ret['fromAccounts'] = array(); if (!isset($ret['to']) && !empty($ret['from'])) { $ret['fromAccounts']['status'] = false; return $ret; } $ieAccountsFull = $ie->retrieveAllByGroupIdWithGroupAccounts($current_user->id); $foundInPersonalAccounts = false; $foundInGroupAccounts = false; $foundInSystemAccounts = false; //$toArray = array(); if ($ret['type'] == "draft") { $toArray = explode(",", $ret['from']); } else { $toArray = $ie->email->email2ParseAddressesForAddressesOnly($ret['to']); } // else foreach ($ieAccountsFull as $k => $v) { $storedOptions = unserialize(base64_decode($v->stored_options)); if (array_search_insensitive($storedOptions['from_addr'], $toArray)) { if ($v->is_personal) { $foundInPersonalAccounts = true; break; } else { $foundInGroupAccounts = true; } // else } // if } // foreach $oe = new OutboundEmail(); $system = $oe->getSystemMailerSettings(); $return = $current_user->getUsersNameAndEmail(); $return['name'] = from_html($return['name']); $useMyAccountString = true; if (empty($return['email'])) { $systemReturn = $current_user->getSystemDefaultNameAndEmail(); $return['email'] = $systemReturn['email']; $return['name'] = from_html($systemReturn['name']); $useMyAccountString = false; } // if $myAccountString = ''; if ($useMyAccountString) { $myAccountString = " - {$app_strings['LBL_MY_ACCOUNT']}"; } // if if (!empty($system->id)) { $admin = new Administration(); $admin->retrieveSettings(); //retrieve all admin settings. if (in_array(trim($return['email']), $toArray)) { $foundInSystemAccounts = true; } // if } // if if (!$foundInPersonalAccounts && !$foundInGroupAccounts && !$foundInSystemAccounts) { $ret['fromAccounts']['status'] = false; return $ret; } // if $ieAccountsFrom = array(); foreach ($ieAccountsFull as $k => $v) { $storedOptions = unserialize(base64_decode($v->stored_options)); $storedOptionsName = from_html($storedOptions['from_name']); $selected = false; if (array_search_insensitive($storedOptions['from_addr'], $toArray)) { //if ($ret['to'] == $storedOptions['from_addr']) { $selected = true; } // if if ($foundInPersonalAccounts) { if ($v->is_personal) { $ieAccountsFrom[] = array("value" => $v->id, "selected" => $selected, "text" => "{$storedOptionsName} ({$storedOptions['from_addr']})"); } // if } else { $ieAccountsFrom[] = array("value" => $v->id, "selected" => $selected, "text" => "{$storedOptionsName} ({$storedOptions['from_addr']}) - {$app_strings['LBL_EMAIL_UPPER_CASE_GROUP']}"); } // else } // foreach if (!empty($system->id)) { if (!$foundInPersonalAccounts && !$foundInGroupAccounts && $foundInSystemAccounts) { $ieAccountsFrom[] = array("value" => $system->id, "selected" => true, "text" => "{$return['name']} ({$return['email']}){$myAccountString}"); } else { $ieAccountsFrom[] = array("value" => $system->id, "text" => "{$return['name']} ({$return['email']}){$myAccountString}"); } // else } // if $ret['fromAccounts']['status'] = $foundInPersonalAccounts || $foundInGroupAccounts || $foundInSystemAccounts ? true : false; $ret['fromAccounts']['data'] = $ieAccountsFrom; return $ret; }
public function testarray_search_insensitive() { //execute the method and test if it returns expected value //test with invalid input $tempArray = ''; $actual = array_search_insensitive('', $tempArray); $this->assertFalse($actual); //test with invalid needle.. $tempArray = array('Key1' => 'value1', 'Key2' => 'value2', 'Key3' => 'value3', 'key4' => 'value4'); $actual = array_search_insensitive('', $tempArray); $this->assertFalse($actual); //test with valid needle and haystack. $tempArray = array('Key1' => 'value1', 'Key2' => 'value2', 'Key3' => 'value3', 'key4' => 'value4'); $actual = array_search_insensitive('value4', $tempArray); $this->assertTrue($actual); //var_dump($actual); }