diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 49f52942af..520d3b8516 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -409,8 +409,6 @@ class AccountController extends Controller $cache->addProperty($account->id); if ($cache->has()) { - Log::debug('Entries are cached, return cache.'); - return $cache->get(); // @codeCoverageIgnore } diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 356188163f..c39ad146e1 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -792,10 +792,15 @@ Breadcrumbs::register( Breadcrumbs::register( 'transactions.mass.edit', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) { - $journalIds = $journals->pluck('id')->toArray(); - $what = strtolower($journals->first()->transactionType->type); - $breadcrumbs->parent('transactions.index', $what); - $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds)); + if($journals->count() > 0) { + $journalIds = $journals->pluck('id')->toArray(); + $what = strtolower($journals->first()->transactionType->type); + $breadcrumbs->parent('transactions.index', $what); + $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds)); + return; + } + + $breadcrumbs->parent('index'); } ); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index b238ad4bf8..c32a34ff00 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -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( FireflyIII\Models\Account::class, function (Faker\Generator $faker) { return [ diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.php index e15ca29237..cdae7253b2 100644 --- a/tests/Feature/Controllers/AccountControllerTest.php +++ b/tests/Feature/Controllers/AccountControllerTest.php @@ -16,14 +16,21 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\Transaction; +use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountTaskerInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; use Steam; use Tests\TestCase; +/** + * Class AccountControllerTest + * + * @package Tests\Feature\Controllers + */ class AccountControllerTest extends TestCase { /** @@ -32,9 +39,10 @@ class AccountControllerTest extends TestCase public function testCreate() { // mock stuff - $collector = $this->mock(JournalCollectorInterface::class); - $repository = $this->mock(CurrencyRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(CurrencyRepositoryInterface::class); $repository->shouldReceive('get')->andReturn(new Collection); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('accounts.create', ['asset'])); @@ -49,9 +57,10 @@ class AccountControllerTest extends TestCase public function testDelete() { // mock stuff - $collector = $this->mock(JournalCollectorInterface::class); - $repository = $this->mock(AccountRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); @@ -68,10 +77,11 @@ class AccountControllerTest extends TestCase public function testDestroy() { // mock stuff - $collector = $this->mock(JournalCollectorInterface::class); - $repository = $this->mock(AccountRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account); $repository->shouldReceive('destroy')->andReturn(true); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']); $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); @@ -88,9 +98,10 @@ class AccountControllerTest extends TestCase public function testEdit() { // mock stuff - $collector = $this->mock(JournalCollectorInterface::class); - $repository = $this->mock(CurrencyRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(CurrencyRepositoryInterface::class); $repository->shouldReceive('get')->andReturn(new Collection); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); @@ -111,9 +122,11 @@ class AccountControllerTest extends TestCase public function testIndex(string $range) { // mock stuff - $account = factory(Account::class)->make(); - $repository = $this->mock(AccountRepositoryInterface::class); + $account = factory(Account::class)->make(); + $repository = $this->mock(AccountRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); $repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); Steam::shouldReceive('balancesById')->andReturn([]); Steam::shouldReceive('getLastActivities')->andReturn([]); @@ -138,7 +151,9 @@ class AccountControllerTest extends TestCase $this->session(['start' => $date, 'end' => clone $date]); // 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('amountInInPeriod')->withAnyArgs()->andReturn('1'); @@ -172,8 +187,10 @@ class AccountControllerTest extends TestCase public function testShowAll(string $range) { // mock stuff - $transaction = factory(Transaction::class)->make(); - $collector = $this->mock(JournalCollectorInterface::class); + $transaction = factory(Transaction::class)->make(); + $collector = $this->mock(JournalCollectorInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $collector->shouldReceive('setAccounts')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); @@ -204,7 +221,9 @@ class AccountControllerTest extends TestCase */ public function testShowBrokenInitial() { - $date = new Carbon; + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); + $date = new Carbon; $this->session(['start' => $date, 'end' => clone $date]); $this->be($this->user()); @@ -222,8 +241,10 @@ class AccountControllerTest extends TestCase public function testShowByDate(string $range) { // mock stuff - $transaction = factory(Transaction::class)->make(); - $collector = $this->mock(JournalCollectorInterface::class); + $transaction = factory(Transaction::class)->make(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); + $collector = $this->mock(JournalCollectorInterface::class); $collector->shouldReceive('setAccounts')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); @@ -254,7 +275,9 @@ class AccountControllerTest extends TestCase public function testShowByDateEmpty(string $range) { // 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('setRange')->andReturnSelf(); $collector->shouldReceive('setLimit')->andReturnSelf(); @@ -282,7 +305,9 @@ class AccountControllerTest extends TestCase */ public function testShowInitial() { - $date = new Carbon; + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); + $date = new Carbon; $this->session(['start' => $date, 'end' => clone $date]); $this->be($this->user()); @@ -296,9 +321,11 @@ class AccountControllerTest extends TestCase */ public function testStore() { - $repository = $this->mock(AccountRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('find')->andReturn(new Account)->once(); $repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make()); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->session(['accounts.create.url' => 'http://localhost']); $this->be($this->user()); @@ -317,9 +344,11 @@ class AccountControllerTest extends TestCase */ public function testUpdate() { - $repository = $this->mock(AccountRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('find')->andReturn(new Account)->once(); $repository->shouldReceive('update')->once(); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->session(['accounts.edit.url' => 'http://localhost']); $this->be($this->user()); diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php index 4608209dbc..49dad45c41 100644 --- a/tests/Feature/Controllers/AttachmentControllerTest.php +++ b/tests/Feature/Controllers/AttachmentControllerTest.php @@ -12,7 +12,9 @@ declare(strict_types = 1); namespace Tests\Feature\Controllers; +use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Tests\TestCase; class AttachmentControllerTest extends TestCase @@ -22,6 +24,8 @@ class AttachmentControllerTest extends TestCase */ public function testDelete() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('attachments.delete', [1])); $response->assertStatus(200); @@ -34,10 +38,13 @@ class AttachmentControllerTest extends TestCase */ public function testDestroy() { - $this->session(['attachments.delete.url' => 'http://localhost']); - + // mock stuff + $journalRepos = $this->mock(JournalRepositoryInterface::class); $repository = $this->mock(AttachmentRepositoryInterface::class); $repository->shouldReceive('destroy')->andReturn(true); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); + + $this->session(['attachments.delete.url' => 'http://localhost']); $this->be($this->user()); $response = $this->post(route('attachments.destroy', [1])); $response->assertStatus(302); @@ -49,9 +56,12 @@ class AttachmentControllerTest extends TestCase */ public function testDownload() { + // mock stuff + $journalRepos = $this->mock(JournalRepositoryInterface::class); $repository = $this->mock(AttachmentRepositoryInterface::class); $repository->shouldReceive('exists')->once()->andReturn(true); $repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.'); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('attachments.download', [1])); @@ -65,6 +75,8 @@ class AttachmentControllerTest extends TestCase */ public function testEdit() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('attachments.edit', [1])); $response->assertStatus(200); @@ -78,6 +90,8 @@ class AttachmentControllerTest extends TestCase */ public function testPreview() { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('attachments.preview', [1])); $response->assertStatus(200); @@ -88,6 +102,12 @@ class AttachmentControllerTest extends TestCase */ 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']); $data = [ 'title' => 'Some updated title ' . rand(1000, 9999), @@ -99,14 +119,6 @@ class AttachmentControllerTest extends TestCase $response = $this->post(route('attachments.update', [1]), $data); $response->assertStatus(302); $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('