/** * @dataProvider datesProvider */ public function testDateValidation($start, $end, $pass, $expected_errors) { $worklist = new Worklist(); $worklist->setAttributes(array('start' => $start, 'end' => $end)); $res = $worklist->validate(array('start', 'end')); $this->assertEquals($pass, $res); $wl_errors = $worklist->getErrors(); if ($expected_errors) { foreach ($expected_errors as $fld => $errors) { $this->assertTrue(array_key_exists($fld, $wl_errors)); foreach ($errors as $error) { $this->assertTrue(in_array($error, $wl_errors[$fld])); } } } else { $this->assertTrue(empty($wl_errors)); } }
/** * @param Worklist $worklist * @param null $user * @param bool $display * * @return bool * * @throws CDbException */ public function createWorklistForUser(Worklist $worklist, $user = null, $display = true) { if (!$user) { $user = $this->getCurrentUser(); } $transaction = $this->startTransaction(); try { $worklist->created_user_id = $user->id; $worklist->last_modified_user_id = $user->id; // save call must force the parent class to accept the set owner id if (!$worklist->save(true, null, true)) { $this->addModelErrors($worklist->getErrors()); throw new Exception('Could not create Worklist.'); } if ($display) { if (!$this->addWorklistToUserDisplay($worklist, $user)) { throw new Exception('Could not set new worklist display order.'); } } $this->audit(self::$AUDIT_TARGET_MANUAL, 'create', array('worklist_id' => $worklist->id, 'owner_id' => $user->id), 'Worklist created.'); if ($transaction) { $transaction->commit(); } } catch (Exception $e) { $this->addError($e->getMessage()); if ($transaction) { $transaction->rollback(); } return false; } return true; }