Expanded test coverage.

This commit is contained in:
James Cole
2017-03-24 15:01:53 +01:00
parent 222b3008d5
commit fe66d089ad
20 changed files with 357 additions and 149 deletions

View File

@@ -7,10 +7,11 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -23,9 +24,11 @@ use Tests\TestCase;
class TransactionControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndex()
{
@@ -78,7 +81,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['transfer','all']));
$response = $this->get(route('transactions.index', ['transfer', 'all']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -86,6 +89,7 @@ class TransactionControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndexByDate()
{
@@ -115,17 +119,84 @@ class TransactionControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndexDeposit()
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['deposit']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
*/
public function testIndexWithdrawal()
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['withdrawal']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::reorder
*/
public function testReorder()
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$journal = factory(TransactionJournal::class)->make();
$journal->date = new Carbon('2016-01-01');
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->once()->andReturn($journal);
$repository->shouldReceive('setOrder')->once()->andReturn(true);
$data = [
'items' => [],
'date' => '2016-01-01',
'items' => [1],
];
$this->be($this->user());
$response = $this->post(route('transactions.reorder'), $data);