firefly-iii/tests/Feature/Controllers/Popup/ReportControllerTest.php

370 lines
15 KiB
PHP
Raw Normal View History

2017-02-12 11:40:39 -06:00
<?php
/**
* ReportControllerTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 01:40:00 -05:00
* 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
2017-12-17 07:42:21 -06:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-02-12 11:40:39 -06:00
*/
2017-03-29 14:20:54 -05:00
declare(strict_types=1);
2017-02-12 11:40:39 -06:00
namespace Tests\Feature\Controllers\Popup;
use Carbon\Carbon;
2017-04-08 03:20:34 -05:00
use FireflyIII\Helpers\Report\PopupReportInterface;
2017-03-12 15:24:34 -05:00
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
2018-03-24 00:08:50 -05:00
use Log;
2017-02-12 11:40:39 -06:00
use Tests\TestCase;
/**
* Class ReportControllerTest
*
2017-08-12 03:27:45 -05:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-02-12 11:40:39 -06:00
*/
class ReportControllerTest extends TestCase
{
2018-03-24 00:08:50 -05:00
/**
*
*/
public function setUp()
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
2018-03-24 00:08:50 -05:00
}
2017-03-29 14:20:54 -05:00
/**
2017-04-08 03:20:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::__construct
2017-03-29 14:20:54 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Could not parse end date
*/
2018-05-11 12:58:10 -05:00
public function testBadEndDate(): void
2017-03-29 14:20:54 -05:00
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'endDate' => 'bla-bla',
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Could not parse start date
*/
2018-05-11 12:58:10 -05:00
public function testBadStartDate(): void
2017-03-29 14:20:54 -05:00
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => 'bla-bla',
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
2018-07-20 09:28:54 -05:00
$response->assertStatus(200);
2017-03-29 14:20:54 -05:00
}
2017-02-12 11:40:39 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
2017-03-12 15:24:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
2017-02-12 11:40:39 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testBalanceAmountDefaultNoBudget(): void
2017-03-29 14:20:54 -05:00
{
2018-02-28 08:50:00 -06:00
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$account = factory(Account::class)->make();
2017-03-29 14:20:54 -05:00
$popupHelper->shouldReceive('balanceForNoBudget')->andReturn(new Collection);
2018-03-28 12:38:20 -05:00
$budgetRepos->shouldReceive('findNull')->andReturn(new Budget)->once()->withArgs([0]);
$accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]);
$popupHelper->shouldReceive('balanceForBudget')->once()->andReturn(new Collection);
2018-02-28 08:50:00 -06:00
2017-03-29 14:20:54 -05:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'balance-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 0,
'role' => 1, // ROLE_DEFAULTROLE
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
*/
2018-05-11 12:58:10 -05:00
public function testBalanceAmountDefaultRole(): void
2017-03-29 14:20:54 -05:00
{
2018-02-28 08:50:00 -06:00
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$budget = factory(Budget::class)->make();
$account = factory(Account::class)->make();
2017-03-29 14:20:54 -05:00
2018-03-28 12:38:20 -05:00
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
$accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]);
2017-04-08 03:20:34 -05:00
$popupHelper->shouldReceive('balanceForBudget')->once()->andReturn(new Collection);
2017-03-29 14:20:54 -05:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'balance-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
'role' => 1, // ROLE_DEFAULTROLE
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(200);
}
2017-04-08 03:20:34 -05:00
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
* @expectedExceptionMessage Firefly cannot handle this type of info-button
*/
2018-05-11 12:58:10 -05:00
public function testBalanceAmountTagRole(): void
2017-04-08 03:20:34 -05:00
{
2018-02-28 08:50:00 -06:00
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budget = factory(Budget::class)->make();
$account = factory(Account::class)->make();
2017-04-08 03:20:34 -05:00
2018-03-28 12:38:20 -05:00
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
$accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]);
2017-04-08 03:20:34 -05:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'balance-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
'role' => 2, // ROLE_TAGROLE
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
2018-07-20 09:28:54 -05:00
$response->assertStatus(200);
2017-04-08 03:20:34 -05:00
}
2017-02-12 11:40:39 -06:00
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
2017-03-12 15:24:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::budgetSpentAmount()
2017-02-12 11:40:39 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testBudgetSpentAmount(): void
2017-02-12 11:40:39 -06:00
{
2018-02-28 08:50:00 -06:00
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$budget = factory(Budget::class)->make();
2017-03-12 15:24:34 -05:00
2018-03-28 12:38:20 -05:00
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
2017-04-08 03:20:34 -05:00
$popupHelper->shouldReceive('byBudget')->andReturn(new Collection);
2017-02-12 11:40:39 -06:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'budget-spent-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
2017-03-05 04:19:06 -06:00
$response = $this->get($uri);
2017-02-12 11:40:39 -06:00
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
2017-03-12 15:24:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::categoryEntry()
2017-02-12 11:40:39 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testCategoryEntry(): void
2017-02-12 11:40:39 -06:00
{
2018-02-28 08:50:00 -06:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
2017-04-08 03:20:34 -05:00
$popupHelper = $this->mock(PopupReportInterface::class);
2017-03-12 15:24:34 -05:00
$category = factory(Category::class)->make();
2018-03-28 12:38:20 -05:00
$categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]);
2017-04-08 03:20:34 -05:00
$popupHelper->shouldReceive('byCategory')->andReturn(new Collection);
2017-02-12 11:40:39 -06:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'category-entry',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
2017-03-05 04:19:06 -06:00
$response = $this->get($uri);
2017-02-12 11:40:39 -06:00
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
2017-03-12 15:24:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::expenseEntry()
2017-02-12 11:40:39 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testExpenseEntry(): void
2017-02-12 11:40:39 -06:00
{
2018-02-28 08:50:00 -06:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = factory(Account::class)->make();
2017-03-12 15:24:34 -05:00
2018-03-28 12:38:20 -05:00
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
2017-04-08 03:20:34 -05:00
$popupHelper->shouldReceive('byExpenses')->andReturn(new Collection);
2017-02-12 11:40:39 -06:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'expense-entry',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
2017-03-05 04:19:06 -06:00
$response = $this->get($uri);
2017-02-12 11:40:39 -06:00
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
2017-03-12 15:24:34 -05:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::incomeEntry()
2017-02-12 11:40:39 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testIncomeEntry(): void
2017-02-12 11:40:39 -06:00
{
2018-02-28 08:50:00 -06:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = factory(Account::class)->make();
2017-03-12 15:24:34 -05:00
2018-03-28 12:38:20 -05:00
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
2017-04-08 03:20:34 -05:00
$popupHelper->shouldReceive('byIncome')->andReturn(new Collection);
2017-02-12 11:40:39 -06:00
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'income-entry',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
2017-03-05 04:19:06 -06:00
$response = $this->get($uri);
2017-02-12 11:40:39 -06:00
$response->assertStatus(200);
}
2017-03-29 14:20:54 -05:00
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Firefly cannot handle
*/
2018-05-11 12:58:10 -05:00
public function testWrongLocation(): void
2017-03-29 14:20:54 -05:00
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
2018-07-20 09:28:54 -05:00
$response->assertStatus(200);
2017-03-29 14:20:54 -05:00
}
2017-02-16 15:33:32 -06:00
}