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

159 lines
5.6 KiB
PHP
Raw Normal View History

2017-12-23 10:42:07 -06:00
<?php
/**
* LinkControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* 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
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use Tests\TestCase;
/**
* Class LinkControllerTest
*/
class LinkControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::__construct
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::delete
*/
public function testDelete()
{
2018-02-28 08:50:00 -06:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
2017-12-23 10:42:07 -06:00
$this->be($this->user());
$response = $this->get(route('transactions.link.delete', [1]));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::destroy
*/
public function testDestroy()
{
2018-02-28 08:50:00 -06:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
2018-02-28 08:50:00 -06:00
2017-12-23 10:42:07 -06:00
$repository->shouldReceive('destroyLink');
2018-02-28 08:50:00 -06:00
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
2017-12-23 10:42:07 -06:00
$this->be($this->user());
$this->session(['journal_links.delete.uri' => 'http://localhost/']);
$response = $this->post(route('transactions.link.destroy', [1]));
$response->assertStatus(302);
$response->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
*/
2017-12-29 02:05:35 -06:00
public function testStore()
2017-12-23 10:42:07 -06:00
{
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$data = [
'link_other' => 8,
'link_type' => '1_inward',
];
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
2017-12-29 02:05:35 -06:00
$repository->shouldReceive('findLink')->andReturn(false);
$repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink);
2017-12-23 10:42:07 -06:00
$this->be($this->user());
$response = $this->post(route('transactions.link.store', [1]), $data);
$response->assertStatus(302);
2017-12-29 02:05:35 -06:00
$response->assertSessionHas('success');
2017-12-23 10:42:07 -06:00
$response->assertRedirect(route('transactions.show', [1]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
*/
2017-12-29 02:05:35 -06:00
public function testStoreAlreadyLinked()
2017-12-23 10:42:07 -06:00
{
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$data = [
'link_other' => 8,
'link_type' => '1_inward',
];
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
2017-12-29 02:05:35 -06:00
$repository->shouldReceive('findLink')->andReturn(true);
2017-12-23 10:42:07 -06:00
$this->be($this->user());
$response = $this->post(route('transactions.link.store', [1]), $data);
$response->assertStatus(302);
2017-12-29 02:05:35 -06:00
$response->assertSessionHas('error');
2017-12-23 10:42:07 -06:00
$response->assertRedirect(route('transactions.show', [1]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
*/
public function testStoreInvalid()
{
2018-02-28 08:50:00 -06:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$data = [
2017-12-23 10:42:07 -06:00
'link_other' => 0,
'link_type' => '1_inward',
];
2018-02-28 08:50:00 -06:00
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
2017-12-23 10:42:07 -06:00
$this->be($this->user());
$response = $this->post(route('transactions.link.store', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
$response->assertRedirect(route('transactions.show', [1]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::switchLink
*/
public function testSwitchLink()
{
2018-02-28 08:50:00 -06:00
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
2018-02-28 08:50:00 -06:00
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
2017-12-23 10:42:07 -06:00
$repository->shouldReceive('switchLink')->andReturn(false);
$this->be($this->user());
$response = $this->get(route('transactions.link.switch', [1]));
$response->assertStatus(302);
}
}