mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fixed tests.
This commit is contained in:
@@ -22,17 +22,13 @@ class ReportController extends Controller
|
|||||||
|
|
||||||
/** @var ReportHelperInterface */
|
/** @var ReportHelperInterface */
|
||||||
protected $helper;
|
protected $helper;
|
||||||
/** @var ReportQueryInterface */
|
|
||||||
protected $query;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReportHelperInterface $helper
|
* @param ReportHelperInterface $helper
|
||||||
* @param ReportQueryInterface $query
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ReportHelperInterface $helper, ReportQueryInterface $query)
|
public function __construct(ReportHelperInterface $helper)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->query = $query;
|
|
||||||
$this->helper = $helper;
|
$this->helper = $helper;
|
||||||
|
|
||||||
View::share('title', trans('firefly.reports'));
|
View::share('title', trans('firefly.reports'));
|
||||||
|
@@ -39,7 +39,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
FactoryMuffin::loadFactories(__DIR__ . '/factories');
|
FactoryMuffin::loadFactories(__DIR__ . '/factories');
|
||||||
|
|
||||||
if (!file_exists($copy)) {
|
if (!file_exists($copy)) {
|
||||||
Log::debug('Created new database.');
|
|
||||||
touch($original);
|
touch($original);
|
||||||
Artisan::call('migrate');
|
Artisan::call('migrate');
|
||||||
|
|
||||||
@@ -49,12 +48,10 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
$currency->code = 'EUR';
|
$currency->code = 'EUR';
|
||||||
$currency->save();
|
$currency->save();
|
||||||
Log::debug('Created new EUR currency.');
|
|
||||||
copy($original, $copy);
|
copy($original, $copy);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (file_exists($copy)) {
|
if (file_exists($copy)) {
|
||||||
Log::debug('Copied copy back over original.');
|
|
||||||
copy($copy, $original);
|
copy($copy, $original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,78 +66,27 @@ class ReportControllerTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testModalBalancedTransfers()
|
|
||||||
{
|
|
||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
||||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
||||||
$journals = new Collection([$journal]);
|
|
||||||
$this->be($account->user);
|
|
||||||
|
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
|
||||||
$query->shouldReceive('balancedTransactionsList')->withAnyArgs()->andReturn($journals);
|
|
||||||
|
|
||||||
|
|
||||||
$this->call('GET', '/reports/modal/' . $account->id . '/2015/1/balanced-transfers');
|
|
||||||
$this->assertResponseOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testModalLeftUnbalanced()
|
|
||||||
{
|
|
||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
||||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
||||||
$secondJournal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
||||||
$group = FactoryMuffin::create('FireflyIII\Models\TransactionGroup');
|
|
||||||
$group->transactionjournals()->save($secondJournal);
|
|
||||||
$journals = new Collection([$journal, $secondJournal]);
|
|
||||||
$this->be($account->user);
|
|
||||||
|
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
|
||||||
$query->shouldReceive('getTransactionsWithoutBudget')->withAnyArgs()->andReturn($journals);
|
|
||||||
|
|
||||||
$this->call('GET', '/reports/modal/' . $account->id . '/2015/1/left-unbalanced');
|
|
||||||
$this->assertResponseOk();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testModalNoBudget()
|
|
||||||
{
|
|
||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
||||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
||||||
$journals = new Collection([$journal]);
|
|
||||||
$this->be($account->user);
|
|
||||||
|
|
||||||
|
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
|
||||||
$query->shouldReceive('getTransactionsWithoutBudget')->withAnyArgs()->andReturn($journals);
|
|
||||||
|
|
||||||
$this->call('GET', '/reports/modal/' . $account->id . '/2015/1/no-budget');
|
|
||||||
$this->assertResponseOk();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testMonth()
|
public function testMonth()
|
||||||
{
|
{
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
$budget1->queryAmount = 12;
|
$budget1->queryAmount = 12;
|
||||||
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
$budget2->queryAmount = 0;
|
$budget2->queryAmount = 0;
|
||||||
$this->be($user);
|
$this->be($user);
|
||||||
|
|
||||||
// mock!
|
// mock!
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
|
||||||
|
|
||||||
// fake!
|
// fake!
|
||||||
$query->shouldReceive('incomeInPeriod')->andReturn([]);
|
$helper->shouldReceive('getAccountReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByExpenseAccount')->andReturn(new Collection);
|
$helper->shouldReceive('getIncomeReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('getAllAccounts')->andReturn(new Collection([$account]));
|
$helper->shouldReceive('getExpenseReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('getBudgetSummary')->andReturn(new Collection([$budget1, $budget2]));
|
$helper->shouldReceive('getBudgetReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByBudget')->andReturn(new Collection);
|
$helper->shouldReceive('getCategoryReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByCategory')->andReturn(new Collection);
|
$helper->shouldReceive('getBalanceReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('balancedTransactionsSum')->andReturn(0);
|
|
||||||
$query->shouldReceive('sharedExpenses')->andReturn(new Collection);
|
|
||||||
$query->shouldReceive('sharedExpensesByCategory')->andReturn(new Collection);
|
|
||||||
|
|
||||||
$this->call('GET', '/reports/2015/1');
|
$this->call('GET', '/reports/2015/1');
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
@@ -145,25 +94,24 @@ class ReportControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testMonthShared()
|
public function testMonthShared()
|
||||||
{
|
{
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
$budget1->queryAmount = 12;
|
$budget1->queryAmount = 12;
|
||||||
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
$budget2->queryAmount = 0;
|
$budget2->queryAmount = 0;
|
||||||
$this->be($user);
|
$this->be($user);
|
||||||
|
|
||||||
// mock!
|
// mock!
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
|
||||||
|
|
||||||
// fake!
|
// fake!
|
||||||
$query->shouldReceive('incomeInPeriod')->andReturn([]);
|
$helper->shouldReceive('getAccountReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByExpenseAccount')->andReturn(new Collection);
|
$helper->shouldReceive('getIncomeReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('getAllAccounts')->andReturn(new Collection([$account]));
|
$helper->shouldReceive('getExpenseReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('getBudgetSummary')->andReturn(new Collection([$budget1, $budget2]));
|
$helper->shouldReceive('getBudgetReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByBudget')->andReturn(new Collection);
|
$helper->shouldReceive('getCategoryReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('journalsByCategory')->andReturn(new Collection);
|
$helper->shouldReceive('getBalanceReport')->andReturn(new Collection);
|
||||||
$query->shouldReceive('balancedTransactionsSum')->andReturn(0);
|
|
||||||
|
|
||||||
$this->call('GET', '/reports/2015/1/shared');
|
$this->call('GET', '/reports/2015/1/shared');
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
@@ -189,16 +137,11 @@ class ReportControllerTest extends TestCase
|
|||||||
$this->be($user);
|
$this->be($user);
|
||||||
|
|
||||||
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
|
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
|
||||||
$query = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
|
|
||||||
|
|
||||||
|
|
||||||
$helper->shouldReceive('yearBalanceReport')->once()->withAnyArgs()->andReturn([]);
|
$helper->shouldReceive('getAccountReport')->once()->withAnyArgs()->andReturn([]);
|
||||||
$query->shouldReceive('getAllAccounts')->once()->withAnyArgs()->andReturn(new Collection([$account]));
|
$helper->shouldReceive('getIncomeReport')->once()->withAnyArgs()->andReturn([]);
|
||||||
|
$helper->shouldReceive('getExpenseReport')->once()->withAnyArgs()->andReturn([]);
|
||||||
$query->shouldReceive('incomeInPeriod')->once()->withAnyArgs()->andReturn(new Collection([$journal, $journal]));
|
|
||||||
$query->shouldReceive('expenseInPeriod')->once()->withAnyArgs()->andReturn(new Collection([$journal, $journal]));
|
|
||||||
$query->shouldReceive('journalsByRevenueAccount')->once()->withAnyArgs()->andReturn($journals);
|
|
||||||
$query->shouldReceive('journalsByExpenseAccount')->once()->withAnyArgs()->andReturn($journals);
|
|
||||||
|
|
||||||
// mock stuff!
|
// mock stuff!
|
||||||
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
||||||
|
@@ -25,7 +25,8 @@ class ReportHelperTest extends TestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
FactoryMuffin::create('FireflyIII\User');
|
FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->object = new ReportHelper;
|
$query = new \FireflyIII\Helpers\Report\ReportQuery();
|
||||||
|
$this->object = new ReportHelper($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,72 +38,6 @@ class ReportHelperTest extends TestCase
|
|||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers FireflyIII\Helpers\Report\ReportHelper::getBudgetsForMonth
|
|
||||||
*/
|
|
||||||
public function testGetBudgetsForMonthWithShared()
|
|
||||||
{
|
|
||||||
$date = new Carbon('2015-01-01');
|
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
|
||||||
$budgets = [];
|
|
||||||
|
|
||||||
// three budget limits starting on the $date:
|
|
||||||
for ($i = 0; $i < 3; $i++) {
|
|
||||||
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
||||||
$budgetLimit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
|
|
||||||
$budgetLimit->startdate = $date;
|
|
||||||
$budget->user_id = $user->id;
|
|
||||||
$budget->save();
|
|
||||||
$budgetLimit->save();
|
|
||||||
$budgets[] = $budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->be($user);
|
|
||||||
|
|
||||||
$result = $this->object->getBudgetsForMonth($date, true);
|
|
||||||
|
|
||||||
// assert each budget is in the array:
|
|
||||||
foreach ($budgets as $budget) {
|
|
||||||
$id = $budget->id;
|
|
||||||
$this->assertEquals($budget->name, $result[$id]['name']);
|
|
||||||
}
|
|
||||||
$this->assertEquals(0, $result[0]['queryAmount']);
|
|
||||||
$this->assertEquals('No budget', $result[0]['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers FireflyIII\Helpers\Report\ReportHelper::getBudgetsForMonth
|
|
||||||
*/
|
|
||||||
public function testGetBudgetsForMonthWithoutShared()
|
|
||||||
{
|
|
||||||
$date = new Carbon('2015-01-01');
|
|
||||||
$user = FactoryMuffin::create('FireflyIII\User');
|
|
||||||
$budgets = [];
|
|
||||||
|
|
||||||
// three budget limits starting on the $date:
|
|
||||||
for ($i = 0; $i < 3; $i++) {
|
|
||||||
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
||||||
$budgetLimit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
|
|
||||||
$budgetLimit->startdate = $date;
|
|
||||||
$budget->user_id = $user->id;
|
|
||||||
$budget->save();
|
|
||||||
$budgetLimit->save();
|
|
||||||
$budgets[] = $budget;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->be($user);
|
|
||||||
|
|
||||||
$result = $this->object->getBudgetsForMonth($date, false);
|
|
||||||
|
|
||||||
// assert each budget is in the array:
|
|
||||||
foreach ($budgets as $budget) {
|
|
||||||
$id = $budget->id;
|
|
||||||
$this->assertEquals($budget->name, $result[$id]['name']);
|
|
||||||
}
|
|
||||||
$this->assertEquals(0, $result[0]['queryAmount']);
|
|
||||||
$this->assertEquals('No budget', $result[0]['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testListOfMonths()
|
public function testListOfMonths()
|
||||||
{
|
{
|
||||||
// start of year up until now
|
// start of year up until now
|
||||||
|
Reference in New Issue
Block a user