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('
');
}
/**
* @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 testEdit()
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$transactions = factory(Transaction::class, 3)->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('');
}
/**
* @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);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromInput
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromRequest
*/
public function testUpdate()
{
$this->session(['transactions.edit-split.url' => 'http://localhost']);
$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' => '',
],
],
];
// 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);
$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('');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
*/
public function testUpdateOpeningBalance()
{
$this->session(['transactions.edit-split.url' => 'http://localhost']);
$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');
}
}