firefly-iii/tests/controllers/HomeControllerTest.php

122 lines
3.7 KiB
PHP
Raw Normal View History

2015-03-13 02:44:07 -05:00
<?php
2015-04-07 13:54:43 -05:00
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
2015-03-13 02:44:07 -05:00
/**
2015-04-07 13:54:43 -05:00
* Class HomeControllerTest
2015-03-13 02:44:07 -05:00
*/
class HomeControllerTest 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();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
parent::tearDown();
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
*/
2015-04-07 11:52:15 -05:00
public function testDateRange()
2015-03-13 02:44:07 -05:00
{
2015-04-07 11:52:15 -05:00
$start = '2015-03-01';
2015-03-28 00:19:09 -05:00
$end = '2015-03-31';
2015-04-07 13:54:43 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
2015-04-07 11:52:15 -05:00
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
2015-03-28 00:19:09 -05:00
$this->assertResponseOk();
$this->assertSessionHas('start');
$this->assertSessionHas('end');
2015-03-13 02:44:07 -05:00
}
2015-04-07 13:54:43 -05:00
2015-03-13 02:44:07 -05:00
/**
2015-03-28 00:19:09 -05:00
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
2015-03-13 02:44:07 -05:00
*/
2015-04-07 11:52:15 -05:00
public function testDateRangeWarning()
2015-03-13 02:44:07 -05:00
{
2015-04-07 11:52:15 -05:00
$start = '2014-03-01';
2015-03-28 00:19:09 -05:00
$end = '2015-03-31';
2015-04-07 13:54:43 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
2015-04-07 11:52:15 -05:00
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
2015-03-28 00:19:09 -05:00
$this->assertResponseOk();
$this->assertSessionHas('start');
$this->assertSessionHas('end');
2015-04-07 11:52:15 -05:00
$this->assertSessionHas('warning');
2015-03-13 02:44:07 -05:00
}
/**
2015-04-07 13:54:43 -05:00
*
2015-03-13 02:44:07 -05:00
*/
2015-04-07 13:54:43 -05:00
public function testFlush()
2015-03-13 02:44:07 -05:00
{
2015-04-07 13:54:43 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
2015-03-31 10:49:47 -05:00
2015-04-07 13:54:43 -05:00
$this->call('GET', '/flush');
$this->assertResponseStatus(302);
2015-03-13 02:44:07 -05:00
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::index
*/
2015-04-07 13:54:43 -05:00
public function testIndex()
2015-03-13 02:44:07 -05:00
{
2015-04-07 13:54:43 -05:00
$user = FactoryMuffin::create('FireflyIII\User');
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journals = new Collection([$journal]);
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$accounts = new Collection([$account]);
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$this->be($user);
// mock ALL THE THINGS!
$repository->shouldReceive('countAccounts')->once()->andReturn(3);
Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($preference);
$repository->shouldReceive('getFrontpageAccounts')->once()->with($preference)->andReturn($accounts);
$repository->shouldReceive('getSavingsAccounts')->once()->andReturn($accounts);
$repository->shouldReceive('getPiggyBankAccounts')->once()->andReturn($accounts);
2015-04-07 13:54:43 -05:00
$repository->shouldReceive('sumOfEverything')->once()->andReturn(1);
$repository->shouldReceive('getFrontpageTransactions')->once()->andReturn($journals);
// language preference:
2015-05-18 10:57:44 -05:00
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
2015-04-07 13:54:43 -05:00
Amount::shouldReceive('getCurrencyCode')->andReturn('EUR');
Amount::shouldReceive('format')->andReturn('xxx');
Amount::shouldReceive('formatJournal')->with($journal)->andReturn('xxx');
$this->call('GET', '/');
$this->assertResponseOk();
2015-03-13 02:44:07 -05:00
}
}