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

469 lines
20 KiB
PHP
Raw Normal View History

2017-02-12 12:00:11 +01:00
<?php
/**
* BillControllerTest.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;
2017-03-05 11:18:34 +01:00
use Carbon\Carbon;
2018-02-28 15:50:00 +01:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
2017-03-05 11:18:34 +01:00
use FireflyIII\Models\Bill;
2018-06-01 22:04:52 +02:00
use FireflyIII\Models\Rule;
2017-03-05 11:18:34 +01:00
use FireflyIII\Models\TransactionJournal;
2017-02-12 12:21:44 +01:00
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
2018-09-03 18:52:46 +02:00
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2017-03-05 11:18:34 +01:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
2018-06-01 22:04:52 +02:00
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
2018-09-03 18:52:46 +02:00
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-06-01 22:04:52 +02:00
use FireflyIII\TransactionRules\TransactionMatcher;
2017-03-05 11:18:34 +01:00
use Illuminate\Pagination\LengthAwarePaginator;
2017-02-12 12:21:44 +01:00
use Illuminate\Support\Collection;
2018-02-28 15:50:00 +01:00
use Illuminate\Support\MessageBag;
2018-03-24 06:08:50 +01:00
use Log;
2018-06-01 22:04:52 +02:00
use Mockery;
2017-02-12 12:00:11 +01:00
use Tests\TestCase;
2017-08-12 10:27:45 +02:00
/**
* Class BillControllerTest
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
2017-02-12 12:00:11 +01:00
class BillControllerTest 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-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
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 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.create'));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
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 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.delete', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
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 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
2017-02-12 12:21:44 +01:00
$repository->shouldReceive('destroy')->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-02-12 12:21:44 +01:00
2017-03-18 20:53:44 +01:00
$this->session(['bills.delete.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->post(route('bills.destroy', [1]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
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
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$billRepos->shouldReceive('getNoteText')->andReturn('Hello');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.edit', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
* @covers \FireflyIII\Http\Controllers\BillController
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 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$bill = factory(Bill::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-02-07 16:49:11 +01:00
$collection = new Collection([$bill]);
$repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();
$repository->shouldReceive('setUser');
2017-12-06 19:41:51 +01:00
$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
2018-04-14 21:21:20 +02:00
$repository->shouldReceive('getRulesForBills')->andReturn([]);
2018-02-07 16:49:11 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.index'));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testRescan(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$rule = Rule::first();
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journal = factory(TransactionJournal::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-06-01 22:04:52 +02:00
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection([$rule]));
//calls for transaction matcher:
2018-09-03 18:52:46 +02:00
// todo bad to do this:
2018-06-01 22:04:52 +02:00
$matcher = $this->mock(TransactionMatcher::class);
$matcher->shouldReceive('setLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setRange')->once()->withArgs([100000]);
$matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn(new Collection);
$repository->shouldReceive('linkCollectionToBill')->once();
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.rescan', [1]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
2017-03-18 11:02:02 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2017-03-18 11:02:02 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testRescanInactive(): void
2017-03-18 11:02:02 +01:00
{
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-18 11:02:02 +01:00
$this->be($this->user());
$response = $this->get(route('bills.rescan', [3]));
$response->assertStatus(302);
$response->assertSessionHas('warning');
}
2017-02-12 12:21:44 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testShow(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
2018-08-06 19:14:30 +02:00
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2017-03-05 11:18:34 +01:00
$repository->shouldReceive('getYearAverage')->andReturn('0');
$repository->shouldReceive('getOverallAverage')->andReturn('0');
$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
2018-04-14 21:21:20 +02:00
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 11:18:34 +01:00
$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('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
2017-12-06 19:41:51 +01:00
$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
2018-02-07 16:49:11 +01:00
$repository->shouldReceive('setUser');
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->get(route('bills.show', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\BillController
2018-03-03 17:16:47 +01:00
* @covers \FireflyIII\Http\Requests\BillFormRequest
* @covers \FireflyIII\Http\Requests\Request
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testStore(): void
2017-02-12 12:21:44 +01:00
{
$this->be($this->user());
$bill = $this->user()->bills()->first();
2017-03-05 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
2018-06-01 22:04:52 +02:00
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn($bill);
2018-06-01 22:04:52 +02:00
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2018-08-05 20:42:45 +02:00
2018-06-01 22:04:52 +02:00
$data = [
'name' => 'New Bill ' . random_int(1000, 9999),
'amount_min' => '100',
'transaction_currency_id' => 1,
'skip' => 0,
'strict' => 1,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
];
$this->session(['bills.create.uri' => 'http://localhost']);
2018-06-01 22:04:52 +02:00
$response = $this->post(route('bills.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Requests\BillFormRequest
* @covers \FireflyIII\Http\Requests\Request
*/
public function testStoreCreateAnother(): void
{
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$bill = $this->user()->bills()->first();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('store')->andReturn($bill);
2018-02-28 15:50:00 +01:00
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$data = [
2018-04-14 21:21:20 +02:00
'name' => 'New Bill ' . random_int(1000, 9999),
'amount_min' => '100',
'transaction_currency_id' => 1,
'skip' => 0,
2018-06-01 22:04:52 +02:00
'create_another' => '1',
2018-04-14 21:21:20 +02:00
'strict' => 1,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
2017-02-12 12:21:44 +01:00
];
2017-03-18 20:53:44 +01:00
$this->session(['bills.create.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->post(route('bills.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
2018-06-01 22:04:52 +02:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Requests\BillFormRequest
* @covers \FireflyIII\Http\Requests\Request
*/
2018-08-06 19:14:30 +02:00
public function testStoreError(): void
2018-06-01 22:04:52 +02:00
{
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
2018-06-01 22:04:52 +02:00
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-08-06 19:14:30 +02:00
$repository->shouldReceive('store')->andReturn(null);
2018-06-01 22:04:52 +02:00
$data = [
'name' => 'New Bill ' . random_int(1000, 9999),
'amount_min' => '100',
'transaction_currency_id' => 1,
'skip' => 0,
'strict' => 1,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
];
$this->be($this->user());
$response = $this->post(route('bills.store'), $data);
$response->assertStatus(302);
2018-08-06 19:14:30 +02:00
$response->assertSessionHas('error');
$response->assertRedirect(route('bills.create'));
2018-06-01 22:04:52 +02:00
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2018-06-01 22:04:52 +02:00
* @covers \FireflyIII\Http\Requests\BillFormRequest
* @covers \FireflyIII\Http\Requests\Request
*/
2018-08-06 19:14:30 +02:00
public function testStoreNoGroup(): void
2018-06-01 22:04:52 +02:00
{
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
2018-06-01 22:04:52 +02:00
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2018-08-06 19:14:30 +02:00
$repository->shouldReceive('store')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2018-06-01 22:04:52 +02:00
$data = [
'name' => 'New Bill ' . random_int(1000, 9999),
'amount_min' => '100',
'transaction_currency_id' => 1,
'skip' => 0,
2018-08-06 19:14:30 +02:00
'create_another' => '1',
2018-06-01 22:04:52 +02:00
'strict' => 1,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
];
2018-08-06 19:14:30 +02:00
$this->session(['bills.create.uri' => 'http://localhost']);
2018-06-01 22:04:52 +02:00
$this->be($this->user());
$response = $this->post(route('bills.store'), $data);
$response->assertStatus(302);
2018-08-06 19:14:30 +02:00
$response->assertSessionHas('success');
2018-06-01 22:04:52 +02:00
}
2017-02-12 12:21:44 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\BillController
2018-03-03 17:16:47 +01:00
* @covers \FireflyIII\Http\Requests\BillFormRequest
* @covers \FireflyIII\Http\Requests\Request
2017-02-12 12:21:44 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdate(): void
2017-02-12 12:21:44 +01:00
{
2017-03-05 11:18:34 +01:00
// mock stuff
2018-08-06 19:14:30 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
2017-03-05 11:18:34 +01:00
$repository->shouldReceive('update')->andReturn(new Bill);
2018-02-28 15:50:00 +01:00
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$data = [
2018-06-01 22:04:52 +02:00
'id' => 1,
'name' => 'Updated Bill ' . random_int(1000, 9999),
'amount_min' => '100',
2018-04-14 21:21:20 +02:00
'transaction_currency_id' => 1,
2018-06-01 22:04:52 +02:00
'skip' => 0,
'amount_max' => '100',
'date' => '2016-01-01',
'repeat_freq' => 'monthly',
2017-02-12 12:21:44 +01:00
];
2017-03-18 20:53:44 +01:00
$this->session(['bills.edit.uri' => 'http://localhost']);
2017-02-12 12:21:44 +01:00
$this->be($this->user());
$response = $this->post(route('bills.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
2017-02-16 22:33:32 +01:00
}