mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Improve test coverage.
This commit is contained in:
@@ -28,6 +28,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@@ -74,35 +75,189 @@ class CreateControllerTest extends TestCase
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$tomorrow = Carbon::create()->addDays(2);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$data = [
|
||||
'title' => 'hello',
|
||||
'title' => 'hello' . random_int(1, 100000),
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'repetition_type' => 'daily',
|
||||
'skip' => 0,
|
||||
'recurring_description' => 'Some descr',
|
||||
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||
'active' => '1',
|
||||
'apply_rules' => '1',
|
||||
'foreign_amount' => '1',
|
||||
'foreign_currency_id' => '2',
|
||||
|
||||
// mandatory for transaction:
|
||||
'transaction_description' => 'Some descr',
|
||||
'transaction_type' => 'withdrawal',
|
||||
'transaction_currency_id' => '1',
|
||||
'amount' => '30',
|
||||
|
||||
// mandatory account info:
|
||||
'source_id' => '1',
|
||||
'source_name' => '',
|
||||
'destination_id' => '',
|
||||
'destination_name' => 'Some Expense',
|
||||
|
||||
// optional fields:
|
||||
'budget_id' => '1',
|
||||
'category' => 'CategoryA',
|
||||
'tags' => 'A,B,C',
|
||||
'create_another' => '1',
|
||||
'repetition_end' => 'times',
|
||||
'repetitions' => 3,
|
||||
];
|
||||
|
||||
'repetition_end' => 'times',
|
||||
'repetitions' => 3,
|
||||
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('recurring.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||
*/
|
||||
public function testStoreDeposit(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$tomorrow = Carbon::create()->addDays(2);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$data = [
|
||||
'title' => 'hello' . random_int(1, 100000),
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'repetition_type' => 'daily',
|
||||
'skip' => 0,
|
||||
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||
'active' => '1',
|
||||
'apply_rules' => '1',
|
||||
'foreign_amount' => '1',
|
||||
'foreign_currency_id' => '2',
|
||||
|
||||
// mandatory for transaction:
|
||||
'transaction_description' => 'Some descr',
|
||||
'transaction_type' => 'deposit',
|
||||
'transaction_currency_id' => '1',
|
||||
'amount' => '30',
|
||||
|
||||
// mandatory account info:
|
||||
'source_id' => '2',
|
||||
'source_name' => 'Some source',
|
||||
'destination_id' => '1',
|
||||
'destination_name' => 'Some Expense',
|
||||
|
||||
// optional fields:
|
||||
'budget_id' => '1',
|
||||
'category' => 'CategoryA',
|
||||
'tags' => 'A,B,C',
|
||||
'create_another' => '1',
|
||||
'repetition_end' => 'times',
|
||||
'repetitions' => 3,
|
||||
];
|
||||
|
||||
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('recurring.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||
*/
|
||||
public function testStoreTransfer(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$tomorrow = Carbon::create()->addDays(2);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$data = [
|
||||
'title' => 'hello' . random_int(1, 100000),
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'repetition_type' => 'daily',
|
||||
'skip' => 0,
|
||||
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||
'active' => '1',
|
||||
'apply_rules' => '1',
|
||||
'foreign_amount' => '1',
|
||||
'foreign_currency_id' => '2',
|
||||
|
||||
// mandatory for transaction:
|
||||
'transaction_description' => 'Some descr',
|
||||
'transaction_type' => 'transfer',
|
||||
'transaction_currency_id' => '1',
|
||||
'amount' => '30',
|
||||
|
||||
// mandatory account info:
|
||||
'source_id' => '2',
|
||||
'source_name' => 'Some source',
|
||||
'destination_id' => '1',
|
||||
'destination_name' => 'Some Expense',
|
||||
|
||||
// optional fields:
|
||||
'budget_id' => '1',
|
||||
'category' => 'CategoryA',
|
||||
'tags' => 'A,B,C',
|
||||
'create_another' => '1',
|
||||
'repetition_end' => 'times',
|
||||
'repetitions' => 3,
|
||||
];
|
||||
|
||||
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('recurring.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||
*/
|
||||
public function testStoreUntilDate(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$tomorrow = Carbon::create()->addDays(2);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$data = [
|
||||
'title' => 'hello' . random_int(1, 100000),
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'repetition_type' => 'daily',
|
||||
'skip' => 0,
|
||||
'recurring_description' => 'Some descr' . random_int(1, 100000),
|
||||
'active' => '1',
|
||||
'apply_rules' => '1',
|
||||
'foreign_amount' => '1',
|
||||
'foreign_currency_id' => '2',
|
||||
|
||||
// mandatory for transaction:
|
||||
'transaction_description' => 'Some descr',
|
||||
'transaction_type' => 'withdrawal',
|
||||
'transaction_currency_id' => '1',
|
||||
'amount' => '30',
|
||||
|
||||
// mandatory account info:
|
||||
'source_id' => '1',
|
||||
'destination_name' => 'Some Expense',
|
||||
|
||||
// optional fields:
|
||||
'budget_id' => '1',
|
||||
'category' => 'CategoryA',
|
||||
'tags' => 'A,B,C',
|
||||
'create_another' => '1',
|
||||
'repetition_end' => 'until_date',
|
||||
'repeat_until' => $tomorrow->format('Y-m-d'),
|
||||
];
|
||||
|
||||
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
|
||||
|
||||
77
tests/Feature/Controllers/Recurring/DeleteControllerTest.php
Normal file
77
tests/Feature/Controllers/Recurring/DeleteControllerTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* DeleteControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Recurring;
|
||||
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class DeleteControllerTest
|
||||
*/
|
||||
class DeleteControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$recurringRepos->shouldReceive('getTransactions')->andReturn(new Collection())->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\DeleteController
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$recurringRepos->shouldReceive('destroy')->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('recurring.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
125
tests/Feature/Controllers/Recurring/EditControllerTest.php
Normal file
125
tests/Feature/Controllers/Recurring/EditControllerTest.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* EditControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Recurring;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class EditControllerTest
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
$recurringRepos->shouldReceive('setUser');
|
||||
$recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
|
||||
$recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
|
||||
$recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
$budgetRepos->shouldReceive('findNull')->andReturn($this->user()->budgets()->first());
|
||||
|
||||
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
||||
//\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\EditController
|
||||
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
|
||||
$recurringRepos->shouldReceive('update')->once();
|
||||
|
||||
$tomorrow = Carbon::create()->addDays(2);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$data = [
|
||||
'id' => $recurrence->id,
|
||||
'title' => 'hello',
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'repetition_type' => 'daily',
|
||||
'skip' => 0,
|
||||
'recurring_description' => 'Some descr',
|
||||
'active' => '1',
|
||||
'apply_rules' => '1',
|
||||
'return_to_edit' => '1',
|
||||
// mandatory for transaction:
|
||||
'transaction_description' => 'Some descr',
|
||||
'transaction_type' => 'withdrawal',
|
||||
'transaction_currency_id' => '1',
|
||||
'amount' => '30',
|
||||
// mandatory account info:
|
||||
'source_id' => '1',
|
||||
'source_name' => '',
|
||||
'destination_id' => '',
|
||||
'destination_name' => 'Some Expense',
|
||||
|
||||
// optional fields:
|
||||
'budget_id' => '1',
|
||||
'category' => 'CategoryA',
|
||||
'tags' => 'A,B,C',
|
||||
'create_another' => '1',
|
||||
'repetition_end' => 'times',
|
||||
'repetitions' => 3,
|
||||
];
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('recurring.update', [1]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
}
|
||||
97
tests/Feature/Controllers/Recurring/IndexControllerTest.php
Normal file
97
tests/Feature/Controllers/Recurring/IndexControllerTest.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Recurring;
|
||||
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class IndexControllerTest
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Recurring\IndexController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
|
||||
$config = new Configuration;
|
||||
$config->data = 0;
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
$collection = $this->user()->recurrences()->take(2)->get();
|
||||
|
||||
// mock cron job config:
|
||||
\FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
|
||||
\FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
|
||||
$repository->shouldReceive('get')->andReturn($collection)->once();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Notes');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getNoteText')->andReturn('Notes');
|
||||
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
|
||||
$repository->shouldReceive('getXOccurrences')->andReturn([]);
|
||||
$repository->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('recurring.show', [$recurrence->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -231,7 +231,6 @@ class ExpenseControllerTest extends TestCase
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn($collection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.expenses', ['1', $expense->id, '20170101', '20170131']));
|
||||
@@ -248,6 +247,36 @@ class ExpenseControllerTest extends TestCase
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);
|
||||
|
||||
// fake collection:
|
||||
$transA = new Transaction;
|
||||
$transA->transaction_currency_id = 1;
|
||||
$transA->transaction_category_name = 'Category';
|
||||
$transA->transaction_category_id = 1;
|
||||
$transA->transaction_currency_symbol = 'A';
|
||||
$transA->transaction_currency_dp = 2;
|
||||
$transA->transaction_amount = '100';
|
||||
$transA->opposing_account_id = $expense->id;
|
||||
$transB = new Transaction;
|
||||
$transB->transaction_currency_id = 2;
|
||||
$transB->transaction_category_name = null;
|
||||
$transB->transaction_category_id = 0;
|
||||
$transB->transaction_journal_budget_name = 'Category2';
|
||||
$transB->transaction_journal_budget_id = 2;
|
||||
$transB->transaction_currency_symbol = 'A';
|
||||
$transB->transaction_currency_dp = 2;
|
||||
$transB->transaction_amount = '100';
|
||||
$transB->opposing_account_id = $expense->id;
|
||||
$collection = new Collection([$transA, $transB]);
|
||||
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getTransactions')->andReturn($collection);
|
||||
//$collector->shouldReceive('')->andReturnSelf();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('report-data.expense.income', ['1', $expense->id, '20170101', '20170131']));
|
||||
$response->assertStatus(200);
|
||||
|
||||
@@ -63,6 +63,23 @@ class CreateControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
*/
|
||||
public function testCreateFromBill(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('rules.create-from-bill', [1,1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Rule\CreateController
|
||||
*/
|
||||
|
||||
117
tests/Feature/Controllers/System/CronControllerTest.php
Normal file
117
tests/Feature/Controllers/System/CronControllerTest.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* CronControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\System;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CronControllerTest
|
||||
*/
|
||||
class CronControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||
*/
|
||||
public function testCron(): void
|
||||
{
|
||||
$users = new Collection([$this->user()]);
|
||||
$job = $this->mock(RecurringCronjob::class);
|
||||
$preference = new Preference();
|
||||
$preference->data = 'token';
|
||||
$job->shouldReceive('fire')->once()->andReturn(true);
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('all')->andReturn($users);
|
||||
\Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'access_token', null])
|
||||
->andReturn($preference)->once();
|
||||
$response = $this->get(route('cron.cron', ['token']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('The recurring transaction cron job fired successfully.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||
*/
|
||||
public function testCronException(): void
|
||||
{
|
||||
$users = new Collection([$this->user()]);
|
||||
$job = $this->mock(RecurringCronjob::class);
|
||||
$preference = new Preference();
|
||||
$preference->data = 'token';
|
||||
$job->shouldReceive('fire')->once()->andThrow(new FireflyException('Exception noted.'));
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('all')->andReturn($users);
|
||||
\Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'access_token', null])
|
||||
->andReturn($preference)->once();
|
||||
$response = $this->get(route('cron.cron', ['token']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Exception noted.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\System\CronController
|
||||
* @covers \FireflyIII\Support\Binder\CLIToken
|
||||
*/
|
||||
public function testCronFalse(): void
|
||||
{
|
||||
$users = new Collection([$this->user()]);
|
||||
$job = $this->mock(RecurringCronjob::class);
|
||||
$preference = new Preference();
|
||||
$preference->data = 'token';
|
||||
$job->shouldReceive('fire')->once()->andReturn(false);
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('all')->andReturn($users);
|
||||
\Preferences::shouldReceive('getForUser')
|
||||
->withArgs([Mockery::any(), 'access_token', null])
|
||||
->andReturn($preference)->once();
|
||||
$response = $this->get(route('cron.cron', ['token']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('The recurring transaction cron job did not fire.');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,6 @@ class ConvertControllerTest extends TestCase
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
|
||||
*/
|
||||
public function testIndexDepositTransfer(): void
|
||||
@@ -64,13 +63,7 @@ class ConvertControllerTest extends TestCase
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
// find deposit:
|
||||
$loop = 0;
|
||||
do {
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $deposit->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$deposit = $this->getRandomDeposit();
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
@@ -102,13 +95,7 @@ class ConvertControllerTest extends TestCase
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
// find deposit:
|
||||
$loop = 0;
|
||||
do {
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $deposit->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$deposit = $this->getRandomDeposit();
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->once();
|
||||
@@ -135,13 +122,7 @@ class ConvertControllerTest extends TestCase
|
||||
// mock stuff:
|
||||
|
||||
// find deposit:
|
||||
$loop = 0;
|
||||
do {
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $deposit->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$deposit = $this->getRandomDeposit();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn($deposit);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
@@ -190,13 +171,7 @@ class ConvertControllerTest extends TestCase
|
||||
// mock stuff:
|
||||
|
||||
// find transfer:
|
||||
$loop = 0;
|
||||
do {
|
||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $transfer->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$transfer = $this->getRandomTransfer();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn($transfer);
|
||||
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1')->once();
|
||||
@@ -215,13 +190,7 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexTransferWithdrawal(): void
|
||||
{
|
||||
// find transfer:
|
||||
$loop = 0;
|
||||
do {
|
||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $transfer->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$transfer = $this->getRandomTransfer();
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
@@ -247,13 +216,7 @@ class ConvertControllerTest extends TestCase
|
||||
{
|
||||
|
||||
// find withdrawal:
|
||||
$loop = 0;
|
||||
do {
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $withdrawal->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
@@ -278,13 +241,7 @@ class ConvertControllerTest extends TestCase
|
||||
public function testIndexWithdrawalTransfer(): void
|
||||
{
|
||||
// find withdrawal:
|
||||
$loop = 0;
|
||||
do {
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $withdrawal->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
// mock stuff:
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
|
||||
@@ -379,13 +336,7 @@ class ConvertControllerTest extends TestCase
|
||||
$account = $this->user()->accounts()->first();
|
||||
|
||||
// find withdrawal:
|
||||
$loop = 0;
|
||||
do {
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $withdrawal->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
|
||||
// mock stuff
|
||||
$messageBag = new MessageBag;
|
||||
@@ -459,12 +410,7 @@ class ConvertControllerTest extends TestCase
|
||||
public function testPostIndexTransferDeposit(): void
|
||||
{
|
||||
// find transfer:
|
||||
$loop = 0;
|
||||
do {
|
||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $transfer->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
$transfer =$this->getRandomTransfer();
|
||||
|
||||
// mock stuff
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
@@ -249,7 +249,9 @@ class SingleControllerTest extends TestCase
|
||||
// mock new account list:
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]])->andReturn(new Collection([$account]))->once();
|
||||
->withArgs(
|
||||
[[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]]
|
||||
)->andReturn(new Collection([$account]))->once();
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(6);
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -867,13 +869,7 @@ class SingleControllerTest extends TestCase
|
||||
}
|
||||
|
||||
// find withdrawal:
|
||||
$loop = 0;
|
||||
do {
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->inRandomOrder()->where('user_id', $this->user()->id)->first();
|
||||
$count = $withdrawal->transactions()->count();
|
||||
$loop++;
|
||||
} while ($count !== 2 && $loop < 30);
|
||||
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
$journalRepos->shouldReceive('update')->andReturn($withdrawal);
|
||||
|
||||
$this->session(['transactions.edit.uri' => 'http://localhost']);
|
||||
|
||||
Reference in New Issue
Block a user