/** * Provide validation for select criteria coming from the client; currently only supports startDate and endDate. * startDate & endDate are expected to be epoch (? or perhaps ISO-8601) * * @param array $selectCriteria * @return bool * * @throws \InvalidArgumentException */ protected function validateSelectCriteria($selectCriteria) { // If we didn't get any criteria, or we didn't get any date criteria, we'll consider it validated for now if (is_array($selectCriteria) && count($selectCriteria) == 0 || !isset($selectCriteria[self::START_DATE_ATTRIBUTE]) && !isset($selectCriteria[self::END_DATE_ATTRIBUTE])) { return true; } // We _could_ treat a solo startDate as a single-day option here. if (!ArrayUtil::checkBothExist($selectCriteria, self::START_DATE_ATTRIBUTE, self::END_DATE_ATTRIBUTE)) { throw new \InvalidArgumentException("Both startDate and endDate need to be supplied."); } // Will throw an \InvalidParameterException if anything goes wrong. list($startDate, $endDate) = $this->checkDateValidity($selectCriteria[self::START_DATE_ATTRIBUTE], $selectCriteria[self::END_DATE_ATTRIBUTE]); $this->checkDateBounds($startDate, $endDate); return true; }
/** * @group FL-1161 * @group FL-1236 */ function testCheckBothExistOnBothParamsMissing() { $testArray = []; $dateTest = ArrayUtil::checkBothExist($testArray, 'startDate', 'endDate'); $this->assertFalse($dateTest, "Neither parameter existed, checkBothExist should return false."); }