mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Cleaning up test data.
This commit is contained in:
parent
8e1dbc03d9
commit
e2d0ee125f
@ -18,8 +18,10 @@ use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
@ -37,7 +39,6 @@ use Log;
|
||||
*/
|
||||
class TestData
|
||||
{
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@ -228,6 +229,139 @@ class TestData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createCategories(User $user)
|
||||
{
|
||||
Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
||||
Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createExpenseAccounts(User $user)
|
||||
{
|
||||
$expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl',
|
||||
'coolblue', 'Shell',
|
||||
'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord'];
|
||||
foreach ($expenses as $name) {
|
||||
// create account:
|
||||
Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 4,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $description
|
||||
* @param Carbon $date
|
||||
* @param string $amount
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public static function createRent(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||
{
|
||||
$fromAccount = TestData::findAccount($user, 'TestData Checking Account');
|
||||
$toAccount = TestData::findAccount($user, 'Land lord');
|
||||
$category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $user->id]);
|
||||
$budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => 1,
|
||||
'transaction_currency_id' => 1,
|
||||
'bill_id' => 1,
|
||||
'description' => $description,
|
||||
'completed' => 1,
|
||||
'date' => $date,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $fromAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount * -1,
|
||||
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $toAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount,
|
||||
|
||||
]
|
||||
);
|
||||
$journal->categories()->save($category);
|
||||
$journal->budgets()->save($budget);
|
||||
|
||||
return $journal;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $description
|
||||
* @param Carbon $date
|
||||
* @param string $amount
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public static function createIncome(User $user, string $description, Carbon $date, string $amount): TransactionJournal
|
||||
{
|
||||
$date = new Carbon($date->format('Y-m') . '-23'); // paid on 23rd.
|
||||
$today = new Carbon;
|
||||
if ($date >= $today) {
|
||||
return new TransactionJournal;
|
||||
}
|
||||
$toAccount = TestData::findAccount($user, 'TestData Checking Account');
|
||||
$fromAccount = TestData::findAccount($user, 'Job');
|
||||
$category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $user->id]);
|
||||
// create journal:
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => 2,
|
||||
'transaction_currency_id' => 1,
|
||||
'description' => $description,
|
||||
'completed' => 1,
|
||||
'date' => $date,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $fromAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount * -1,
|
||||
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $toAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => $amount,
|
||||
|
||||
]
|
||||
);
|
||||
$journal->categories()->save($category);
|
||||
|
||||
return $journal;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @param User $user
|
||||
@ -366,6 +500,26 @@ class TestData
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public static function createRevenueAccounts(User $user)
|
||||
{
|
||||
$revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];
|
||||
foreach ($revenues as $name) {
|
||||
// create account:
|
||||
Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 5,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
@ -468,6 +622,22 @@ class TestData
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public static function createUsers(): User
|
||||
{
|
||||
$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();
|
||||
$user->attachRole($admin);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $name
|
||||
@ -508,5 +678,56 @@ class TestData
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public static function openingBalanceSavings(User $user, Carbon $date)
|
||||
{
|
||||
// opposing account for opening balance:
|
||||
$opposing = Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 6,
|
||||
'name' => 'Opposing for savings',
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// savings
|
||||
$savings = TestData::findAccount($user, 'TestData Savings');
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => 4,
|
||||
'transaction_currency_id' => 1,
|
||||
'description' => 'Opening balance for savings account',
|
||||
'completed' => 1,
|
||||
'date' => $date->format('Y-m-d'),
|
||||
]
|
||||
);
|
||||
|
||||
// transactions
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $opposing->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -10000,
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 10000,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,9 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call('PermissionSeeder');
|
||||
|
||||
// set up basic test data (as little as possible):
|
||||
if (App::environment() == 'testing') {
|
||||
if (App::environment() == 'testing' || App::environment() == 'local') {
|
||||
$this->call('TestDataSeeder');
|
||||
}
|
||||
|
||||
// this one is reserved for more extensive testing.
|
||||
if (App::environment() == 'local') {
|
||||
$this->call('VisualTestDataSeeder');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
68
database/seeds/OldTestDataSeeder.php
Normal file
68
database/seeds/OldTestDataSeeder.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Migration\TestData;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Class OldTestDataSeeder
|
||||
*/
|
||||
class OldTestDataSeeder extends Seeder
|
||||
{
|
||||
/** @var Carbon */
|
||||
public $start;
|
||||
|
||||
/**
|
||||
* TestDataSeeder constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->start = Carbon::create()->subYear()->startOfYear();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// create budget limits for these budgets
|
||||
// TestData::createBudgetLimit($user, new Carbon, 'Groceries', 400);
|
||||
// TestData::createBudgetLimit($user, new Carbon, 'Bills', 1000);
|
||||
// TestData::createBudgetLimit($user, new Carbon, 'Car', 100);
|
||||
|
||||
// create some categories for user #1
|
||||
$this->createCategories($user);
|
||||
|
||||
// create some piggy banks for user #1
|
||||
TestData::createPiggybanks($user);
|
||||
|
||||
// create some expense accounts for user #1
|
||||
$this->createExpenseAccounts($user);
|
||||
|
||||
// create some revenue accounts for user #1
|
||||
$this->createRevenueAccounts($user);
|
||||
|
||||
// create journal + attachment:
|
||||
TestData::createAttachments($user, $this->start);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
/**
|
||||
* TestDataSeeder.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Role;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\Migration\TestData;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
@ -16,6 +17,8 @@ use Illuminate\Database\Seeder;
|
||||
*/
|
||||
class TestDataSeeder extends Seeder
|
||||
{
|
||||
/** @var Carbon */
|
||||
public $end;
|
||||
/** @var Carbon */
|
||||
public $start;
|
||||
|
||||
@ -24,7 +27,8 @@ class TestDataSeeder extends Seeder
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->start = Carbon::create()->subYear()->startOfYear();
|
||||
$this->start = Carbon::create()->subYears(2)->startOfYear();
|
||||
$this->end = Carbon::now();
|
||||
|
||||
}
|
||||
|
||||
@ -35,153 +39,58 @@ class TestDataSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$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]);
|
||||
// start by creating all users:
|
||||
// method will return the first user.
|
||||
$user = TestData::createUsers();
|
||||
|
||||
|
||||
$admin = Role::where('name', 'owner')->first();
|
||||
$user->attachRole($admin);
|
||||
|
||||
|
||||
// create asset accounts for user #1.
|
||||
// create all kinds of static data:
|
||||
TestData::createAssetAccounts($user);
|
||||
|
||||
// create bills for user #1
|
||||
TestData::createBills($user);
|
||||
|
||||
// create some budgets for user #1
|
||||
TestData::createBudgets($user);
|
||||
|
||||
// create budget limits for these budgets
|
||||
TestData::createBudgetLimit($user, new Carbon, 'Groceries', 400);
|
||||
TestData::createBudgetLimit($user, new Carbon, 'Bills', 1000);
|
||||
TestData::createBudgetLimit($user, new Carbon, 'Car', 100);
|
||||
|
||||
// create some categories for user #1
|
||||
$this->createCategories($user);
|
||||
|
||||
// create some piggy banks for user #1
|
||||
TestData::createCategories($user);
|
||||
TestData::createPiggybanks($user);
|
||||
|
||||
// create some expense accounts for user #1
|
||||
$this->createExpenseAccounts($user);
|
||||
|
||||
// create some revenue accounts for user #1
|
||||
$this->createRevenueAccounts($user);
|
||||
|
||||
// create journal + attachment:
|
||||
TestData::createExpenseAccounts($user);
|
||||
TestData::createRevenueAccounts($user);
|
||||
TestData::createAttachments($user, $this->start);
|
||||
|
||||
// create opening balance for savings account:
|
||||
$this->openingBalanceSavings($user);
|
||||
|
||||
// need at least one rule group and one rule:
|
||||
TestData::openingBalanceSavings($user, $this->start);
|
||||
TestData::createRules($user);
|
||||
|
||||
// create a tag:
|
||||
TestData::createTags($user);
|
||||
}
|
||||
// loop from start to end, create dynamic info.
|
||||
$current = clone $this->start;
|
||||
while ($current < $this->end) {
|
||||
$month = $current->format('F Y');
|
||||
// create salaries:
|
||||
TestData::createIncome($user, 'Salary ' . $month, $current, strval(rand(2000, 2100)));
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createCategories(User $user)
|
||||
{
|
||||
Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
||||
Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
||||
}
|
||||
// pay bills:
|
||||
TestData::createRent($user, 'Rent for ' . $month, $current, '800');
|
||||
// $this->createWater('Water bill for ' . $month, $current, 15);
|
||||
// $this->createTV('TV bill for ' . $month, $current, 60);
|
||||
// $this->createPower('Power bill for ' . $month, $current, 120);
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createExpenseAccounts(User $user)
|
||||
{
|
||||
$expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl',
|
||||
'coolblue', 'Shell',
|
||||
'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord'];
|
||||
foreach ($expenses as $name) {
|
||||
// create account:
|
||||
Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 4,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// pay daily groceries:
|
||||
// $this->createGroceries($current);
|
||||
|
||||
// create tag (each type of tag, for date):
|
||||
// TestData::createTags($this->user, $current);
|
||||
|
||||
// go out for drinks:
|
||||
// $this->createDrinksAndOthers($current);
|
||||
|
||||
// save money every month:
|
||||
// $this->createSavings($current);
|
||||
|
||||
// buy gas for the car every month:
|
||||
// $this->createCar($current);
|
||||
|
||||
// create budget limits.
|
||||
TestData::createBudgetLimit($user, $current, 'Groceries', '400');
|
||||
TestData::createBudgetLimit($user, $current, 'Bills', '1000');
|
||||
TestData::createBudgetLimit($user, $current, 'Car', '100');
|
||||
|
||||
echo 'Created test data for ' . $month . "\n";
|
||||
$current->addMonth();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function createRevenueAccounts(User $user)
|
||||
{
|
||||
$revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google'];
|
||||
foreach ($revenues as $name) {
|
||||
// create account:
|
||||
Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 5,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function openingBalanceSavings(User $user)
|
||||
{
|
||||
// opposing account for opening balance:
|
||||
$opposing = Account::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'account_type_id' => 6,
|
||||
'name' => 'Opposing for savings',
|
||||
'active' => 1,
|
||||
'encrypted' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// savings
|
||||
$savings = TestData::findAccount($user, 'TestData Savings');
|
||||
|
||||
$journal = TransactionJournal::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'transaction_type_id' => 4,
|
||||
'transaction_currency_id' => 1,
|
||||
'description' => 'Opening balance for savings account',
|
||||
'completed' => 1,
|
||||
'date' => $this->start->format('Y-m-d'),
|
||||
]
|
||||
);
|
||||
|
||||
// transactions
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $opposing->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -10000,
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $savings->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 10000,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,15 +31,17 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
'data' => $range,
|
||||
]
|
||||
);
|
||||
// set period to match?
|
||||
|
||||
}
|
||||
// if selected "custom", change the session to a weird custom range:
|
||||
// (20 days):
|
||||
if($range === "custom") {
|
||||
if ($range === "custom") {
|
||||
$this->session(
|
||||
[
|
||||
'start' => Carbon::now(),
|
||||
'end' => Carbon::now()->subDays(20),
|
||||
]
|
||||
'end' => Carbon::now()->subDays(20),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user