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,14 +7,12 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers\Admin;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Facades\Preferences;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -60,14 +58,43 @@ class UserControllerTest extends TestCase
public function testShow()
{
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getUserData')->andReturn([]);
$repository->shouldReceive('getUserData')->andReturn(
[
'export_jobs_success' => 0,
'import_jobs_success' => 0,
'attachments_size' => 0,
]
);
$this->be($this->user());
$response = $this->get(route('admin.users.edit', [1]));
$response = $this->get(route('admin.users.show', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Admin\UserController::update
*/
public function testUpdate()
{
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('changePassword')->once();
$repository->shouldReceive('changeStatus')->once();
$data = [
'id' => 1,
'email' => 'test@example.com',
'password' => 'james',
'password_confirmation' => 'james',
'blocked_code' => 'blocked',
'blocked' => 1,
];
$this->be($this->user());
$response = $this->post(route('admin.users.update', ['1']), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
}

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers;
@@ -36,6 +36,7 @@ class TagControllerTest extends TestCase
public function testCreate()
{
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -51,6 +52,7 @@ class TagControllerTest extends TestCase
public function testDelete()
{
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@@ -83,8 +85,11 @@ class TagControllerTest extends TestCase
public function testEdit()
{
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('tagAllowAdvance')->once()->andReturn(false);
$repository->shouldReceive('tagAllowBalancing')->once()->andReturn(false);
$this->be($this->user());
$response = $this->get(route('tags.edit', [1]));
@@ -124,22 +129,20 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon);
$repository->shouldReceive('earnedInPeriod')->andReturn('1');
$repository->shouldReceive('find')->andReturn(new Tag);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setTag')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setTag')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
@@ -148,6 +151,67 @@ class TagControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TagController::show
*/
public function testShowDate()
{
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setTag')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
$response = $this->get(route('tags.show', [1, '2016-01-01']));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TagController::show
*/
public function testShowAll()
{
// mock stuff
$repository = $this->mock(TagRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setTag')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
$response = $this->get(route('tags.show', [1, 'all']));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TagController::store
*/

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);