/** * Tests the stage_checkbox function * $start coming out as $expected will tell us that it works as expected * with both existing and non-existant keys */ function testStageCheckbox() { $start = array('bears' => 'green', 'emus' => 'purple'); $expected = array('bears' => 1, 'emus' => 'purple'); ContributionTrackingProcessor::stage_checkbox($start, 'bears'); ContributionTrackingProcessor::stage_checkbox($start, 'llamas'); $this->assertEquals($start, $expected, "stage_checkbox is not working as expected."); }
/** * There are a few values that come in, which are both generated by * checkboxes, and are the exact inverse of the way we save them in the * table. * For these values, if the key exists (and is not explicit false), it is * received as "true". Therefore, the rekey'd value should be false. * However, the old key not existing isn't exactly conclusive. * @param array $array The array to rekey (by reference) * @param string $oldkey The key to change * @param string $invertedkey The key meant to contain the inverted boolean * of the old key. */ static function rekey_invert_boolean(&$array, $oldkey, $invertedkey) { if (array_key_exists($oldkey, $array)) { if ($array[$oldkey] !== false) { unset($array[$oldkey]); $array[$invertedkey] = false; } else { $array[$invertedkey] = 1; } return; } if (array_key_exists($invertedkey, $array)) { ContributionTrackingProcessor::stage_checkbox($array, $invertedkey); return; } //at this point, neither key exists. We go with the default. $default = ContributionTrackingProcessor::getContributionDefaults(); if (array_key_exists($invertedkey, $default)) { $array[$invertedkey] = $default[$invertedkey]; } }