New test data.

This commit is contained in:
James Cole 2016-02-04 11:00:26 +01:00
parent 151e8e8f17
commit f0bb462f1c
3 changed files with 137 additions and 51 deletions

View File

@ -9,11 +9,18 @@ namespace FireflyIII\Support\Migration;
* of the MIT license. See the LICENSE file for details.
*/
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\Tag;
use FireflyIII\User;
use Log;
@ -93,6 +100,21 @@ class TestData
'skip' => 0,
]
);
}
/**
* @param User $user
*/
public static function createBudgets(User $user)
{
Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
// some empty budgets.
foreach (['A', 'B', 'C', 'D', "E"] as $letter) {
Budget::firstOrCreateEncrypted(['name' => 'Empty budget ' . $letter, 'user_id' => $user->id]);
}
}
/**
@ -233,6 +255,108 @@ class TestData
}
/**
* @param User $user
*/
public static function createRules(User $user)
{
$group = RuleGroup::create(
[
'user_id' => $user->id,
'order' => 1,
'title' => trans('firefly.default_rule_group_name'),
'description' => trans('firefly.default_rule_group_description'),
'active' => 1,
]
);
$rule = Rule::create(
[
'user_id' => $user->id,
'rule_group_id' => $group->id,
'order' => 1,
'active' => 1,
'stop_processing' => 0,
'title' => trans('firefly.default_rule_name'),
'description' => trans('firefly.default_rule_description'),
]
);
// three triggers:
RuleTrigger::create(
[
'rule_id' => $rule->id,
'order' => 1,
'active' => 1,
'stop_processing' => 0,
'trigger_type' => 'user_action',
'trigger_value' => 'store-journal',
]
);
RuleTrigger::create(
[
'rule_id' => $rule->id,
'order' => 2,
'active' => 1,
'stop_processing' => 0,
'trigger_type' => 'description_is',
'trigger_value' => trans('firefly.default_rule_trigger_description'),
]
);
RuleTrigger::create(
[
'rule_id' => $rule->id,
'order' => 3,
'active' => 1,
'stop_processing' => 0,
'trigger_type' => 'from_account_is',
'trigger_value' => trans('firefly.default_rule_trigger_from_account'),
]
);
// two actions:
RuleAction::create(
[
'rule_id' => $rule->id,
'order' => 1,
'active' => 1,
'action_type' => 'prepend_description',
'action_value' => trans('firefly.default_rule_action_prepend'),
]
);
RuleAction::create(
[
'rule_id' => $rule->id,
'order' => 1,
'active' => 1,
'action_type' => 'set_category',
'action_value' => trans('firefly.default_rule_action_set_category'),
]
);
}
/**
* @param User $user
* @param Carbon|null $date
*/
public static function createTags(User $user, Carbon $date = null)
{
$title = 'SomeTag nr. ' . rand(1, 1234);
if (!is_null($date)) {
$title = 'SomeTag' . $date->month . '.' . $date->year . '.nothing';
}
Tag::create(
[
'user_id' => $user->id,
'tag' => $title,
'tagMode' => 'nothing',
'date' => is_null($date) ? null : $date->format('Y-m-d'),
]
);
}
/**
* @param User $user
* @param $name

View File

@ -39,6 +39,7 @@ class TestDataSeeder extends Seeder
{
$user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
User::create(['email' => 'thegrumpydictator+empty@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
User::create(['email' => 'thegrumpydictator+deleteme@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]);
$admin = Role::where('name', 'owner')->first();
@ -52,7 +53,7 @@ class TestDataSeeder extends Seeder
TestData::createBills($user);
// create some budgets for user #1
$this->createBudgets($user);
TestData::createBudgets($user);
// create some categories for user #1
$this->createCategories($user);
@ -71,6 +72,12 @@ class TestDataSeeder extends Seeder
// create opening balance for savings account:
$this->openingBalanceSavings($user);
// need at least one rule group and one rule:
TestData::createRules($user);
// create a tag:
TestData::createTags($user);
}
/**
@ -89,7 +96,7 @@ class TestDataSeeder extends Seeder
'transaction_currency_id' => 1,
'description' => 'Some journal for attachment',
'completed' => 1,
'date' => new Carbon,
'date' => $this->start->format('Y-m-d'),
]
);
Transaction::create(
@ -150,37 +157,6 @@ class TestDataSeeder extends Seeder
}
/**
* @param $user
*/
private function createBudgets($user)
{
$set = [
Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]),
Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]),
];
$current = new Carbon;
/** @var Budget $budget */
foreach ($set as $budget) {
// some budget limits:
$start = clone $current;
$end = clone $current;
$start->startOfMonth();
$end->endOfMonth();
BudgetLimit::create(
[
'budget_id' => $budget->id,
'startdate' => $start->format('Y-m-d'),
'amount' => 500,
'repeats' => 0,
'repeat_freq' => 'monthly',
]
);
}
}
/**
* @param User $user
*/

View File

@ -445,6 +445,9 @@ class VisualTestDataSeeder extends Seeder
TestData::createBills($this->user);
TestData::createPiggybanks($this->user);
// create some budgets for user
TestData::createBudgets($this->user);
$this->createRules();
// preference to only see account #1 on frontpage.
@ -472,7 +475,7 @@ class VisualTestDataSeeder extends Seeder
$this->createGroceries($current);
// create tag (each type of tag, for date):
$this->createTags($current);
TestData::createTags($this->user, $current);
// go out for drinks:
$this->createDrinksAndOthers($current);
@ -1003,23 +1006,6 @@ class VisualTestDataSeeder extends Seeder
}
/**
* @param Carbon $date
*/
protected function createTags(Carbon $date)
{
Tag::create(
[
'user_id' => $this->user->id,
'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing',
'tagMode' => 'nothing',
'date' => $date->format('Y-m-d'),
]
);
}
/**
*
*/