Files
firefly-iii/tests/Feature/Controllers/PiggyBankControllerTest.php

514 lines
22 KiB
PHP
Raw Normal View History

2017-02-12 12:00:11 +01:00
<?php
/**
* PiggyBankControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* 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
2017-12-17 14:42:21 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-02-12 12:00:11 +01:00
*/
2017-07-08 06:28:44 +02:00
declare(strict_types=1);
2017-02-12 12:00:11 +01:00
namespace Tests\Feature\Controllers;
2018-03-07 10:18:22 +01:00
use Amount;
use Carbon\Carbon;
2017-03-05 18:15:38 +01:00
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
2017-02-12 12:32:13 +01:00
use FireflyIII\Models\PiggyBank;
2018-03-07 10:18:22 +01:00
use FireflyIII\Models\TransactionCurrency;
2017-03-05 18:15:38 +01:00
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2018-03-07 10:18:22 +01:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2017-03-05 18:15:38 +01:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
2017-02-17 20:14:38 +01:00
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
2017-03-05 18:15:38 +01:00
use Illuminate\Support\Collection;
2018-03-24 06:08:50 +01:00
use Log;
2018-06-01 22:04:52 +02:00
use Mockery;
2017-03-17 16:34:57 +01:00
use Steam;
2017-02-12 12:00:11 +01:00
use Tests\TestCase;
2017-03-05 18:15:38 +01:00
/**
* Class PiggyBankControllerTest
*
2017-08-12 10:27:45 +02:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-03-05 18:15:38 +01:00
*/
2017-02-12 12:00:11 +01:00
class PiggyBankControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
2018-03-24 06:08:50 +01:00
{
parent::setUp();
2018-09-03 18:52:46 +02:00
Log::info(sprintf('Now in %s.', \get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-02-12 12:21:44 +01:00
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testAdd(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
2018-04-27 11:29:09 +02:00
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.add', [1]));
$response->assertStatus(200);
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testAddMobile(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-02-28 15:50:00 +01:00
$piggyRepos->shouldReceive('getCurrentAmount')->andReturn('0');
2018-04-27 11:29:09 +02:00
$piggyRepos->shouldReceive('leftOnAccount')->andReturn('0');
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.add-money-mobile', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testCreate(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
2018-03-07 10:18:22 +01:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2017-03-05 18:15:38 +01:00
2018-03-07 10:18:22 +01:00
// new account list thing.
$currency = TransactionCurrency::first();
$account = factory(Account::class)->make();
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
2017-02-12 12:21:44 +01:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-03-07 10:18:22 +01:00
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('balance')->andReturn('0');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-03-07 10:18:22 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.create'));
2018-03-07 10:18:22 +01:00
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
2017-02-12 12:21:44 +01:00
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testDelete(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.delete', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testDestroy(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$repository->shouldReceive('destroy')->andReturn(true);
2017-03-18 20:53:44 +01:00
$this->session(['piggy-banks.delete.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->post(route('piggy-banks.destroy', [2]));
$response->assertStatus(302);
$response->assertSessionHas('success');
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('index'));
2017-02-12 12:21:44 +01:00
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testEdit(): void
2017-02-12 12:21:44 +01:00
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
2017-03-05 18:15:38 +01:00
// mock stuff
$account = factory(Account::class)->make();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-03-07 10:18:22 +01:00
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$account = factory(Account::class)->make();
2018-03-07 10:18:22 +01:00
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
2017-03-05 18:15:38 +01:00
$accountRepos->shouldReceive('getAccountsByType')
2018-03-07 10:18:22 +01:00
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(new Collection([$account]))->once();
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('balance')->andReturn('0');
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.edit', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIndex(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$currencyRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1234')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('1234')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$accountRepos->shouldReceive('getOpeningBalanceAmount')->withAnyArgs()->andReturn('10')->atLeast()->once();
$accountRepos->shouldReceive('getOpeningBalanceDate')->withAnyArgs()->andReturn(new Carbon())->atLeast()->once();
$accountRepos->shouldReceive('getNoteText')->withAnyArgs()->andReturn('Hello')->atLeast()->once();
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$piggies = $this->user()->piggyBanks()->take(2)->get();
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->once()->andReturn($first);
$repository->shouldReceive('getPiggyBanks')->andReturn($piggies);
2018-02-17 14:14:26 +01:00
$repository->shouldReceive('getCurrentAmount')->andReturn('10');
2018-04-27 11:29:09 +02:00
$repository->shouldReceive('setUser');
$repository->shouldReceive('correctOrder');
2018-05-31 20:04:19 +02:00
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('1');
2017-03-17 16:34:57 +01:00
2018-04-27 11:29:09 +02:00
Steam::shouldReceive('balance')->twice()->andReturn('1');
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.index'));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testPostAdd(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canAddAmount')->once()->andReturn(true);
$repository->shouldReceive('addAmount')->once()->andReturn(true);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$data = ['amount' => '1.123'];
$this->be($this->user());
$response = $this->post(route('piggy-banks.add', [1]), $data);
$response->assertStatus(302);
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('piggy-banks.index'));
2017-02-12 12:21:44 +01:00
$response->assertSessionHas('success');
}
/**
* Add way too much
2017-02-12 12:21:44 +01:00
*
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testPostAddTooMuch(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canAddAmount')->once()->andReturn(false);
2017-03-05 18:15:38 +01:00
$data = ['amount' => '1000'];
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->post(route('piggy-banks.add', [1]), $data);
2017-02-12 12:21:44 +01:00
$response->assertStatus(302);
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('error');
2017-02-12 12:21:44 +01:00
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testPostRemove(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canRemoveAmount')->once()->andReturn(true);
$repository->shouldReceive('removeAmount')->once()->andReturn(true);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$data = ['amount' => '1.123'];
$this->be($this->user());
$response = $this->post(route('piggy-banks.remove', [1]), $data);
$response->assertStatus(302);
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('piggy-banks.index'));
2017-02-12 12:21:44 +01:00
$response->assertSessionHas('success');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
*/
public function testPostRemoveTooMuch(): void
{
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('canRemoveAmount')->once()->andReturn(false);
$data = ['amount' => '1.123'];
$this->be($this->user());
$response = $this->post(route('piggy-banks.remove', [1]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('piggy-banks.index'));
$response->assertSessionHas('error');
}
2017-02-12 12:21:44 +01:00
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testRemove(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.remove', [1]));
$response->assertStatus(200);
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testRemoveMobile(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.remove-money-mobile', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* Test setting of order/
*
* @covers \FireflyIII\Http\Controllers\PiggyBankController
*/
public function testSetOrder(): void
{
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
2018-06-01 22:04:52 +02:00
$repository->shouldReceive('setOrder')->once()->withArgs([Mockery::any(), 3])->andReturn(false);
$data = ['order' => '3'];
$this->be($this->user());
$response = $this->post(route('piggy-banks.set-order', [1]), $data);
$response->assertStatus(200);
$response->assertExactJson(['data' => 'OK']);
}
/**
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2017-02-12 12:21:44 +01:00
*/
public function testShow(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$currencyRepos->shouldReceive('setUser');
2018-05-31 20:04:19 +02:00
$repository->shouldReceive('setUser')->once();
2018-07-01 09:27:22 +02:00
$journalRepos->shouldReceive('firstNull')->once()->andReturn($first);
2017-03-05 18:15:38 +01:00
$repository->shouldReceive('getEvents')->andReturn(new Collection);
2018-05-31 20:04:19 +02:00
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('1');
$repository->shouldReceive('getCurrentAmount')->andReturn('1');
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('piggy-banks.show', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2018-03-03 17:16:47 +01:00
* @covers \FireflyIII\Http\Requests\PiggyBankFormRequest
2017-02-12 12:21:44 +01:00
*/
public function testStore(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
$repository->shouldReceive('store')->andReturn(new PiggyBank);
2017-03-18 20:53:44 +01:00
$this->session(['piggy-banks.create.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$data = [
2018-03-28 19:38:20 +02:00
'name' => 'Piggy ' . random_int(999, 10000),
2017-02-12 12:21:44 +01:00
'targetamount' => '100.123',
'account_id' => 2,
'amount_currency_id_targetamount' => 1,
];
$this->be($this->user());
$response = $this->post(route('piggy-banks.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('index'));
2017-02-12 12:21:44 +01:00
}
/**
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Controllers\PiggyBankController
2018-03-03 17:16:47 +01:00
* @covers \FireflyIII\Http\Requests\PiggyBankFormRequest
2017-02-12 12:21:44 +01:00
*/
public function testUpdate(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 18:15:38 +01:00
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 18:15:38 +01:00
$repository->shouldReceive('update')->andReturn(new PiggyBank);
2017-03-18 20:53:44 +01:00
$this->session(['piggy-banks.edit.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$data = [
2018-03-03 17:16:47 +01:00
'id' => 3,
2018-03-28 19:38:20 +02:00
'name' => 'Updated Piggy ' . random_int(999, 10000),
2017-02-12 12:21:44 +01:00
'targetamount' => '100.123',
'account_id' => 2,
'amount_currency_id_targetamount' => 1,
];
$this->be($this->user());
$response = $this->post(route('piggy-banks.update', [3]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
2017-02-12 12:32:13 +01:00
$response->assertRedirect(route('index'));
2017-02-12 12:21:44 +01:00
}
2017-02-16 22:33:32 +01:00
}