Clean up old tests.

This commit is contained in:
James Cole
2021-03-12 18:31:19 +01:00
parent a05d006fa7
commit 81f5224b11
36 changed files with 792 additions and 3261 deletions

View File

@@ -0,0 +1,63 @@
<?php
/*
* AccountControllerTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Api\Autocomplete;
use Tests\TestCase;
use Laravel\Passport\Passport;
use Log;
/**
* Class AccountControllerTest
*/
class AccountControllerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
*
*/
public function testBasic(): void
{
$this->assertTrue(true);
}
/**
* @covers \FireflyIII\Api\V1\Controllers\Autocomplete\AccountController
*/
public function testAccounts(): void
{
// test API
$response = $this->get(route('api.v1.autocomplete.accounts'), ['Accept' => 'application/json']);
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/json');
}
}

View File

@@ -1,110 +0,0 @@
<?php
/*
* CorrectOpeningBalanceCurrenciesTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* CorrectOpeningBalanceCurrenciesTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class CorrectOpeningBalanceCurrenciesTest
*
* @package Tests\Feature\Console\Commands\Correction
*/
class CorrectOpeningBalanceCurrenciesTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\CorrectOpeningBalanceCurrencies
*/
public function testBasic(): void
{
$this->assertTrue(true);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CorrectOpeningBalanceCurrencies
*/
public function testHandleOK(): void
{
// run command
$this->artisan('firefly-iii:fix-ob-currencies')
->expectsOutput('There was nothing to fix in the opening balance transactions.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CorrectOpeningBalanceCurrencies
*/
public function testHandleBroken(): void
{
// create opening balance journal for test. Is enough to trigger this test.
TransactionJournal::factory()->openingBalance()->create();
// run command
$this->artisan('firefly-iii:fix-ob-currencies')
->expectsOutput('Corrected 1 opening balance transaction(s).')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CorrectOpeningBalanceCurrencies
*/
public function testHandleNoAccount(): void
{
Log::debug('Now in testHandleNoAccount');
// create opening balance journal for test. Is enough to trigger this test.
$journal = TransactionJournal::factory()->brokenOpeningBalance()->create();
// run command
$this->artisan('firefly-iii:fix-ob-currencies')
->expectsOutput(sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id))
//->expectsOutput('Cant fix this line.')
->assertExitCode(0);
$journal->forceDelete();
}
}

View File

@@ -1,64 +0,0 @@
<?php
/**
* CreateAccessTokensTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Preference;
use Tests\TestCase;
/**
* Class CreateAccessTokensTest
*/
class CreateAccessTokensTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateAccessTokens
*/
public function testHandle(): void
{
// remove preferences so token will be generated
Preference::where('name', 'access_token')->delete();
$this->artisan('firefly-iii:create-access-tokens')
->expectsOutput(sprintf('Generated access token for user %s', $this->user()->email))
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateAccessTokens
*/
public function testHandlePrefExists(): void
{
$preference = new Preference;
$preference->data = '123';
$preference->name = 'access_token';
$preference->user_id = $this->user()->id;
$preference->save();
$this->artisan('firefly-iii:create-access-tokens')
->expectsOutput('All access tokens OK!')
->assertExitCode(0);
}
}

View File

@@ -1,72 +0,0 @@
<?php
/**
* CreateLinkTypesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\LinkType;
use Log;
use Tests\TestCase;
/**
* Class CreateLinkTypesTest
*/
class CreateLinkTypesTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateLinkTypes
*/
public function testHandle(): void
{
// delete all other link types:
LinkType::whereNotIn('name', ['Related', 'Refund', 'Paid', 'Reimbursement'])->forceDelete();
// delete link type:
LinkType::where('name', 'Reimbursement')->forceDelete();
$this->assertCount(3, LinkType::get());
// run command, expect output:
$this->artisan('firefly-iii:create-link-types')
->expectsOutput('Created missing link type "Reimbursement"')
->assertExitCode(0);
$this->assertCount(4, LinkType::get());
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateLinkTypes
*/
public function testHandleNothing(): void
{
$this->assertCount(4, LinkType::get());
// run command, expect output:
$this->artisan('firefly-iii:create-link-types')
->expectsOutput('All link types OK!')
->assertExitCode(0);
$this->assertCount(4, LinkType::get());
}
}

View File

@@ -1,62 +0,0 @@
<?php
/**
* DeleteEmptyGroupsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\TransactionGroup;
use Log;
use Tests\TestCase;
/**
* Class DeleteEmptyGroupsTest
*/
class DeleteEmptyGroupsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyGroups
*/
public function testHandle(): void
{
// assume there are no empty groups..
$this->artisan('firefly-iii:delete-empty-groups')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyGroups
*/
public function testHandleWithGroup(): void
{
// create new group:
$group = TransactionGroup::create(['user_id' => 1]);
// command should delete it.
$this->artisan('firefly-iii:delete-empty-groups')
->expectsOutput('Deleted 1 empty transaction group(s).')
->assertExitCode(0);
// should not be able to find it:
$this->assertCount(0, TransactionGroup::where('id', $group->id)->whereNull('deleted_at')->get());
}
}

View File

@@ -1,112 +0,0 @@
<?php
/**
* DeleteEmptyJournalsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class DeleteEmptyJournalsTest
*/
class DeleteEmptyJournalsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyJournals
*/
public function testHandle(): void
{
// assume there are no empty journals or uneven journals
$this->artisan('firefly-iii:delete-empty-journals')
->expectsOutput('No uneven transaction journals.')
->expectsOutput('No empty transaction journals.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyJournals
*/
public function testHandleEmptyJournals(): void
{
// create empty journal:
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Hello',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$this->artisan('firefly-iii:delete-empty-journals')
->expectsOutput('No uneven transaction journals.')
->expectsOutput(sprintf('Deleted empty transaction journal #%d', $journal->id))
->assertExitCode(0);
// verify its indeed gone
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->get());
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyJournals
*/
public function testHandleUnevenJournals(): void
{
// create empty journal:
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Hello',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
// link empty transaction
$transaction = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => 1,
'amount' => '5',
]
);
$this->artisan('firefly-iii:delete-empty-journals')
->expectsOutput(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $journal->id))
->expectsOutput('No empty transaction journals.')
->assertExitCode(0);
// verify both are gone
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->get());
$this->assertCount(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->get());
}
}

View File

@@ -1,137 +0,0 @@
<?php
/**
* DeleteOrphanedTransactionsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class DeleteOrphanedTransactionsTest
*/
class DeleteOrphanedTransactionsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteOrphanedTransactions
*/
public function testHandle(): void
{
// assume there are no orphaned transactions.
$this->artisan('firefly-iii:delete-orphaned-transactions')
->expectsOutput('No orphaned transactions.')
->expectsOutput('No orphaned accounts.')
->assertExitCode(0);
}
/**
*
*/
public function testHandleOrphanedAccounts(): void
{
// create deleted account:
$account = Account::create(
[
'user_id' => 1,
'name' => 'Some account',
'account_type_id' => 1,
]
);
$account->delete();
// create NOT deleted journal + transaction.
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Hello',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$transaction = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $account->id,
'amount' => '5',
]
);
$this->artisan('firefly-iii:delete-orphaned-transactions')
->expectsOutput('No orphaned transactions.')
->expectsOutput(sprintf('Deleted transaction journal #%d because account #%d was already deleted.',
$journal->id, $account->id))
->assertExitCode(0);
// verify bad objects are gone.
$this->assertCount(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->get());
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->get());
$this->assertCount(0, Account::where('id', $account->id)->whereNull('deleted_at')->get());
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteOrphanedTransactions
*/
public function testHandleOrphanedTransactions(): void
{
// create deleted journal:
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Hello',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$journal->delete();
// create NOT deleted transaction.
$transaction = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => 1,
'amount' => '5',
]
);
$this->artisan('firefly-iii:delete-orphaned-transactions')
->expectsOutput(sprintf('Transaction #%d (part of deleted transaction journal #%d) has been deleted as well.',
$transaction->id, $journal->id))
->expectsOutput('No orphaned accounts.')
->assertExitCode(0);
// verify objects are gone.
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->get());
$this->assertCount(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->get());
}
}

View File

@@ -1,84 +0,0 @@
<?php
/**
* DeleteZeroAmountTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class DeleteZeroAmountTest
*/
class DeleteZeroAmountTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteZeroAmount
*/
public function testHandle(): void
{
// assume there are no transactions with a zero amount.
$this->artisan('firefly-iii:delete-zero-amount')
->expectsOutput('No zero-amount transaction journals.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteZeroAmount
*/
public function testHandleTransactions(): void
{
$account = $this->getRandomAsset();
// create NOT deleted journal + transaction.
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Hello',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$transaction = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $account->id,
'amount' => '0',
]
);
// assume there are no transactions with a zero amount.
$this->artisan('firefly-iii:delete-zero-amount')
->expectsOutput(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id))
->assertExitCode(0);
// verify objects are gone.
$this->assertCount(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->get());
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->get());
}
}

View File

@@ -1,78 +0,0 @@
<?php
/**
* EnableCurrenciesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionCurrency;
use Tests\TestCase;
/**
* Class EnableCurrenciesTest
*/
class EnableCurrenciesTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\EnableCurrencies
*/
public function testHandleEnabled(): void
{
$count = TransactionCurrency::where('enabled', 1)->count();
$this->artisan('firefly-iii:enable-currencies')
->expectsOutput('All currencies are correctly enabled or disabled.')
->assertExitCode(0);
$this->assertCount($count, TransactionCurrency::where('enabled', 1)->get());
}
/**
* @covers \FireflyIII\Console\Commands\Correction\EnableCurrencies
*/
public function testHandleDisabled(): void
{
// find a disabled currency, update a budget limit with it.
$currency = TransactionCurrency::where('enabled', 0)->first();
$budget = $this->getRandomBudget();
$budgetLimit = new BudgetLimit;
$budgetLimit->transaction_currency_id = $currency->id;
$budgetLimit->budget_id = $budget->id;
$budgetLimit->start_date = '2020-01-01';
$budgetLimit->end_date = '2020-01-02';
$budgetLimit->amount = '4';
$budgetLimit->save();
// assume the current database is intact.
$count = TransactionCurrency::where('enabled', 1)->count();
$this->artisan('firefly-iii:enable-currencies')
->expectsOutput(sprintf('%d were (was) still disabled. This has been corrected.', 1))
->assertExitCode(0);
// assume its been enabled.
$this->assertCount($count + 1, TransactionCurrency::where('enabled', 1)->get());
$budgetLimit->forceDelete();
}
}

View File

@@ -1,69 +0,0 @@
<?php
/*
* FixAccountOrderTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* FixAccountOrderTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use DB;
use FireflyIII\Models\Account;
use Tests\TestCase;
class FixAccountOrderTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixAccountOrder
*/
public function testHandle(): void
{
// reset all asset accounts accounts:
Account::select()->update(['order' => 0]);
$this->artisan('firefly-iii:fix-account-order')
->assertExitCode(0);
$this->assertCount(0, Account::where('order', '=',0)->get());
}
}

View File

@@ -1,364 +0,0 @@
<?php
/**
* FixAccountTypesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Tests\TestCase;
/**
* Class FixAccountTypesTest
*/
class FixAccountTypesTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixAccountTypes
*/
public function testHandleUneven(): void
{
$source = $this->getRandomDebt();
$type = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id,
'amount' => '-10',
]
);
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(sprintf('Cannot inspect transaction journal #%d because it has 1 transaction(s) instead of 2.', $journal->id))
->assertExitCode(0);
$one->forceDelete();
$journal->forceDelete();
}
/**
* @covers \FireflyIII\Console\Commands\Correction\FixAccountTypes
*/
public function testHandle(): void
{
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput('All account types are OK!')
->assertExitCode(0);
}
/**
* Try to fix a withdrawal that goes from a loan to another loan.
*
* @covers \FireflyIII\Console\Commands\Correction\FixAccountTypes
*/
public function testHandleWithdrawalLoanLoan(): void
{
$source = $this->getRandomLoan();
$destination = $this->getRandomLoan($source->id);
$type = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id,
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $destination->id,
'amount' => '10',
]
);
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(sprintf('The source account of %s #%d cannot be of type "%s".', $type->type, $journal->id, 'Loan'))
->expectsOutput(sprintf('The destination account of %s #%d cannot be of type "%s".', $type->type, $journal->id, 'Loan'))
->expectsOutput('Acted on 1 transaction(s)!')
->assertExitCode(0);
// since system cant handle this problem, dont look for changed transactions.
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Transferring from an asset to a loan should be a withdrawal, not a transfer
*/
public function testHandleTransferAssetLoan(): void
{
$source = $this->getRandomAsset();
$destination = $this->getRandomLoan();
$type = TransactionType::where('type', TransactionType::TRANSFER)->first();
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id,
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $destination->id,
'amount' => '10',
]
);
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id))
->expectsOutput('Acted on 1 transaction(s)!')
->assertExitCode(0);
// verify the change has been made.
$this->assertCount(1, TransactionJournal::where('id', $journal->id)->where('transaction_type_id', $withdrawal->id)->get());
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->where('transaction_type_id', $type->id)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Transferring from a loan to an asset should be a deposit, not a transfer
*/
public function testHandleTransferLoanAsset(): void
{
$source = $this->getRandomLoan();
$destination = $this->getRandomAsset();
$type = TransactionType::where('type', TransactionType::TRANSFER)->first();
$deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $type->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id,
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $destination->id,
'amount' => '10',
]
);
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id))
->expectsOutput('Acted on 1 transaction(s)!')
->assertExitCode(0);
// verify the change has been made.
$this->assertCount(1, TransactionJournal::where('id', $journal->id)->where('transaction_type_id', $deposit->id)->get());
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->where('transaction_type_id', $type->id)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Withdrawal with a revenue account as a destination must be converted.
*/
public function testHandleWithdrawalAssetRevenue(): void
{
$source = $this->getRandomAsset();
$destination = $this->getRandomRevenue(); // is revenue account.
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $withdrawal->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id,
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $destination->id, // revenue cannot be destination.
'amount' => '10',
]
);
// create expense account with the same name:
$expense = AccountType::where('type', AccountType::EXPENSE)->first();
$newDestination = Account::create(
[
'name' => $destination->name,
'account_type_id' => $expense->id,
'user_id' => 1,
]
);
// asset we find bad destination.
$this->assertCount(0, Transaction::where('id', $two->id)->where('account_id', $newDestination->id)->get());
$this->assertCount(1, Transaction::where('id', $two->id)->where('account_id', $destination->id)->get());
// Transaction journal #137, destination account changed from #1 ("Checking Account") to #29 ("Land lord").
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(
sprintf(
'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").',
$journal->id,
$destination->id, $destination->name,
$newDestination->id, $newDestination->name
)
)
->expectsOutput('Acted on 1 transaction(s)!')
->assertExitCode(0);
// verify the change has been made
$this->assertCount(1, Transaction::where('id', $two->id)->where('account_id', $newDestination->id)->get());
$this->assertCount(0, Transaction::where('id', $two->id)->where('account_id', $destination->id)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
/**
* Deposit with an expense account as a source instead of a revenue account must be converted.
*/
public function testHandleDepositAssetExpense(): void
{
$source = $this->getRandomExpense(); // expense account
//$newSource = $this->getRandomRevenue();
$destination = $this->getRandomAsset();
$deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $deposit->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $source->id, // expense account cannot be source.
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $destination->id,
'amount' => '10',
]
);
// create revenue account with the same name:
$revenue = AccountType::where('type', AccountType::REVENUE)->first();
$newSource = Account::create(
[
'name' => $source->name,
'account_type_id' => $revenue->id,
'user_id' => 1,
]
);
$this->assertCount(0, Transaction::where('id', $one->id)->where('account_id', $newSource->id)->get());
$this->assertCount(1, Transaction::where('id', $one->id)->where('account_id', $source->id)->get());
// Transaction journal #137, destination account changed from #1 ("Checking Account") to #29 ("Land lord").
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput(
sprintf(
'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").',
$journal->id,
$destination->id, $destination->name,
$newSource->id, $newSource->name
)
)
->expectsOutput('Acted on 1 transaction(s)!')
->assertExitCode(0);
$this->assertCount(1, Transaction::where('id', $one->id)->where('account_id', $newSource->id)->get());
$this->assertCount(0, Transaction::where('id', $one->id)->where('account_id', $source->id)->get());
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
}
}

View File

@@ -1,69 +0,0 @@
<?php
/*
* FixGroupAccountsTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* FixGroupAccountsTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use Tests\TestCase;
/**
* Class FixGroupAccountsTest
*/
class FixGroupAccountsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixGroupAccounts
*/
public function testHandle(): void
{
// basic group with multiple journals, should trigger event.
$this->artisan('firefly-iii:unify-group-accounts')
->expectsOutput('Updated inconsistent transaction groups.')
->assertExitCode(0);
// This just triggers the events. No real test.
}
}

View File

@@ -1,95 +0,0 @@
<?php
/*
* FixLongDescriptionsTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* FixLongDescriptionsTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use Tests\TestCase;
/**
* Class FixLongDescriptionsTest
*/
class FixLongDescriptionsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixLongDescriptions
*/
public function testHandle(): void
{
$journal = $this->getRandomWithdrawal();
$original = $journal->description;
$journal->description = str_repeat('ABCDEF123456x', 200);
$journal->save();
$this->artisan('firefly-iii:fix-long-descriptions')
->expectsOutput(sprintf('Truncated description of transaction journal #%d', $journal->id))
->expectsOutput('Verified all transaction group and journal title lengths.')
->assertExitCode(0);
$journal->description = $original;
$journal->save();
}
/**
* @covers \FireflyIII\Console\Commands\Correction\FixLongDescriptions
*/
public function testHandleGroup(): void
{
$journal = $this->getRandomWithdrawal();
$group = $journal->transactionGroup;
$original = $group->title;
$group->title = str_repeat('ABCDEF123456x', 200);
$group->save();
$this->artisan('firefly-iii:fix-long-descriptions')
->expectsOutput(sprintf('Truncated description of transaction group #%d', $group->id))
->expectsOutput('Verified all transaction group and journal title lengths.')
->assertExitCode(0);
$group->title = $original;
$group->save();
}
}

View File

@@ -1,123 +0,0 @@
<?php
/**
* FixPiggiesTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use Log;
use Tests\TestCase;
/**
* Class FixPiggiesTest
*/
class FixPiggiesTest extends TestCase
{
/**
* Null event.
*
* @covers \FireflyIII\Console\Commands\Correction\FixPiggies
*/
public function testHandleNull(): void
{
/** @var PiggyBank $piggy */
$piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
// create event to trigger console commands.
$event = PiggyBankEvent::create(
[
'piggy_bank_id' => $piggy->id,
'date' => '2019-01-01',
'amount' => 5,
]
);
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-piggies')
->expectsOutput('All piggy bank events are correct.')
->assertExitCode(0);
$event->forceDelete();
}
/**
* Withdrawal instead of transfer
*
* @covers \FireflyIII\Console\Commands\Correction\FixPiggies
*/
public function testHandleBadJournal(): void
{
/** @var PiggyBank $piggy */
$piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
$withdrawal = $this->getRandomWithdrawal();
// create event to trigger console commands.
$event = PiggyBankEvent::create(
[
'piggy_bank_id' => $piggy->id,
'date' => '2019-01-01',
'amount' => 5,
'transaction_journal_id' => $withdrawal->id,
]
);
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-piggies')
->expectsOutput(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $piggy->id))
->expectsOutput('Fixed 1 piggy bank event(s).')
->assertExitCode(0);
// verify update
$this->assertCount(0, PiggyBankEvent::where('id', $event->id)->where('transaction_journal_id', $withdrawal->id)->get());
}
/**
* Withdrawal instead of transfer
*
* @covers \FireflyIII\Console\Commands\Correction\FixPiggies
*/
public function testHandleDeletedJournal(): void
{
/** @var PiggyBank $piggy */
$piggy = $this->user()->piggyBanks()->inRandomOrder()->first();
$transfer = $this->getRandomTransfer();
$event = PiggyBankEvent::create(
[
'piggy_bank_id' => $piggy->id,
'date' => '2019-01-01',
'amount' => 5,
'transaction_journal_id' => $transfer->id,
]
);
$transfer->deleted_at = '2019-01-01 12:00:00';
$transfer->save();
$transfer->refresh();
$this->artisan('firefly-iii:fix-piggies')
->expectsOutput('Fixed 1 piggy bank event(s).')
->assertExitCode(0);
// verify update
$this->assertCount(0, PiggyBankEvent::where('id', $event->id)->where('transaction_journal_id', $transfer->id)->get());
$event->forceDelete();
}
}

View File

@@ -1,70 +0,0 @@
<?php
/*
* FixRecurringTransactionsTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* FixRecurringTransactionsTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Recurrence;
use Tests\TestCase;
/**
* Class FixRecurringTransactionsTest
*/
class FixRecurringTransactionsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixRecurringTransactions
*/
public function testHandle(): void
{
// test DB contains a broken recurring transaction.
$recurring = Recurrence::whereTitle('broken_recurrence')->first();
$this->artisan('firefly-iii:fix-recurring-transactions')
->expectsOutput(sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.',
$recurring->id, 'Withdrawal','Transfer',
))
->assertExitCode(0);
}
}

View File

@@ -1,65 +0,0 @@
<?php
/*
* FixTransactionTypesTest.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
/*
* FixTransactionTypesTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use Tests\TestCase;
/**
* Class FixTransactionTypesTest
*/
class FixTransactionTypesTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixTransactionTypes
*/
public function testHandle(): void
{
$this->artisan('firefly-iii:fix-transaction-types')
//->expectsOutput()
->assertExitCode(0);
}
}

View File

@@ -1,95 +0,0 @@
<?php
/**
* FixUnevenAmountTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Log;
use Tests\TestCase;
/**
* Class FixUnevenAmountTest
*/
class FixUnevenAmountTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixUnevenAmount
*/
public function testHandle(): void
{
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-uneven-amount')
->expectsOutput('Amount integrity OK!')
->assertExitCode(0);
// dont verify anything
}
/**
* Create uneven journal
* @covers \FireflyIII\Console\Commands\Correction\FixUnevenAmount
*/
public function testHandleUneven(): void
{
$asset = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => $withdrawal->id,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '12',
]
);
$this->artisan('firefly-iii:fix-uneven-amount')
->expectsOutput(sprintf('Corrected amount in transaction journal #%d', $journal->id))
->assertExitCode(0);
// verify change.
$this->assertCount(1, Transaction::where('id', $one->id)->where('amount', '-10')->get());
$this->assertCount(1, Transaction::where('id', $two->id)->where('amount', '10')->get());
}
}

View File

@@ -1,69 +0,0 @@
<?php
/**
* RemoveBillsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal;
use Log;
use Tests\TestCase;
/**
* Class RemoveBillsTest
*/
class RemoveBillsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\RemoveBills
*/
public function testHandle(): void
{
// assume there's nothing to fix.
$this->artisan('firefly-iii:remove-bills')
->expectsOutput('All transaction journals have correct bill information.')
->assertExitCode(0);
// dont verify anything
}
/**
* @covers \FireflyIII\Console\Commands\Correction\RemoveBills
*/
public function testHandleWithdrawal(): void
{
$bill = $this->getRandomBill();
$journal = $this->getRandomDeposit();
$journal->bill_id = $bill->id;
$journal->save();
$this->artisan('firefly-iii:remove-bills')
->expectsOutput(sprintf('Transaction journal #%d should not be linked to bill #%d.', $journal->id, $bill->id))
->assertExitCode(0);
// verify change
$this->assertCount(0, TransactionJournal::where('id', $journal->id)->whereNotNull('bill_id')->get());
}
}

View File

@@ -1,70 +0,0 @@
<?php
/**
* RenameMetaFieldsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournalMeta;
use Log;
use Tests\TestCase;
/**
* Class RenameMetaFieldsTest
*/
class RenameMetaFieldsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\RenameMetaFields
*/
public function testHandle(): void
{
$this->artisan('firefly-iii:rename-meta-fields')
->expectsOutput('All meta fields are correct.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\RenameMetaFields
*/
public function testHandleFixed(): void
{
$withdrawal = $this->getRandomWithdrawal();
$entry = TransactionJournalMeta::create(
[
'transaction_journal_id' => $withdrawal->id,
'name' => 'importHashV2',
'data' => 'Fake data',
]
);
$this->artisan('firefly-iii:rename-meta-fields')
->expectsOutput('Renamed 1 meta field(s).')
->assertExitCode(0);
// verify update
$this->assertCount(1, TransactionJournalMeta::where('id', $entry->id)->where('name', 'import_hash_v2')->get());
}
}

View File

@@ -1,64 +0,0 @@
<?php
/**
* TransferBudgetsTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Console\Commands\Correction;
use Log;
use Tests\TestCase;
/**
* Class TransferBudgetsTest
*/
class TransferBudgetsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\TransferBudgets
*/
public function testHandle(): void
{
$this->artisan('firefly-iii:fix-transfer-budgets')
->expectsOutput('No invalid budget/journal entries.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Correction\TransferBudgets
*/
public function testHandleBudget(): void
{
$deposit = $this->getRandomDeposit();
$budget = $this->getRandomBudget();
$deposit->budgets()->save($budget);
$this->artisan('firefly-iii:fix-transfer-budgets')
->expectsOutput(sprintf('Transaction journal #%d is a %s, so has no longer a budget.', $deposit->id, $deposit->transactionType->type))
->expectsOutput('Corrected 1 invalid budget/journal entries (entry).')
->assertExitCode(0);
// verify change
$this->assertCount(0, $deposit->budgets()->get());
}
}