Expand some tests.

This commit is contained in:
James Cole 2017-03-11 22:28:51 +01:00
parent 4abc271805
commit 8f14c78ba1
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 102 additions and 5 deletions

View File

@ -61,15 +61,12 @@ class AccountController extends Controller
*/ */
public function all(Account $account) public function all(Account $account)
{ {
$cache = new CacheProperties(); $cache = new CacheProperties;
$cache->addProperty('chart.account.all'); $cache->addProperty('chart.account.all');
$cache->addProperty($account->id); $cache->addProperty($account->id);
if ($cache->has()) { if ($cache->has()) {
Log::debug('Return chart.account.all from cache.');
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
Log::debug('Regenerate chart.account.all from scratch.');
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);

View File

@ -12,6 +12,10 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Admin; 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; use Tests\TestCase;
class UserControllerTest extends TestCase class UserControllerTest extends TestCase
@ -21,6 +25,8 @@ class UserControllerTest extends TestCase
*/ */
public function testEdit() public function testEdit()
{ {
$repository = $this->mock(UserRepositoryInterface::class);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('admin.users.edit', [1])); $response = $this->get(route('admin.users.edit', [1]));
$response->assertStatus(200); $response->assertStatus(200);
@ -34,7 +40,11 @@ class UserControllerTest extends TestCase
*/ */
public function testIndex() public function testIndex()
{ {
$this->be($this->user()); $repository = $this->mock(UserRepositoryInterface::class);
$user = $this->user();
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
$this->be($user);
$response = $this->get(route('admin.users')); $response = $this->get(route('admin.users'));
$response->assertStatus(200); $response->assertStatus(200);
// has bread crumb // has bread crumb
@ -46,6 +56,9 @@ class UserControllerTest extends TestCase
*/ */
public function testShow() public function testShow()
{ {
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getUserData')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('admin.users.edit', [1])); $response = $this->get(route('admin.users.edit', [1]));
$response->assertStatus(200); $response->assertStatus(200);

View File

@ -12,6 +12,16 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Steam;
use Tests\TestCase; use Tests\TestCase;
class AccountControllerTest extends TestCase class AccountControllerTest extends TestCase
@ -25,6 +35,14 @@ class AccountControllerTest extends TestCase
*/ */
public function testExpenseAccounts(string $range) public function testExpenseAccounts(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->andReturn(new Collection);
$generator->shouldReceive('singleSet')->andReturn([]);
Steam::shouldReceive('balancesById')->twice()->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense')); $response = $this->get(route('chart.account.expense'));
@ -33,12 +51,26 @@ class AccountControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseBudget * @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseBudget
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::getBudgetNames
* @dataProvider dateRangeProvider * @dataProvider dateRangeProvider
* *
* @param string $range * @param string $range
*/ */
public function testExpenseBudget(string $range) public function testExpenseBudget(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131'])); $response = $this->get(route('chart.account.expense-budget', [1, '20120101', '20120131']));
@ -53,6 +85,18 @@ class AccountControllerTest extends TestCase
*/ */
public function testExpenseCategory(string $range) public function testExpenseCategory(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131'])); $response = $this->get(route('chart.account.expense-category', [1, '20120101', '20120131']));
@ -70,6 +114,14 @@ class AccountControllerTest extends TestCase
*/ */
public function testFrontpage(string $range) public function testFrontpage(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
Steam::shouldReceive('balanceInRange')->andReturn([]);
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.frontpage')); $response = $this->get(route('chart.account.frontpage'));
@ -84,6 +136,18 @@ class AccountControllerTest extends TestCase
*/ */
public function testIncomeCategory(string $range) public function testIncomeCategory(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('pieChart')->andReturn([]);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131'])); $response = $this->get(route('chart.account.income-category', [1, '20120101', '20120131']));
@ -98,6 +162,13 @@ class AccountControllerTest extends TestCase
*/ */
public function testPeriod(string $range) public function testPeriod(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.period', [1, '2012-01-01'])); $response = $this->get(route('chart.account.period', [1, '2012-01-01']));
@ -106,9 +177,13 @@ class AccountControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::report * @covers \FireflyIII\Http\Controllers\Chart\AccountController::report
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::accountBalanceChart
*/ */
public function testReport() public function testReport()
{ {
$generator = $this->mock(GeneratorInterface::class);
$generator->shouldReceive('multiSet')->andreturn([]);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.account.report', ['1', '20120101', '20120131'])); $response = $this->get(route('chart.account.report', ['1', '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);
@ -122,6 +197,13 @@ class AccountControllerTest extends TestCase
*/ */
public function testRevenueAccounts(string $range) public function testRevenueAccounts(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->andReturn(new Collection);
$generator->shouldReceive('singleSet')->andReturn([]);
Steam::shouldReceive('balancesById')->twice()->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.revenue')); $response = $this->get(route('chart.account.revenue'));
@ -136,6 +218,11 @@ class AccountControllerTest extends TestCase
*/ */
public function testSingle(string $range) public function testSingle(string $range)
{ {
$generator = $this->mock(GeneratorInterface::class);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.account.single', [1])); $response = $this->get(route('chart.account.single', [1]));