mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-09 14:18:59 +00:00
Updated tests.
This commit is contained in:
@@ -8,6 +8,7 @@ use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Database\SwitchUser;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
@@ -29,11 +30,11 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Eloquent $model
|
||||
* @param Eloquent $model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(\Eloquent $model)
|
||||
public function destroy(Eloquent $model)
|
||||
{
|
||||
$model->delete();
|
||||
|
||||
@@ -74,12 +75,12 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Eloquent $model
|
||||
* @param array $data
|
||||
* @param Eloquent $model
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(\Eloquent $model, array $data)
|
||||
public function update(Eloquent $model, array $data)
|
||||
{
|
||||
$model->name = $data['name'];
|
||||
$model->match = $data['match'];
|
||||
@@ -113,45 +114,13 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
$errors = new MessageBag;
|
||||
|
||||
if (isset($model['name']) && strlen($model['name']) == 0) {
|
||||
$errors->add('name', 'Name must be longer.');
|
||||
}
|
||||
if (isset($model['name']) && strlen($model['name']) > 200) {
|
||||
$errors->add('name', 'Name must be shorter.');
|
||||
}
|
||||
|
||||
if (isset($model['match']) && strlen(trim($model['match'])) <= 2) {
|
||||
$errors->add('match', 'Needs more matches.');
|
||||
}
|
||||
|
||||
if (isset($model['amount_min']) && floatval($model['amount_min']) < 0.01) {
|
||||
$errors->add('amount_min', 'Minimum amount must be higher.');
|
||||
}
|
||||
if (isset($model['amount_max']) && floatval($model['amount_max']) < 0.02) {
|
||||
$errors->add('amount_max', 'Maximum amount must be higher.');
|
||||
}
|
||||
if (isset($model['amount_min']) && isset($model['amount_max']) && floatval($model['amount_min']) > floatval($model['amount_max'])) {
|
||||
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
|
||||
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
|
||||
}
|
||||
|
||||
if ($model['date'] != '') {
|
||||
try {
|
||||
new Carbon($model['date']);
|
||||
} catch (\Exception $e) {
|
||||
$errors->add('date', 'Invalid date.');
|
||||
}
|
||||
}
|
||||
|
||||
$reminders = \Config::get('firefly.budget_periods');
|
||||
if (!isset($model['repeat_freq']) || (isset($model['repeat_freq']) && !in_array($model['repeat_freq'], $reminders))) {
|
||||
$errors->add('repeat_freq', 'Invalid reminder period');
|
||||
}
|
||||
|
||||
if (isset($model['skip']) && intval($model['skip']) < 0) {
|
||||
$errors->add('skip', 'Invalid skip.');
|
||||
}
|
||||
$object = new \RecurringTransaction($model);
|
||||
$object->isValid();
|
||||
$errors->merge($object->getErrors());
|
||||
|
||||
$set = ['name', 'match', 'amount_min', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active'];
|
||||
foreach ($set as $entry) {
|
||||
|
Reference in New Issue
Block a user