This fixes most of the tests.

This commit is contained in:
James Cole 2016-03-02 13:37:28 +01:00
parent 3ef84dc1fc
commit 500243b0b3
6 changed files with 67 additions and 19 deletions

View File

@ -187,7 +187,7 @@ class Importer
// some debug info:
$journalId = $journal->id;
$type = $journal->getTransactionType();
$type = $journal->transaction_type_type ?? $journal->transactionType->type;
/** @var Account $asset */
$asset = $this->importData['asset-account-object'];
/** @var Account $opposing */

View File

@ -99,7 +99,7 @@ class TransactionController extends Controller
*/
public function delete(TransactionJournal $journal)
{
$what = strtolower($journal->getTransactionType());
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);
// put previous url in session
@ -141,6 +141,9 @@ class TransactionController extends Controller
*/
public function edit(ARI $repository, TransactionJournal $journal)
{
// get journal again:
/** @var TransactionJournal $journal */
$journal = TransactionJournal::expanded()->where('transaction_journals.id', $journal->id)->first(TransactionJournal::QUERYFIELDS);
// cannot edit opening balance
if ($journal->isOpeningBalance()) {
throw new FireflyException('Cannot edit this transaction (#' . $journal->id . '). Edit the account instead!');
@ -150,7 +153,7 @@ class TransactionController extends Controller
$maxFileSize = Steam::phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = Steam::phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
$what = strtolower($journal->getTransactionType());
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
$budgets[0] = trans('form.noBudget');
@ -183,15 +186,19 @@ class TransactionController extends Controller
$preFilled['amount'] = $journal->amount_positive;
if ($journal->isWithdrawal()) {
$preFilled['account_id'] = $journal->source_account->id;
$preFilled['expense_account'] = $journal->destination_account->name_for_editform;
$preFilled['account_id'] = $journal->source_account_id;
if ($journal->destination_account_type != 'Cash account') {
$preFilled['expense_account'] = $journal->destination_account_name;
}
} else {
$preFilled['account_id'] = $journal->destination_account->id;
$preFilled['revenue_account'] = $journal->source_account->name_for_editform;
$preFilled['account_id'] = $journal->destination_account_id;
if ($journal->source_account_type != 'Cash account') {
$preFilled['revenue_account'] = $journal->source_account_name;
}
}
$preFilled['account_from_id'] = $journal->source_account->id;
$preFilled['account_to_id'] = $journal->destination_account->id;
$preFilled['account_from_id'] = $journal->source_account_id;
$preFilled['account_to_id'] = $journal->destination_account_id;
Session::flash('preFilled', $preFilled);
Session::flash('gaEventCategory', 'transactions');
@ -279,8 +286,8 @@ class TransactionController extends Controller
$t->after = bcadd($t->before, $t->amount);
}
);
$what = strtolower($journal->getTransactionType());
$subTitle = trans('firefly.' . $journal->getTransactionType()) . ' "' . e($journal->description) . '"';
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.' . $journal->transaction_type_type ?? $journal->transactionType->type) . ' "' . e($journal->description) . '"';
return view('transactions.show', compact('journal', 'events', 'subTitle', 'what'));
}
@ -314,7 +321,6 @@ class TransactionController extends Controller
if (count($att->getMessages()->get('attachments')) > 0) {
Session::flash('info', $att->getMessages()->get('attachments'));
}
Log::debug('Before event. From account name is: ' . $journal->source_account->name);
event(new TransactionJournalStored($journal, intval($request->get('piggy_bank_id'))));

View File

@ -44,6 +44,19 @@ use Watson\Validating\ValidatingTrait;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal after($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal before($date)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal transactionTypes($types)
*
* @property-read string $transaction_type_type
* @property-read string $transaction_currency_code
* @property-read string $destination_amount
* @property-read string $destination_account_id
* @property-read string $destination_account_name
* @property-read string $destination_account_type
* @property-read string $source_amount
* @property-read string $source_account_id
* @property-read string $source_account_name
* @property-read string $source_account_type
*
*/
class TransactionJournal extends BaseModel
{

View File

@ -53,7 +53,8 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal)
{
$fromAccountName = strtolower($journal->source_account->name);
$sourceAccount = $journal->transactions()->where('amount', '<', 0)->first()->account;
$fromAccountName = strtolower($sourceAccount->name);
$search = strtolower($this->triggerValue);
if ($fromAccountName == $search) {

View File

@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>

View File

@ -7,13 +7,14 @@
* of the MIT license. See the LICENSE file for details.
*/
use FireflyIII\Helpers\Collection\Account as AccountCollection;
use FireflyIII\Helpers\Collection\Balance;
use FireflyIII\Helpers\Collection\Bill as BillCollection;
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
use FireflyIII\Helpers\Collection\Expense;
use FireflyIII\Helpers\Collection\Income;
use FireflyIII\Helpers\Collection\Account as AccountCollection;
use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
use FireflyIII\Helpers\Collection\Balance;
use Illuminate\Support\Collection;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-01-19 at 15:39:28.
@ -53,7 +54,6 @@ class ReportControllerTest extends TestCase
$defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
$accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
$defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
$defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
@ -79,6 +79,22 @@ class ReportControllerTest extends TestCase
public function testReportDefaultMultiYear($range)
{
$this->be($this->user());
// mock some stuff.
$accountHelper = $this->mock('FireflyIII\Helpers\Report\AccountReportHelperInterface');
$defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
$budgetRepos = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$categoryRepos = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$budgetRepos->shouldReceive('getActiveBudgets')->once()->andReturn(new Collection);
$categoryRepos->shouldReceive('listCategories')->once()->andReturn(new Collection);
$accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
$defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
$defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
$defaultHelper->shouldReceive('tagReport')->once()->andReturn([]);
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/reports/report/default/20160101/20171231/1,2');
$this->assertResponseStatus(200);
@ -93,6 +109,18 @@ class ReportControllerTest extends TestCase
*/
public function testReportDefaultYear($range)
{
// mock some stuff.
$accountHelper = $this->mock('FireflyIII\Helpers\Report\AccountReportHelperInterface');
$defaultHelper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
$accountHelper->shouldReceive('getAccountReport')->once()->andReturn(new AccountCollection);
$defaultHelper->shouldReceive('getIncomeReport')->once()->andReturn(new Income);
$defaultHelper->shouldReceive('getExpenseReport')->once()->andReturn(new Expense);
$defaultHelper->shouldReceive('tagReport')->once()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', '/reports/report/default/20160101/20161231/1,2');