firefly-iii/tests/Feature/Controllers/Transaction/SplitControllerTest.php

173 lines
7.5 KiB
PHP
Raw Normal View History

2017-02-12 11:40:39 -06:00
<?php
/**
* SplitControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace Tests\Feature\Controllers\Transaction;
2017-03-04 08:29:20 -06:00
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
2017-03-03 23:53:46 -06:00
use FireflyIII\Models\AccountType;
2017-03-04 08:29:20 -06:00
use FireflyIII\Models\Transaction;
2017-02-12 11:40:39 -06:00
use FireflyIII\Models\TransactionJournal;
2017-03-03 23:53:46 -06:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
2017-03-04 08:29:20 -06:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
2017-03-03 23:53:46 -06:00
use Illuminate\Support\Collection;
2017-03-04 08:29:20 -06:00
use Illuminate\Support\MessageBag;
2017-02-12 11:40:39 -06:00
use Tests\TestCase;
/**
* Class SplitControllerTest
*
* @package Tests\Feature\Controllers\Transaction
*/
class SplitControllerTest extends TestCase
{
2017-03-05 11:15:38 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
*/
public function testEditSingle()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$transactions = factory(Transaction::class, 1)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection)->once();
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
2017-02-12 11:40:39 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
2017-02-17 13:14:38 -06:00
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
2017-03-03 23:53:46 -06:00
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
2017-02-12 11:40:39 -06:00
*/
public function testEdit()
{
2017-03-03 23:53:46 -06:00
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
2017-03-04 08:29:20 -06:00
$transactions = factory(Transaction::class, 3)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
2017-03-03 23:53:46 -06:00
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection)->once();
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
2017-03-04 08:29:20 -06:00
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
2017-03-03 23:53:46 -06:00
2017-02-12 11:40:39 -06:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
2017-03-03 23:53:46 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
*/
public function testEditOpeningBalance()
{
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$opening->id]));
$response->assertStatus(302);
}
2017-02-12 11:40:39 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
2017-03-03 23:53:46 -06:00
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromInput
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromRequest
2017-02-12 11:40:39 -06:00
*/
public function testUpdate()
{
2017-03-18 14:53:44 -05:00
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
2017-02-12 11:40:39 -06:00
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$data = [
'id' => $deposit->id,
'what' => 'deposit',
'journal_description' => 'Updated salary',
'currency_id' => 1,
'journal_destination_account_id' => 1,
'journal_amount' => 1591,
'date' => '2014-01-24',
'tags' => '',
'transactions' => [
[
'description' => 'Split #1',
'source_account_name' => 'Job',
'amount' => 1591,
'category' => '',
],
],
];
2017-03-04 08:29:20 -06:00
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('updateSplitJournal')->andReturn($deposit);
$repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
$attachmentRepos = $this->mock(AttachmentHelperInterface::class);
$attachmentRepos->shouldReceive('saveAttachmentsForModel');
$attachmentRepos->shouldReceive('getMessages')->andReturn(new MessageBag);
2017-02-12 11:40:39 -06:00
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$deposit->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// journal is updated?
$response = $this->get(route('transactions.show', [$deposit->id]));
$response->assertStatus(200);
$response->assertSee('Updated salary');
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
2017-03-03 23:53:46 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
*/
public function testUpdateOpeningBalance()
{
2017-03-18 14:53:44 -05:00
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
2017-03-03 23:53:46 -06:00
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$data = [
'id' => $opening->id,
];
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
$response->assertStatus(302);
$response->assertSessionMissing('success');
}
2017-02-16 15:33:32 -06:00
}