firefly-iii/tests/controllers/ReportControllerTest.php

173 lines
5.9 KiB
PHP
Raw Normal View History

2015-05-03 04:02:34 -05:00
<?php
2015-05-15 16:02:42 -05:00
use FireflyIII\Models\AccountMeta;
2015-05-03 04:02:34 -05:00
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ReportControllerTest
*/
class ReportControllerTest extends TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
parent::setUp();
}
/**
* This method is called before the first test of this test class is run.
*
* @since Method available since Release 3.4.0
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
parent::tearDown();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\ReportController::index
*/
2015-05-03 04:02:34 -05:00
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock stuff
2015-05-15 16:02:42 -05:00
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// make shared:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'accountRole',
'data' => 'sharedAsset'
]
);
2015-05-03 04:02:34 -05:00
$helper->shouldReceive('listOfMonths')->andReturn([]);
$helper->shouldReceive('listOfYears')->andReturn([]);
2015-05-15 16:02:42 -05:00
$repository->shouldReceive('getAccounts')->andReturn(new Collection([$account]));
2015-05-03 04:02:34 -05:00
$this->call('GET', '/reports');
$this->assertResponseOk();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\ReportController::month
*/
2015-05-15 16:02:42 -05:00
public function testMonth()
{
2015-05-18 10:57:44 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
2015-05-17 04:28:58 -05:00
FactoryMuffin::create('FireflyIII\Models\Account');
2015-05-16 09:04:51 -05:00
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
2015-05-15 16:02:42 -05:00
$budget1->queryAmount = 12;
2015-05-16 09:04:51 -05:00
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
2015-05-15 16:02:42 -05:00
$budget2->queryAmount = 0;
$this->be($user);
// mock!
2015-05-16 09:04:51 -05:00
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
2015-05-15 16:02:42 -05:00
// fake!
2015-05-16 09:04:51 -05:00
$helper->shouldReceive('getAccountReport')->andReturn(new Collection);
$helper->shouldReceive('getIncomeReport')->andReturn(new Collection);
$helper->shouldReceive('getExpenseReport')->andReturn(new Collection);
$helper->shouldReceive('getBudgetReport')->andReturn(new Collection);
$helper->shouldReceive('getCategoryReport')->andReturn(new Collection);
$helper->shouldReceive('getBalanceReport')->andReturn(new Collection);
2015-05-18 10:57:44 -05:00
$helper->shouldReceive('getBillReport')->andReturn(new Collection);
2015-05-16 09:04:51 -05:00
2015-05-15 16:02:42 -05:00
$this->call('GET', '/reports/2015/1');
$this->assertResponseOk();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\ReportController::month
*/
2015-05-15 16:02:42 -05:00
public function testMonthShared()
{
2015-05-18 10:57:44 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
2015-05-17 04:28:58 -05:00
FactoryMuffin::create('FireflyIII\Models\Account');
2015-05-16 09:04:51 -05:00
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
2015-05-15 16:02:42 -05:00
$budget1->queryAmount = 12;
2015-05-16 09:04:51 -05:00
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
2015-05-15 16:02:42 -05:00
$budget2->queryAmount = 0;
$this->be($user);
// mock!
2015-05-16 09:04:51 -05:00
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
2015-05-15 16:02:42 -05:00
// fake!
2015-05-16 09:04:51 -05:00
$helper->shouldReceive('getAccountReport')->andReturn(new Collection);
$helper->shouldReceive('getIncomeReport')->andReturn(new Collection);
$helper->shouldReceive('getExpenseReport')->andReturn(new Collection);
$helper->shouldReceive('getBudgetReport')->andReturn(new Collection);
$helper->shouldReceive('getCategoryReport')->andReturn(new Collection);
$helper->shouldReceive('getBalanceReport')->andReturn(new Collection);
2015-05-18 10:57:44 -05:00
$helper->shouldReceive('getBillReport')->andReturn(new Collection);
2015-05-15 16:02:42 -05:00
$this->call('GET', '/reports/2015/1/shared');
$this->assertResponseOk();
}
2015-05-23 12:41:54 -05:00
/**
* @covers FireflyIII\Http\Controllers\ReportController::year
*/
2015-05-03 04:02:34 -05:00
public function testYear()
{
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
2015-05-15 16:02:42 -05:00
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// make shared:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'accountRole',
'data' => 'sharedAsset'
]
);
2015-05-17 04:28:58 -05:00
new Collection([$journal]);
2015-05-03 04:02:34 -05:00
$this->be($user);
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
2015-05-15 16:02:42 -05:00
2015-05-16 09:04:51 -05:00
$helper->shouldReceive('getAccountReport')->once()->withAnyArgs()->andReturn([]);
$helper->shouldReceive('getIncomeReport')->once()->withAnyArgs()->andReturn([]);
$helper->shouldReceive('getExpenseReport')->once()->withAnyArgs()->andReturn([]);
2015-05-03 04:02:34 -05:00
// mock stuff!
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
2015-05-16 01:09:15 -05:00
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->once()->andReturn('X');
2015-05-03 04:02:34 -05:00
Amount::shouldReceive('format')->andReturn('X');
2015-05-15 16:02:42 -05:00
$this->call('GET', '/reports/2015/shared');
2015-05-03 04:02:34 -05:00
$this->assertResponseOk();
}
}