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

486 lines
18 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;
2019-07-21 17:15:06 +02:00
use Amount;
2018-02-28 15:50:00 +01:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
2019-07-21 17:15:06 +02:00
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
2017-03-05 11:18:34 +01:00
use FireflyIII\Models\Bill;
2019-07-21 17:15:06 +02:00
use FireflyIII\Models\Preference;
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;
use FireflyIII\Repositories\User\UserRepositoryInterface;
2018-06-01 22:04:52 +02:00
use FireflyIII\TransactionRules\TransactionMatcher;
2018-12-17 07:09:44 +01:00
use FireflyIII\Transformers\BillTransformer;
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;
2019-07-21 17:15:06 +02:00
use Preferences;
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();
2019-04-09 20:05:20 +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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_bills_create');
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(AttachmentHelperInterface::class);
$this->mock(BillRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$bill = $this->getRandomBill();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(AttachmentHelperInterface::class);
$this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
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', [$bill->id]));
2017-02-12 12:21:44 +01:00
$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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$repository = $this->mock(BillRepositoryInterface::class);
$this->mock(AttachmentHelperInterface::class);
Preferences::shouldReceive('mark')->atLeast()->once();
2018-09-03 18:52:46 +02:00
2017-02-12 12:21:44 +01:00
$repository->shouldReceive('destroy')->andReturn(true);
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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$userRepos = $this->mock(UserRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$this->mock(AttachmentHelperInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$billRepos->shouldReceive('getNoteText')->andReturn('Hello');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
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
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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_bills_index');
2019-08-23 09:41:31 +02:00
Amount::shouldReceive('getDefaultCurrency')->andReturn($this->getEuro());
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$this->mock(AttachmentHelperInterface::class);
2019-07-25 14:19:49 +02:00
$bill = $this->getRandomBill();
$repository = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
2019-08-12 17:36:37 +02:00
$euro = $this->getEuro();
2019-08-29 17:53:25 +02:00
//$pref = new Preference;
//$pref->data = 50;
//Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
2019-07-21 17:15:06 +02:00
Amount::shouldReceive('formatAnything')->andReturn('-100');
2018-12-17 07:09:44 +01:00
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
2019-08-29 17:53:25 +02:00
['id' => 5, 'active' => true,
'name' => 'x', 'next_expected_match' => '2018-01-01',
'amount_min' => '10',
'amount_max' => '10',
2019-08-12 17:36:37 +02:00
'currency' => $this->getEuro(),
2019-08-09 18:06:43 +02:00
'currency_id' => $euro->id,
'currency_code' => $euro->code,
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places,
2019-07-24 19:02:41 +02:00
]
2018-12-17 07:09:44 +01:00
);
2018-09-03 18:52:46 +02:00
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
2019-07-23 17:33:23 +02:00
2018-02-07 16:49:11 +01:00
$collection = new Collection([$bill]);
2019-08-29 17:53:25 +02:00
$repository->shouldReceive('getBills')->andReturn($collection)->once();
2018-02-07 16:49:11 +01:00
$repository->shouldReceive('setUser');
2018-09-27 13:11:31 +02:00
$repository->shouldReceive('getNoteText')->andReturn('Hi there');
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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-25 14:19:49 +02:00
$rule = $this->getRandomRule();
$repository = $this->mock(BillRepositoryInterface::class);
2019-07-21 17:15:06 +02:00
$this->mock(AttachmentHelperInterface::class);
2018-09-03 18:52:46 +02:00
2019-07-23 17:33:23 +02:00
2018-06-01 22:04:52 +02:00
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection([$rule]));
//calls for transaction matcher:
$matcher = $this->mock(TransactionMatcher::class);
2018-12-21 15:42:40 +01:00
$matcher->shouldReceive('setSearchLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setTriggeredLimit')->once()->withArgs([100000]);
2018-06-01 22:04:52 +02:00
$matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
2019-07-21 17:15:06 +02:00
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
2018-06-01 22:04:52 +02:00
$repository->shouldReceive('linkCollectionToBill')->once();
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$bill = $this->getRandomInactiveBill();
$this->mock(AttachmentHelperInterface::class);
$this->mock(BillRepositoryInterface::class);
2017-03-18 11:02:02 +01:00
$this->be($this->user());
$response = $this->get(route('bills.rescan', [$bill->id]));
2017-03-18 11:02:02 +01:00
$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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_bills_show');
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$repository = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
$collector = $this->mock(GroupCollectorInterface::class);
$group = $this->getRandomWithdrawalGroup();
$this->mock(AttachmentHelperInterface::class);
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$paginator = new LengthAwarePaginator([$group], 1, 40, 1);
// mock collector:
$collector->shouldReceive('setBill')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator);
Amount::shouldReceive('formatAnything')->andReturn('-100');
2018-12-17 07:09:44 +01:00
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
$transformer->shouldReceive('getDefaultIncludes')->atLeast()->once();
$transformer->shouldReceive('getAvailableIncludes')->atLeast()->once();
2019-01-27 18:11:10 +01:00
$repository->shouldReceive('getAttachments')->atLeast()->once()->andReturn(new Collection);
2018-12-17 07:09:44 +01:00
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
'currency_symbol' => 'x', 'amount_min' => '10', 'amount_max' => '15',
]
2018-12-17 07:09:44 +01:00
);
2018-09-03 18:52:46 +02:00
$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');
2018-04-14 21:21:20 +02:00
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
$this->be($this->user());
$bill = $this->user()->bills()->first();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-21 17:15:06 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$repository->shouldReceive('store')->andReturn($bill);
2018-06-01 22:04:52 +02:00
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->once();
2018-08-05 20:42:45 +02:00
2018-06-01 22:04:52 +02:00
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'New Bill ' . $this->randomInt(),
2018-06-01 22:04:52 +02:00
'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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2018-06-01 22:04:52 +02:00
// mock stuff
2019-07-21 17:15:06 +02:00
$bill = $this->getRandomBill();
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
$repository->shouldReceive('store')->andReturn($bill);
2018-02-28 15:50:00 +01:00
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->once();
2017-03-05 11:18:34 +01:00
2017-02-12 12:21:44 +01:00
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'New Bill ' . $this->randomInt(),
2018-04-14 21:21:20 +02:00
'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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2018-06-01 22:04:52 +02:00
// mock stuff
2019-07-21 17:15:06 +02:00
$repository = $this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
2019-07-21 17:15:06 +02:00
$this->mock(AttachmentHelperInterface::class);
2018-08-06 19:14:30 +02:00
$repository->shouldReceive('store')->andReturn(null);
2018-06-01 22:04:52 +02:00
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'New Bill ' . $this->randomInt(),
2018-06-01 22:04:52 +02:00
'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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2018-06-01 22:04:52 +02:00
// mock stuff
2019-07-25 14:19:49 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
2018-08-06 19:14:30 +02:00
$repository->shouldReceive('store')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
$attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag);
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->once();
2018-06-01 22:04:52 +02:00
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'New Bill ' . $this->randomInt(),
2018-06-01 22:04:52 +02:00
'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
{
2019-07-21 17:15:06 +02:00
$this->mockDefaultSession();
2017-03-05 11:18:34 +01:00
// mock stuff
2019-07-25 14:19:49 +02:00
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
2018-09-03 18:52:46 +02:00
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);
2019-07-21 17:15:06 +02:00
Preferences::shouldReceive('mark')->atLeast()->once();
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,
2019-06-16 13:16:46 +02:00
'name' => 'Updated Bill ' . $this->randomInt(),
2018-06-01 22:04:52 +02:00
'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
}