mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-16 18:25:00 -06:00
188 lines
5.9 KiB
PHP
188 lines
5.9 KiB
PHP
<?php
|
|
use Carbon\Carbon;
|
|
use FireflyIII\Models\Account;
|
|
use FireflyIII\Models\AccountType;
|
|
use FireflyIII\Models\Preference;
|
|
use FireflyIII\Models\TransactionCurrency;
|
|
use Illuminate\Support\Collection;
|
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 20:05:14.
|
|
*/
|
|
class AccountControllerTest extends TestCase
|
|
{
|
|
/** @var Account */
|
|
public $account;
|
|
|
|
/**
|
|
* 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->createAccount();
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
|
|
}
|
|
|
|
public function createAccount()
|
|
{
|
|
if (is_null($this->account)) {
|
|
$this->account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
Log::debug('Created a new account.');
|
|
//$this->account->accountType->type = 'Asset account';
|
|
//$this->account->accountType->save();
|
|
}
|
|
}
|
|
|
|
public function testCreate()
|
|
{
|
|
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
|
|
$pref->data = '1M';
|
|
$this->be($pref->user);
|
|
|
|
|
|
Preferences::shouldReceive('get', 'viewRange')->andReturn($pref);
|
|
|
|
// CURRENCY:
|
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
|
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
|
Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
|
|
|
|
$this->call('GET', '/accounts/create/asset');
|
|
$this->assertResponseOk();
|
|
|
|
|
|
$this->assertViewHas('subTitle', 'Create a new asset account');
|
|
$this->assertViewHas('subTitleIcon', 'fa-money');
|
|
$this->assertViewHas('what', 'asset');
|
|
|
|
}
|
|
|
|
public function testDelete()
|
|
{
|
|
|
|
$this->be($this->account->user);
|
|
$this->call('GET', '/accounts/delete/' . $this->account->id);
|
|
$this->assertResponseOk();
|
|
$this->assertViewHas('subTitle', 'Delete ' . strtolower(e($this->account->accountType->type)) . ' "' . e($this->account->name) . '"');
|
|
|
|
}
|
|
|
|
public function testDestroy()
|
|
{
|
|
// fake an account.
|
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
|
|
|
$this->be($account->user);
|
|
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
|
|
|
// post it!
|
|
$this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
|
|
$this->assertSessionHas('success');
|
|
$this->assertCount(0, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
|
}
|
|
|
|
public function testEdit()
|
|
{
|
|
// fake an account.
|
|
|
|
$this->be($this->account->user);
|
|
$this->assertCount(1, DB::table('accounts')->where('id', $this->account->id)->whereNull('deleted_at')->get());
|
|
|
|
// create a transaction journal that will act as opening balance:
|
|
$openingBalance = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
|
$repository->shouldReceive('openingBalanceTransaction')->andReturn($openingBalance);
|
|
|
|
// create a transaction that will be returned for the opening balance transaction:
|
|
$openingBalanceTransaction = FactoryMuffin::create('FireflyIII\Models\Transaction');
|
|
$repository->shouldReceive('getFirstTransaction')->andReturn($openingBalanceTransaction);
|
|
|
|
// CURRENCY:
|
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
|
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
|
Amount::shouldReceive('getAllCurrencies')->once()->andReturn([$currency]);
|
|
|
|
// get edit page:
|
|
$this->call('GET', '/accounts/edit/' . $this->account->id);
|
|
|
|
// assert stuff:
|
|
$this->assertResponseOk();
|
|
$this->assertSessionHas('preFilled');
|
|
$this->assertViewHas('subTitle', 'Edit ' . strtolower(e($this->account->accountType->type)) . ' "' . e($this->account->name) . '"');
|
|
|
|
|
|
}
|
|
|
|
public function testIndex()
|
|
{
|
|
// an account:
|
|
$this->be($this->account->user);
|
|
|
|
$collection = new Collection;
|
|
$collection->push($this->account);
|
|
|
|
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
|
$repository->shouldReceive('getAccounts')->andReturn($collection);
|
|
$repository->shouldReceive('countAccounts')->andReturn(1);
|
|
$repository->shouldReceive('getLastActivity')->andReturn(null);
|
|
|
|
Amount::shouldReceive('format')->andReturn('');
|
|
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
|
|
|
|
|
|
// put stuff in session:
|
|
$this->session(['start' => new Carbon, 'end' => new Carbon]);
|
|
|
|
// get edit page:
|
|
$this->call('GET', '/accounts/asset');
|
|
$this->assertResponseOk();
|
|
$this->assertViewHas('what', 'asset');
|
|
|
|
}
|
|
|
|
public function testShow()
|
|
{
|
|
// an account:
|
|
$this->be($this->account->user);
|
|
|
|
Amount::shouldReceive('getCurrencyCode')->once()->andReturn('A');
|
|
|
|
// get edit page:
|
|
$this->call('GET', '/accounts/show/' . $this->account->id);
|
|
$this->assertResponseOk();
|
|
}
|
|
|
|
public function testStore()
|
|
{
|
|
$this->markTestIncomplete();
|
|
}
|
|
|
|
public function testUpdate()
|
|
{
|
|
$this->markTestIncomplete();
|
|
}
|
|
|
|
}
|