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

417 lines
16 KiB
PHP
Raw Normal View History

2017-02-12 18:40:39 +01:00
<?php
/**
* ReportControllerTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2017-02-12 18:40:39 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 08:40:00 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-02-12 18:40:39 +01:00
*/
2017-03-29 21:20:54 +02:00
declare(strict_types=1);
2017-02-12 18:40:39 +01:00
namespace Tests\Feature\Controllers\Popup;
2019-06-29 19:47:31 +02:00
use Amount;
2017-02-12 18:40:39 +01:00
use Carbon\Carbon;
2017-04-08 10:20:34 +02:00
use FireflyIII\Helpers\Report\PopupReportInterface;
2017-03-12 21:24:34 +01:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
2018-03-24 06:08:50 +01:00
use Log;
2017-02-12 18:40:39 +01:00
use Tests\TestCase;
/**
* Class ReportControllerTest
*
2017-08-12 10:27:45 +02:00
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2017-02-12 18:40:39 +01:00
*/
class ReportControllerTest extends TestCase
{
2018-03-24 06:08:50 +01:00
/**
*
*/
2018-09-02 20:27:26 +02:00
public function setUp(): void
2018-03-24 06:08:50 +01:00
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-03-24 06:08:50 +01:00
}
2017-03-29 21:20:54 +02:00
/**
2019-06-29 19:47:31 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-03-29 21:20:54 +02:00
*/
2018-05-11 19:58:10 +02:00
public function testBadEndDate(): void
2017-03-29 21:20:54 +02:00
{
2019-06-29 19:47:31 +02:00
$this->mock(PopupReportInterface::class);
$this->mockDefaultSession();
2017-03-29 21:20:54 +02: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);
2018-07-27 04:46:21 +02:00
$response->assertStatus(200);
2019-06-29 19:47:31 +02:00
$response->assertSee('Firefly III cannot handle');
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
2017-03-29 21:20:54 +02:00
}
/**
2019-06-29 19:47:31 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-03-29 21:20:54 +02:00
*/
2018-05-11 19:58:10 +02:00
public function testBadStartDate(): void
2017-03-29 21:20:54 +02:00
{
2019-06-29 19:47:31 +02:00
$this->mock(PopupReportInterface::class);
2018-12-12 20:30:25 +01:00
2017-03-29 21:20:54 +02:00
$this->be($this->user());
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2017-03-29 21:20:54 +02:00
$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 16:28:54 +02:00
$response->assertStatus(200);
2019-06-29 19:47:31 +02:00
$response->assertSee('Firefly III cannot handle');
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
2017-03-29 21:20:54 +02:00
}
2017-02-12 18:40:39 +01:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testBudgetSpentAmount(): void
2017-02-12 18:40:39 +01:00
{
2019-07-26 17:48:24 +02:00
$this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
2018-02-28 15:50:00 +01:00
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
2019-07-25 14:19:49 +02:00
$budget = $this->getRandomBudget();
2017-03-12 21:24:34 +01:00
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2018-03-28 19:38:20 +02:00
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
2019-06-29 19:47:31 +02:00
$popupHelper->shouldReceive('byBudget')->andReturn([]);
2017-02-12 18:40:39 +01:00
2019-08-17 12:08:09 +02:00
//Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
2019-07-26 17:48:24 +02: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,
2019-08-17 12:08:09 +02:00
'currencyId' => 1,
2019-07-26 17:48:24 +02:00
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(200);
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
*/
public function testBudgetSpentAmountNoBudget(): void
{
$this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
2019-08-17 12:08:09 +02:00
//Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
2019-07-26 17:48:24 +02:00
$this->mockDefaultSession();
$budgetRepos->shouldReceive('findNull')->andReturnNull()->once()->withArgs([1]);
$popupHelper->shouldReceive('byBudget')->andReturn([]);
2017-02-12 18:40:39 +01: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 11:19:06 +01:00
$response = $this->get($uri);
2017-02-12 18:40:39 +01:00
$response->assertStatus(200);
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
2017-02-12 18:40:39 +01:00
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testCategoryEntry(): void
2017-02-12 18:40:39 +01:00
{
2019-06-29 19:47:31 +02:00
$this->mock(BudgetRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
2018-02-28 15:50:00 +01:00
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
2017-04-08 10:20:34 +02:00
$popupHelper = $this->mock(PopupReportInterface::class);
2019-07-25 14:19:49 +02:00
$category = $this->getRandomCategory();
2017-03-12 21:24:34 +01:00
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2018-03-28 19:38:20 +02:00
$categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]);
2019-06-29 19:47:31 +02:00
$popupHelper->shouldReceive('byCategory')->andReturn([]);
2019-08-17 12:08:09 +02:00
//Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
2017-02-12 18:40:39 +01: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 11:19:06 +01:00
$response = $this->get($uri);
2017-02-12 18:40:39 +01:00
$response->assertStatus(200);
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
*/
public function testCategoryEntryUnknown(): void
{
$this->mock(BudgetRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$this->mockDefaultSession();
$categoryRepos->shouldReceive('findNull')->andReturn(null)->once()->withArgs([1]);
$popupHelper->shouldReceive('byCategory')->andReturn([]);
$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);
$response = $this->get($uri);
$response->assertStatus(200);
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
$response->assertSee('This is an unknown category. Apologies.');
2017-02-12 18:40:39 +01:00
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testExpenseEntry(): void
2017-02-12 18:40:39 +01:00
{
2018-02-28 15:50:00 +01: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);
2019-07-25 14:19:49 +02:00
$account = $this->getRandomAsset();
2017-03-12 21:24:34 +01:00
2019-08-17 12:08:09 +02:00
//Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
2019-07-26 17:48:24 +02:00
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2018-03-28 19:38:20 +02:00
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
2019-06-29 19:47:31 +02:00
$popupHelper->shouldReceive('byExpenses')->andReturn([]);
2017-02-12 18:40:39 +01: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 11:19:06 +01:00
$response = $this->get($uri);
2017-02-12 18:40:39 +01:00
$response->assertStatus(200);
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
*/
public function testExpenseEntryUnknown(): void
{
$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);
$this->mockDefaultSession();
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
$popupHelper->shouldReceive('byExpenses')->andReturn([]);
$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);
$response = $this->get($uri);
$response->assertStatus(200);
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
$response->assertSee('This is an unknown account. Apologies.');
2017-02-12 18:40:39 +01:00
}
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-02-12 18:40:39 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testIncomeEntry(): void
2017-02-12 18:40:39 +01:00
{
2018-02-28 15:50:00 +01: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);
2019-07-25 14:19:49 +02:00
$account = $this->getRandomAsset();
2017-03-12 21:24:34 +01:00
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2018-03-28 19:38:20 +02:00
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
2019-06-29 19:47:31 +02:00
$popupHelper->shouldReceive('byIncome')->andReturn([]);
2019-08-17 12:08:09 +02:00
//Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once();
2019-07-26 17:48:24 +02: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);
$response = $this->get($uri);
$response->assertStatus(200);
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
*/
public function testIncomeEntryUnknown(): void
{
$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);
$this->mockDefaultSession();
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
$popupHelper->shouldReceive('byIncome')->andReturn([]);
2017-02-12 18:40:39 +01: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 11:19:06 +01:00
$response = $this->get($uri);
2017-02-12 18:40:39 +01:00
$response->assertStatus(200);
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
2017-02-12 18:40:39 +01:00
}
2017-03-29 21:20:54 +02:00
/**
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Http\Controllers\Popup\ReportController
2017-03-29 21:20:54 +02:00
* @expectedExceptionMessage Firefly cannot handle
*/
2018-05-11 19:58:10 +02:00
public function testWrongLocation(): void
2017-03-29 21:20:54 +02:00
{
2018-12-12 20:30:25 +01:00
$popupReport = $this->mock(PopupReportInterface::class);
2019-06-29 19:47:31 +02:00
$this->mockDefaultSession();
2017-03-29 21:20:54 +02: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 16:28:54 +02:00
$response->assertStatus(200);
2019-07-26 17:48:24 +02:00
$response->assertDontSee('Firefly III could not render the view. Please see the log files.');
2017-03-29 21:20:54 +02:00
}
2017-02-16 22:33:32 +01:00
}