mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Expand test coverage.
This commit is contained in:
@@ -41,14 +41,19 @@ class AutoCompleteControllerTest extends TestCase
|
||||
*/
|
||||
public function testAllAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$collection = new Collection([$accountA]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])
|
||||
->andReturn(new Collection);
|
||||
->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.all-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,18 +77,39 @@ class AutoCompleteControllerTest extends TestCase
|
||||
public function testExpenseAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn(
|
||||
new Collection([$account])
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.expense-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$account->name]);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController::journalsWithId
|
||||
*/
|
||||
public function testJournalsWithId()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('id', '!=', 1)->first();
|
||||
$journal->journal_id = $journal->id;
|
||||
$collection = new Collection([$journal]);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$collector->shouldReceive('setLimit')->withArgs([400])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->withArgs([1])->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.journals-with-id', [1]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([['id' => $journal->id, 'name' => $journal->id . ': ' . $journal->description]]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,18 +118,20 @@ class AutoCompleteControllerTest extends TestCase
|
||||
public function testRevenueAccounts()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn(
|
||||
new Collection([$account])
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.revenue-accounts'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$account->name]);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
100
tests/Feature/Controllers/Json/BoxControllerTest.php
Normal file
100
tests/Feature/Controllers/Json/BoxControllerTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* BoxControllerTest.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\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class BoxControllerTest
|
||||
*/
|
||||
class BoxControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::available
|
||||
*/
|
||||
public function testAvailable()
|
||||
{
|
||||
$return = [
|
||||
0 => [
|
||||
'spent' => '-1200', // more than budgeted.
|
||||
],
|
||||
];
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('1000');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('collectBudgetInformation')->andReturn($return);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.available'));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::balance
|
||||
*/
|
||||
public function testBalance()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.balance'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::bills
|
||||
*/
|
||||
public function testBills()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.bills'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorth()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth()
|
||||
*/
|
||||
public function testNetWorthFuture()
|
||||
{
|
||||
$start = new Carbon;
|
||||
$start->addMonths(6)->startOfMonth();
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
$this->session(['start' => $start, 'end' => $end]);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
51
tests/Feature/Controllers/Json/FrontpageControllerTest.php
Normal file
51
tests/Feature/Controllers/Json/FrontpageControllerTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* FrontpageControllerTest.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\Json;
|
||||
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class FrontpageControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class FrontpageControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\FrontpageController::piggyBanks
|
||||
*/
|
||||
public function testPiggyBanks()
|
||||
{
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy]));
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.fp.piggy-banks'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
95
tests/Feature/Controllers/Json/IntroControllerTest.php
Normal file
95
tests/Feature/Controllers/Json/IntroControllerTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* IntroControllerTest.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\Json;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IntroControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class IntroControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroSteps()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['index']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroStepsAsset()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getIntroSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getBasicSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::getSpecificSteps
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::hasOutroStep
|
||||
*/
|
||||
public function testGetIntroStepsOutro()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.intro', ['reports_report', 'category']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::postEnable
|
||||
*/
|
||||
public function testPostEnable()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('json.intro.enable', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\IntroController::postFinished
|
||||
*/
|
||||
public function testPostFinished()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('json.intro.finished', ['accounts_create', 'asset']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user