mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Updated tests
This commit is contained in:
parent
884d6c59a2
commit
e5a2e1a8c7
@ -409,8 +409,6 @@ class AccountController extends Controller
|
|||||||
$cache->addProperty($account->id);
|
$cache->addProperty($account->id);
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
Log::debug('Entries are cached, return cache.');
|
|
||||||
|
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,10 +792,15 @@ Breadcrumbs::register(
|
|||||||
Breadcrumbs::register(
|
Breadcrumbs::register(
|
||||||
'transactions.mass.edit', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) {
|
'transactions.mass.edit', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) {
|
||||||
|
|
||||||
|
if($journals->count() > 0) {
|
||||||
$journalIds = $journals->pluck('id')->toArray();
|
$journalIds = $journals->pluck('id')->toArray();
|
||||||
$what = strtolower($journals->first()->transactionType->type);
|
$what = strtolower($journals->first()->transactionType->type);
|
||||||
$breadcrumbs->parent('transactions.index', $what);
|
$breadcrumbs->parent('transactions.index', $what);
|
||||||
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
|
$breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$breadcrumbs->parent('index');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,6 +33,15 @@ $factory->define(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$factory->define(
|
||||||
|
FireflyIII\Models\Budget::class, function (Faker\Generator $faker) {
|
||||||
|
return [
|
||||||
|
'id' => $faker->numberBetween(1, 10),
|
||||||
|
'name' => $faker->words(3, true),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$factory->define(
|
$factory->define(
|
||||||
FireflyIII\Models\Account::class, function (Faker\Generator $faker) {
|
FireflyIII\Models\Account::class, function (Faker\Generator $faker) {
|
||||||
return [
|
return [
|
||||||
|
@ -16,14 +16,21 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Steam;
|
use Steam;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AccountControllerTest
|
||||||
|
*
|
||||||
|
* @package Tests\Feature\Controllers
|
||||||
|
*/
|
||||||
class AccountControllerTest extends TestCase
|
class AccountControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -32,9 +39,10 @@ class AccountControllerTest extends TestCase
|
|||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('accounts.create', ['asset']));
|
$response = $this->get(route('accounts.create', ['asset']));
|
||||||
@ -49,9 +57,10 @@ class AccountControllerTest extends TestCase
|
|||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -68,10 +77,11 @@ class AccountControllerTest extends TestCase
|
|||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account);
|
$repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account);
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']);
|
$this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']);
|
||||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||||
@ -88,9 +98,10 @@ class AccountControllerTest extends TestCase
|
|||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||||
@ -113,7 +124,9 @@ class AccountControllerTest extends TestCase
|
|||||||
// mock stuff
|
// mock stuff
|
||||||
$account = factory(Account::class)->make();
|
$account = factory(Account::class)->make();
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
Steam::shouldReceive('balancesById')->andReturn([]);
|
Steam::shouldReceive('balancesById')->andReturn([]);
|
||||||
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
||||||
|
|
||||||
@ -139,6 +152,8 @@ class AccountControllerTest extends TestCase
|
|||||||
|
|
||||||
// mock stuff:
|
// mock stuff:
|
||||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
||||||
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
||||||
|
|
||||||
@ -174,6 +189,8 @@ class AccountControllerTest extends TestCase
|
|||||||
// mock stuff
|
// mock stuff
|
||||||
$transaction = factory(Transaction::class)->make();
|
$transaction = factory(Transaction::class)->make();
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
@ -204,6 +221,8 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowBrokenInitial()
|
public function testShowBrokenInitial()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
@ -223,6 +242,8 @@ class AccountControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$transaction = factory(Transaction::class)->make();
|
$transaction = factory(Transaction::class)->make();
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
@ -255,6 +276,8 @@ class AccountControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
// mock stuff
|
// mock stuff
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
@ -282,6 +305,8 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowInitial()
|
public function testShowInitial()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
@ -296,9 +321,11 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository->shouldReceive('find')->andReturn(new Account)->once();
|
$repository->shouldReceive('find')->andReturn(new Account)->once();
|
||||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->session(['accounts.create.url' => 'http://localhost']);
|
$this->session(['accounts.create.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -317,9 +344,11 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository->shouldReceive('find')->andReturn(new Account)->once();
|
$repository->shouldReceive('find')->andReturn(new Account)->once();
|
||||||
$repository->shouldReceive('update')->once();
|
$repository->shouldReceive('update')->once();
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->session(['accounts.edit.url' => 'http://localhost']);
|
$this->session(['accounts.edit.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
|
@ -12,7 +12,9 @@ declare(strict_types = 1);
|
|||||||
namespace Tests\Feature\Controllers;
|
namespace Tests\Feature\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class AttachmentControllerTest extends TestCase
|
class AttachmentControllerTest extends TestCase
|
||||||
@ -22,6 +24,8 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('attachments.delete', [1]));
|
$response = $this->get(route('attachments.delete', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -34,10 +38,13 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
$this->session(['attachments.delete.url' => 'http://localhost']);
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$this->session(['attachments.delete.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('attachments.destroy', [1]));
|
$response = $this->post(route('attachments.destroy', [1]));
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -49,9 +56,12 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDownload()
|
public function testDownload()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||||
$repository->shouldReceive('exists')->once()->andReturn(true);
|
$repository->shouldReceive('exists')->once()->andReturn(true);
|
||||||
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
|
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('attachments.download', [1]));
|
$response = $this->get(route('attachments.download', [1]));
|
||||||
@ -65,6 +75,8 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('attachments.edit', [1]));
|
$response = $this->get(route('attachments.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -78,6 +90,8 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testPreview()
|
public function testPreview()
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('attachments.preview', [1]));
|
$response = $this->get(route('attachments.preview', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -88,6 +102,12 @@ class AttachmentControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('update')->once();
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->session(['attachments.edit.url' => 'http://localhost']);
|
$this->session(['attachments.edit.url' => 'http://localhost']);
|
||||||
$data = [
|
$data = [
|
||||||
'title' => 'Some updated title ' . rand(1000, 9999),
|
'title' => 'Some updated title ' . rand(1000, 9999),
|
||||||
@ -99,14 +119,6 @@ class AttachmentControllerTest extends TestCase
|
|||||||
$response = $this->post(route('attachments.update', [1]), $data);
|
$response = $this->post(route('attachments.update', [1]), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
// view should be updated
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('attachments.edit', [1]));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
// has bread crumb
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
$response->assertSee($data['title']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,13 @@ declare(strict_types = 1);
|
|||||||
namespace Tests\Feature\Controllers;
|
namespace Tests\Feature\Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@ -23,6 +29,10 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.create'));
|
$response = $this->get(route('bills.create'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -35,6 +45,10 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.delete', [1]));
|
$response = $this->get(route('bills.delete', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -47,8 +61,11 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(BillRepositoryInterface::class);
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->session(['bills.delete.url' => 'http://localhost']);
|
$this->session(['bills.delete.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
@ -62,6 +79,10 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.edit', [1]));
|
$response = $this->get(route('bills.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -75,6 +96,12 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('getBills')->andReturn(new Collection);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.index'));
|
$response = $this->get(route('bills.index'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -87,8 +114,12 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testRescan()
|
public function testRescan()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(BillRepositoryInterface::class);
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection);
|
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.rescan', [1]));
|
$response = $this->get(route('bills.rescan', [1]));
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -100,6 +131,23 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow()
|
public function testShow()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('getYearAverage')->andReturn('0');
|
||||||
|
$repository->shouldReceive('getOverallAverage')->andReturn('0');
|
||||||
|
$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setBills')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('bills.show', [1]));
|
$response = $this->get(route('bills.show', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -112,6 +160,12 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('store')->andReturn(new Bill);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'New Bill ' . rand(1000, 9999),
|
'name' => 'New Bill ' . rand(1000, 9999),
|
||||||
'match' => 'some words',
|
'match' => 'some words',
|
||||||
@ -128,13 +182,6 @@ class BillControllerTest extends TestCase
|
|||||||
$response = $this->post(route('bills.store'), $data);
|
$response = $this->post(route('bills.store'), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
// list must be updated
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('bills.index'));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
$response->assertSee($data['name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,6 +189,12 @@ class BillControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(BillRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('update')->andReturn(new Bill);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'Updated Bill ' . rand(1000, 9999),
|
'name' => 'Updated Bill ' . rand(1000, 9999),
|
||||||
'match' => 'some more words',
|
'match' => 'some more words',
|
||||||
@ -159,12 +212,6 @@ class BillControllerTest extends TestCase
|
|||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
// list must be updated
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('bills.index'));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
$response->assertSee($data['name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,12 @@ namespace Tests\Feature\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -26,9 +30,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testAmount()
|
public function testAmount()
|
||||||
{
|
{
|
||||||
$data = [
|
// mock stuff
|
||||||
'amount' => 200,
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
];
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
|
||||||
|
|
||||||
|
$data = ['amount' => 200,];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.amount', [1]), $data);
|
$response = $this->post(route('budgets.amount', [1]), $data);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -39,6 +47,10 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.create'));
|
$response = $this->get(route('budgets.create'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -51,6 +63,10 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.delete', [1]));
|
$response = $this->get(route('budgets.delete', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -63,11 +79,14 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
$this->session(['budgets.delete.url' => 'http://localhost']);
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
|
$this->session(['budgets.delete.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.destroy', [1]));
|
$response = $this->post(route('budgets.destroy', [1]));
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -79,6 +98,10 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.edit', [1]));
|
$response = $this->get(route('budgets.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -96,7 +119,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex(string $range)
|
public function testIndex(string $range)
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
$repository->shouldReceive('cleanupBudgets');
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||||
@ -119,10 +148,11 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoBudget(string $range)
|
public function testNoBudget(string $range)
|
||||||
{
|
{
|
||||||
$date = new Carbon();
|
// mock stuff
|
||||||
$this->session(['start' => $date, 'end' => clone $date]);
|
|
||||||
|
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
@ -131,6 +161,9 @@ class BudgetControllerTest extends TestCase
|
|||||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
|
$date = new Carbon();
|
||||||
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('budgets.no-budget'));
|
$response = $this->get(route('budgets.no-budget'));
|
||||||
@ -144,9 +177,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testPostUpdateIncome()
|
public function testPostUpdateIncome()
|
||||||
{
|
{
|
||||||
$data = [
|
// mock stuff
|
||||||
'amount' => '200',
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
];
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('setAvailableBudget');
|
||||||
|
|
||||||
|
$data = ['amount' => '200',];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('budgets.income.post'), $data);
|
$response = $this->post(route('budgets.income.post'), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -161,20 +198,10 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow(string $range)
|
public function testShow(string $range)
|
||||||
{
|
{
|
||||||
$date = new Carbon();
|
// mock stuff
|
||||||
$date->subDay();
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
$this->session(['first' => $date]);
|
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
// mock account repository
|
|
||||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
|
||||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
|
||||||
|
|
||||||
|
|
||||||
// mock budget repository
|
|
||||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
|
||||||
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
|
||||||
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
|
||||||
// mock journal collector:
|
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
@ -184,6 +211,16 @@ class BudgetControllerTest extends TestCase
|
|||||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||||
|
|
||||||
|
$date = new Carbon();
|
||||||
|
$date->subDay();
|
||||||
|
$this->session(['first' => $date]);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
@ -200,10 +237,15 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowByBudgetLimit(string $range)
|
public function testShowByBudgetLimit(string $range)
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
// mock account repository
|
// mock account repository
|
||||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
|
|
||||||
// mock budget repository
|
// mock budget repository
|
||||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||||
@ -233,6 +275,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$budget = factory(Budget::class)->make();
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('find')->andReturn($budget);
|
||||||
|
$repository->shouldReceive('store')->andReturn($budget);
|
||||||
$this->session(['budgets.create.url' => 'http://localhost']);
|
$this->session(['budgets.create.url' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -249,6 +298,14 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$budget = factory(Budget::class)->make();
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('find')->andReturn($budget);
|
||||||
|
$repository->shouldReceive('update');
|
||||||
|
|
||||||
$this->session(['budgets.edit.url' => 'http://localhost']);
|
$this->session(['budgets.edit.url' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -266,6 +323,12 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdateIncome()
|
public function testUpdateIncome()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
|
||||||
|
|
||||||
// must be in list
|
// must be in list
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('budgets.income', [1]));
|
$response = $this->get(route('budgets.income', [1]));
|
||||||
|
@ -13,8 +13,11 @@ namespace Tests\Feature\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -26,6 +29,10 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('categories.create'));
|
$response = $this->get(route('categories.create'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -38,6 +45,10 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDelete()
|
public function testDelete()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('categories.delete', [1]));
|
$response = $this->get(route('categories.delete', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -50,10 +61,15 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
$this->session(['categories.delete.url' => 'http://localhost']);
|
// mock stuff
|
||||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
|
$this->session(['categories.delete.url' => 'http://localhost']);
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->post(route('categories.destroy', [1]));
|
$response = $this->post(route('categories.destroy', [1]));
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
@ -65,6 +81,10 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEdit()
|
public function testEdit()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('categories.edit', [1]));
|
$response = $this->get(route('categories.edit', [1]));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -78,6 +98,13 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex()
|
public function testIndex()
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('getCategories')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('categories.index'));
|
$response = $this->get(route('categories.index'));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -93,6 +120,16 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoCategory(string $range)
|
public function testNoCategory(string $range)
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withoutCategory')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getJournals')->andReturn(new Collection);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('categories.no-category'));
|
$response = $this->get(route('categories.no-category'));
|
||||||
@ -103,21 +140,27 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\CategoryController::show
|
* @covers \FireflyIII\Http\Controllers\CategoryController::show
|
||||||
|
* @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
|
||||||
|
*
|
||||||
* @dataProvider dateRangeProvider
|
* @dataProvider dateRangeProvider
|
||||||
*
|
*
|
||||||
* @param string $range
|
* @param string $range
|
||||||
*/
|
*/
|
||||||
public function testShow(string $range)
|
public function testShow(string $range)
|
||||||
{
|
{
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
|
||||||
|
$repository->shouldReceive('spentInPeriod')->andReturn('0');
|
||||||
|
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
|
||||||
|
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
|
||||||
|
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$accRepository = $this->mock(AccountRepositoryInterface::class);
|
|
||||||
$catRepository = $this->mock(CategoryRepositoryInterface::class);
|
|
||||||
|
|
||||||
$accRepository->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
|
|
||||||
$catRepository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
|
|
||||||
|
|
||||||
// collector stuff:
|
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||||
@ -126,11 +169,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
||||||
|
|
||||||
// more repos stuff:
|
|
||||||
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
||||||
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
|
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$response = $this->get(route('categories.show', [1]));
|
$response = $this->get(route('categories.show', [1]));
|
||||||
@ -146,16 +184,19 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowAll(string $range)
|
public function testShowAll(string $range)
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
|
||||||
// collector stuff:
|
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
@ -166,15 +207,22 @@ class CategoryControllerTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
|
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
|
||||||
|
* @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
|
||||||
* @dataProvider dateRangeProvider
|
* @dataProvider dateRangeProvider
|
||||||
*
|
*
|
||||||
* @param string $range
|
* @param string $range
|
||||||
*/
|
*/
|
||||||
public function testShowByDate(string $range)
|
public function testShowByDate(string $range)
|
||||||
{
|
{
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
// collector stuff:
|
|
||||||
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||||
@ -183,8 +231,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
||||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
||||||
|
|
||||||
// mock category repository
|
|
||||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
|
||||||
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
|
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
|
||||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||||
$repository->shouldReceive('earnedInPeriod')->andReturn('1');
|
$repository->shouldReceive('earnedInPeriod')->andReturn('1');
|
||||||
@ -202,6 +248,12 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('find')->andReturn(new Category);
|
||||||
|
$repository->shouldReceive('store')->andReturn(new Category);
|
||||||
|
|
||||||
$this->session(['categories.create.url' => 'http://localhost']);
|
$this->session(['categories.create.url' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -211,13 +263,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
$response = $this->post(route('categories.store'), $data);
|
$response = $this->post(route('categories.store'), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
// must be in list
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('categories.index'));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
$response->assertSee($data['name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,6 +270,12 @@ class CategoryControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||||
|
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
$repository->shouldReceive('update');
|
||||||
|
$repository->shouldReceive('find')->andReturn(new Category);
|
||||||
|
|
||||||
$this->session(['categories.edit.url' => 'http://localhost']);
|
$this->session(['categories.edit.url' => 'http://localhost']);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
@ -235,13 +286,6 @@ class CategoryControllerTest extends TestCase
|
|||||||
$response = $this->post(route('categories.update', [1]), $data);
|
$response = $this->post(route('categories.update', [1]), $data);
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
|
|
||||||
// must be in list
|
|
||||||
$this->be($this->user());
|
|
||||||
$response = $this->get(route('categories.index'));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
|
||||||
$response->assertSee($data['name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user