Removed everything related to unit tests. Can restore later.

This commit is contained in:
James Cole
2015-07-02 08:51:53 +02:00
parent ec349b31c7
commit 58af3dc6ea
58 changed files with 0 additions and 12865 deletions

View File

@@ -1,353 +0,0 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Account;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class AccountControllerTest
*/
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()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
if (is_null($this->account)) {
$this->account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->account->user_id = $user->id;
$this->account->save();
}
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::create
*/
public function testCreate()
{
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
$pref->data = '1M';
$this->be($pref->user);
Preferences::shouldReceive('get')->withArgs(['viewRange', '1M'])->andReturn($pref);
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language);
// CURRENCY:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
$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');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::delete
*/
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) . '"');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::destroy
*/
public function testDestroy()
{
// fake an account.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
// mock:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('destroy')->andReturn(true);
// post it!
$this->call('POST', '/accounts/destroy/' . $account->id, ['_token' => 'replaceme']);
$this->assertSessionHas('success');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::edit
*/
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:
$opening = FactoryMuffin::create('FireflyIII\Models\Transaction');
$repository->shouldReceive('getFirstTransaction')->andReturn($opening);
// CURRENCY:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
// 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) . '"');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::index
*/
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')->andReturn('A');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
// 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');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::show
*/
public function testShow()
{
// an account:
$this->be($this->account->user);
// mock!
Amount::shouldReceive('getCurrencyCode')->andReturn('A');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
// get edit page:
$this->call('GET', '/accounts/show/' . $this->account->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::store
*/
public function testStore()
{
// an account:
$this->be($this->account->user);
$data = [
'name' => 'New test account ' . rand(1, 1000),
'what' => 'asset',
'virtualBalance' => 0,
'accountRole' => 'defaultAsset',
'openingBalance' => 20,
'openingBalanceDate' => date('Y-m-d'),
'openingBalanceCurrency' => 1,
'_token' => 'replaceme'
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\AccountFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake store routine:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('store')->andReturn($this->account);
$this->call('POST', '/accounts/store', $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::store
*/
public function testStoreAndRedirect()
{
// an account:
$this->be($this->account->user);
$data = [
'name' => 'New test account ' . rand(1, 1000),
'what' => 'asset',
'virtualBalance' => 0,
'accountRole' => 'defaultAsset',
'openingBalance' => 20,
'openingBalanceDate' => date('Y-m-d'),
'openingBalanceCurrency' => 1,
'_token' => 'replaceme',
'create_another' => 1,
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\AccountFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake store routine:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('store')->andReturn($this->account);
$this->call('POST', '/accounts/store', $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::update
*/
public function testUpdate()
{
// an account:
$this->be($this->account->user);
$data = [
'name' => 'Edited test account ' . rand(1, 1000),
'active' => 1,
'accountRole' => 'defaultAsset',
'virtualBalance' => 0,
'openingBalance' => 25,
'openingBalanceDate' => date('Y-m-d'),
'openingBalanceCurrency' => 1,
'_token' => 'replaceme'
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\AccountFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake update routine:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('update')->andReturn($this->account);
$this->call('POST', '/accounts/update/' . $this->account->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::update
*/
public function testUpdateAndRedirect()
{
// an account:
$this->be($this->account->user);
$data = [
'name' => 'Edited test account ' . rand(1, 1000),
'active' => 1,
'accountRole' => 'defaultAsset',
'virtualBalance' => 0,
'openingBalance' => 25,
'openingBalanceDate' => date('Y-m-d'),
'openingBalanceCurrency' => 1,
'_token' => 'replaceme',
'return_to_edit' => 1,
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\AccountFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake update routine:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('update')->andReturn($this->account);
$this->call('POST', '/accounts/update/' . $this->account->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
}

View File

@@ -1,78 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class AuthControllerTest
*/
class AuthControllerTest 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();
//FactoryMuffin::create('FireflyIII\User');
}
/**
* 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();
}
/**
* @covers FireflyIII\Http\Controllers\Auth\AuthController::postRegister
* @covers FireflyIII\Http\Controllers\Auth\AuthController::validator
* @covers FireflyIII\Http\Controllers\Auth\AuthController::create
*/
public function testPostRegister()
{
$data = [
'email' => 'test@example.com',
'password' => 'onetwothree',
'password_confirmation' => 'onetwothree',
'_token' => 'replaceMe'
];
$this->call('POST', '/auth/register', $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\Auth\AuthController::postRegister
* @covers FireflyIII\Http\Controllers\Auth\AuthController::validator
* @covers FireflyIII\Http\Controllers\Auth\AuthController::create
*/
public function testPostRegisterFails()
{
$data = [
'email' => 'test@example.com',
'password' => 'onetwothree',
'password_confirmation' => 'onetwofour',
'_token' => 'replaceMe'
];
$this->call('POST', '/auth/register', $data);
$this->assertResponseStatus(302);
}
}

View File

@@ -1,273 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class BillControllerTest
*/
class BillControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\BillController::create
*/
public function testCreate()
{
// go!
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
// CURRENCY:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/bills/create');
$this->assertViewHas('subTitle', 'Create new bill');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BillController::delete
*/
public function testDelete()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
$this->call('GET', '/bills/delete/' . $bill->id);
$this->assertViewHas('subTitle', 'Delete bill "' . e($bill->name) . '"');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BillController::destroy
*/
public function testDestroy()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$repository->shouldReceive('destroy')->andReturn(true);
$this->call('POST', '/bills/destroy/' . $bill->id, ['_token' => 'replaceMe']);
$this->assertSessionHas('success', 'The bill was deleted.');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\BillController::edit
*/
public function testEdit()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
// CURRENCY:
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/bills/edit/' . $bill->id);
$this->assertViewHas('subTitle', 'Edit bill "' . e($bill->name) . '"');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BillController::index
*/
public function testIndex()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
$collection = new Collection;
$collection->push($bill);
Amount::shouldReceive('format')->andReturn('XX');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$repository->shouldReceive('getBills')->once()->andReturn($collection);
$repository->shouldReceive('nextExpectedMatch')->with($bill)->andReturn(new Carbon);
$repository->shouldReceive('lastFoundMatch')->with($bill)->andReturn(new Carbon);
$this->call('GET', '/bills');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BillController::rescan
*/
public function testRescan()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$collection = new Collection;
$this->be($bill->user);
$collection->push($journal);
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn($collection);
$repository->shouldReceive('scan');
$this->call('GET', '/bills/rescan/' . $bill->id);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Rescanned everything.');
}
/**
* @covers FireflyIII\Http\Controllers\BillController::rescan
*/
public function testRescanInactive()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->active = 0;
$bill->save();
$this->be($bill->user);
$this->call('GET', '/bills/rescan/' . $bill->id);
$this->assertResponseStatus(302);
$this->assertSessionHas('warning', 'Inactive bills cannot be scanned.');
}
/**
* @covers FireflyIII\Http\Controllers\BillController::show
*/
public function testShow()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$collection = new Collection;
$bill->save();
$this->be($bill->user);
$collection->push($journal);
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$repository->shouldReceive('getJournals')->once()->andReturn($collection);
$repository->shouldReceive('nextExpectedMatch')->once()->andReturn(new Carbon);
Amount::shouldReceive('format')->andReturn('XX');
Amount::shouldReceive('formatJournal')->andReturn('XX');
Amount::shouldReceive('getCurrencyCode')->andReturn('XX');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/bills/show/' . $bill->id);
}
/**
* @covers FireflyIII\Http\Controllers\BillController::store
*/
public function testStore()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\BillFormRequest');
$this->be($bill->user);
$request->shouldReceive('getBillData')->once()->andReturn([]);
$repository->shouldReceive('store')->with([])->andReturn($bill);
$this->call('POST', '/bills/store', ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Bill "' . e($bill->name) . '" stored.');
}
/**
* @covers FireflyIII\Http\Controllers\BillController::store
*/
public function testStoreAndRedirect()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\BillFormRequest');
$this->be($bill->user);
$request->shouldReceive('getBillData')->once()->andReturn([]);
$repository->shouldReceive('store')->with([])->andReturn($bill);
$this->call('POST', '/bills/store', ['_token' => 'replaceMe', 'create_another' => 1]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Bill "' . e($bill->name) . '" stored.');
}
/**
* @covers FireflyIII\Http\Controllers\BillController::update
*/
public function testUpdate()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\BillFormRequest');
$this->be($bill->user);
$request->shouldReceive('getBillData')->once()->andReturn([]);
$repository->shouldReceive('update')->andReturn($bill);
$this->call('POST', '/bills/update/' . $bill->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Bill "' . e($bill->name) . '" updated.');
}
/**
* @covers FireflyIII\Http\Controllers\BillController::update
*/
public function testUpdateAndRedirect()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\BillFormRequest');
$this->be($bill->user);
$request->shouldReceive('getBillData')->once()->andReturn([]);
$repository->shouldReceive('update')->andReturn($bill);
$this->call('POST', '/bills/update/' . $bill->id, ['_token' => 'replaceMe', 'return_to_edit' => 1]);
$this->assertResponseStatus(302);
}
}

View File

@@ -1,435 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class BudgetControllerTest
*/
class BudgetControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::amount
*/
public function testAmount()
{
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$limitRepetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$budget = $limitRepetition->budgetlimit->budget;
$this->be($budget->user);
$today = new Carbon;
$this->session(['start' => $today]);
$repository->shouldReceive('updateLimitAmount')->once()->andReturn($limitRepetition);
$this->call('POST', '/budgets/amount/' . $budget->id, ['amount' => 100, '_token' => 'replaceme']);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::amount
*/
public function testAmountZero()
{
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$limitRepetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$budget = $limitRepetition->budgetlimit->budget;
$this->be($budget->user);
$today = new Carbon;
$this->session(['start' => $today]);
$repository->shouldReceive('updateLimitAmount')->once()->andReturn($limitRepetition);
$this->call('POST', '/budgets/amount/' . $budget->id, ['amount' => 0, '_token' => 'replaceme']);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::create
*/
public function testCreate()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$this->call('GET', '/budgets/create');
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Create a new budget');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::delete
*/
public function testDelete()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$this->call('GET', '/budgets/delete/' . $budget->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete budget "' . e($budget->name) . '"');
$this->assertViewHas('budget');
$this->assertSessionHas('budgets.delete.url');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::destroy
*/
public function testDestroy()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('destroy')->andReturn(true);
$this->call('POST', '/budgets/destroy/' . $budget->id, ['_token' => 'replaceme']);
$this->assertSessionHas('success', 'The budget "' . e($budget->name) . '" was deleted.');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::edit
*/
public function testEdit()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$this->call('GET', '/budgets/edit/' . $budget->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Edit budget "' . e($budget->name) . '"');
$this->assertViewHas('budget');
$this->assertSessionHas('budgets.edit.url');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::index
*/
public function testIndex()
{
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$collection = new Collection;
$collection->push($budget);
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$repository->shouldReceive('getActiveBudgets')->once()->andReturn($collection);
$repository->shouldReceive('getInactiveBudgets')->once()->andReturn($collection);
$repository->shouldReceive('cleanupBudgets')->once();
$repository->shouldReceive('spentInPeriodCorrected')->once();
$repository->shouldReceive('getCurrentRepetition')->once()->andReturn($repetition);
Amount::shouldReceive('getCurrencySymbol')->andReturn('x');
Amount::shouldReceive('format')->andReturn('x');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
$this->call('GET', '/budgets');
$this->assertResponseOk();
$this->assertViewHas('budgets');
$this->assertViewHas('inactive');
$this->assertViewHas('inactive');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::noBudget
*/
public function testNoBudget()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('getWithoutBudget')->andReturn(new Collection);
$this->call('GET', '/budgets/list/noBudget');
$this->assertResponseOk();
$this->assertViewHas('list');
$this->assertViewHas('subTitle');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::postUpdateIncome
*/
public function testPostUpdateIncome()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$date = Carbon::now()->startOfMonth()->format('FY');
Preferences::shouldReceive('set')->once()->withArgs(['budgetIncomeTotal' . $date, 1001]);
Preferences::shouldReceive('mark')->once()->andReturn(true);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$this->call('POST', '/budgets/income', ['_token' => 'replaceme', 'amount' => 1001]);
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('budgets.index');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::show
*/
public function testShow()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$this->be($budget->user);
$paginator = new LengthAwarePaginator(new Collection, 0, 20, 1);
Amount::shouldReceive('getCurrencyCode')->andReturn('x');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('format')->andReturn('x');
$repository->shouldReceive('getJournals')->andReturn($paginator);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$this->call('GET', '/budgets/show/' . $budget->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::show
*/
public function testShowInvalidRepetition()
{
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$budget = $repetition->budgetLimit->budget;
$otherBudget = FactoryMuffin::create('FireflyIII\Models\Budget');
$otherBudget->user_id = $budget->user_id;
$otherBudget->save();
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$this->be($otherBudget->user);
Amount::shouldReceive('getCurrencyCode')->andReturn('x');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('format')->andReturn('x');
$repository->shouldReceive('getJournals')->andReturn(new Collection);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$this->call('GET', '/budgets/show/' . $otherBudget->id . '/' . $repetition->id);
$this->assertResponseOk();
$this->assertViewHas('message', 'Invalid selection.');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::show
*/
public function testShowRepetition()
{
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$budget = $repetition->budgetLimit->budget;
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$this->be($budget->user);
$paginator = new LengthAwarePaginator(new Collection, 0, 20, 1);
Amount::shouldReceive('getCurrencyCode')->andReturn('x');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('format')->andReturn('x');
$repository->shouldReceive('getJournals')->andReturn($paginator);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$this->call('GET', '/budgets/show/' . $budget->id . '/' . $repetition->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::store
*/
public function testStore()
{
// a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$data = [
'name' => 'New test budget ' . rand(1, 1000),
'_token' => 'replaceme'
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake store routine:
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('store')->andReturn($budget);
$this->call('POST', '/budgets/store', $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::store
*/
public function testStoreAndRedirect()
{
// a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$data = [
'name' => 'New test budget ' . rand(1, 1000),
'_token' => 'replaceme',
'create_another' => 1,
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake store routine:
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('store')->andReturn($budget);
$this->call('POST', '/budgets/store', $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::update
*/
public function testUpdate()
{
// a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$data = [
'name' => 'Edited test account ' . rand(1, 1000),
'active' => 1,
'_token' => 'replaceme'
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake update routine:
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('update')->andReturn($budget);
$this->call('POST', '/budgets/update/' . $budget->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::update
*/
public function testUpdateAndRedirect()
{
// a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$data = [
'name' => 'Edited test account ' . rand(1, 1000),
'active' => 1,
'_token' => 'replaceme',
'return_to_edit' => 1,
];
// fake validation routine:
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
$request->shouldReceive('input')->andReturn('');
// fake update routine:
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('update')->andReturn($budget);
$this->call('POST', '/budgets/update/' . $budget->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\BudgetController::updateIncome
*/
public function testUpdateIncome()
{
// a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$date = Carbon::now()->format('FY');
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
Preferences::shouldReceive('get')->withArgs(['budgetIncomeTotal' . $date, 1000])->andReturn($pref);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$this->call('GET', '/budgets/income');
$this->assertResponseOk();
$this->assertViewHas('amount');
}
}

View File

@@ -1,263 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class CategoryControllerTest
*/
class CategoryControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::create
*/
public function testCreate()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$this->call('GET', '/categories/create');
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Create a new category');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::delete
*/
public function testDelete()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$this->call('GET', '/categories/delete/' . $category->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete category "' . e($category->name) . '"');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::destroy
*/
public function testDestroy()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$repository->shouldReceive('destroy');
$this->call('POST', '/categories/destroy/' . $category->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'The category "' . e($category->name) . '" was deleted.');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::edit
*/
public function testEdit()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$this->call('GET', '/categories/edit/' . $category->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Edit category "' . e($category->name) . '"');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::index
*/
public function testIndex()
{
$collection = new Collection;
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$collection->push($category);
Amount::shouldReceive('getCurrencyCode')->andReturn('xx');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$repository->shouldReceive('getCategories')->andReturn($collection);
$repository->shouldReceive('getLatestActivity')->andReturn(new Carbon);
$this->call('GET', '/categories');
$this->assertResponseOk();
$this->assertViewHas('categories');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::noCategory
*/
public function testNoCategory()
{
$collection = new Collection;
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
$collection->push($journal);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('xx');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$repository->shouldReceive('getWithoutCategory')->andReturn($repository);
$this->call('GET', '/categories/list/noCategory');
$this->assertResponseOk();
$this->assertViewHas('subTitle');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::show
*/
public function testShow()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$collection = new Collection;
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($category->user);
$collection->push($journal);
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$repository->shouldReceive('getJournals')->andReturn($collection);
$repository->shouldReceive('countJournals')->andReturn(1);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('xx');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('formatJournal')->andReturn('xx');
$this->call('GET', '/categories/show/' . $category->id);
$this->assertResponseOk();
$this->assertViewHas('hideCategory', true);
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::store
*/
public function testStore()
{
// create
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
// mock
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
// expect
$repository->shouldReceive('store')->andReturn($category);
$request->shouldReceive('input')->andReturn('');
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::store
*/
public function testStoreAndRedirect()
{
// create
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
// mock:
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
// fake:
$repository->shouldReceive('store')->andReturn($category);
$request->shouldReceive('input')->andReturn('');
$this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'create_another' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'New category "' . $category->name . '" stored!');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::update
*/
public function testUpdate()
{
// create
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
// mock
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
// expect
$repository->shouldReceive('update')->andReturn($category);
$request->shouldReceive('input')->andReturn('');
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
}
/**
* @covers FireflyIII\Http\Controllers\CategoryController::update
*/
public function testUpdateAndRedirect()
{
// create
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
// mock
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest');
// expect
$request->shouldReceive('input')->andReturn('');
$repository->shouldReceive('update')->andReturn($category);
$this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'return_to_edit' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Category "' . $category->name . '" updated.');
}
}

View File

@@ -1,279 +0,0 @@
<?php
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class CurrencyControllerTest
*/
class CurrencyControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::create
*/
public function testCreate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/currency/create');
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Create a new currency');
$this->assertViewHas('subTitleIcon', 'fa-plus');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::defaultCurrency
*/
public function testDefaultCurrency()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->call('GET', '/currency/default/' . $currency->id);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', $currency->name . ' is now the default currency.');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::delete
*/
public function testDelete()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('countJournals')->andReturn(0);
$this->call('GET', '/currency/delete/' . $currency->id);
$this->assertResponseOk();
$this->assertViewHas('currency');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::delete
*/
public function testDeleteUnable()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('countJournals')->andReturn(1);
$this->call('GET', '/currency/delete/' . $currency->id);
$this->assertResponseStatus(302);
$this->assertSessionHas('error');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::destroy
*/
public function testDestroy()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('countJournals')->andReturn(0);
$this->call('POST', '/currency/destroy/' . $currency->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success', 'Currency "' . e($currency->name) . '" deleted');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::destroy
*/
public function testDestroyUnable()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('countJournals')->andReturn(1);
$this->call('POST', '/currency/destroy/' . $currency->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('error');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::edit
*/
public function testEdit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('countJournals')->andReturn(0);
$this->call('GET', '/currency/edit/' . $currency->id);
$this->assertResponseOk();
$this->assertViewHas('currency');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::index
*/
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$repository->shouldReceive('get')->andReturn(new Collection);
$repository->shouldReceive('getCurrencyByPreference')->andReturn($currency);
$this->call('GET', '/currency');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CurrencyFormRequest');
$request->shouldReceive('getCurrencyData')->andReturn([]);
$repository->shouldReceive('store')->andReturn($currency);
$this->call('POST', '/currency/store', ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::store
*/
public function testStoreAndReturn()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CurrencyFormRequest');
$request->shouldReceive('getCurrencyData')->andReturn([]);
$repository->shouldReceive('store')->andReturn($currency);
$this->call('POST', '/currency/store', ['_token' => 'replaceMe', 'create_another' => 1]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::update
*/
public function testUpdate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CurrencyFormRequest');
$request->shouldReceive('getCurrencyData')->andReturn([]);
$repository->shouldReceive('update')->andReturn($currency);
$this->call('POST', '/currency/update/' . $currency->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\CurrencyController::update
*/
public function testUpdateAndReturn()
{
$user = FactoryMuffin::create('FireflyIII\User');
$role = FactoryMuffin::create('FireflyIII\Models\Role');
$role->name = 'owner';
$role->save();
$user->attachRole($role);
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
$request = $this->mock('FireflyIII\Http\Requests\CurrencyFormRequest');
$request->shouldReceive('getCurrencyData')->andReturn([]);
$repository->shouldReceive('update')->andReturn($currency);
$this->call('POST', '/currency/update/' . $currency->id, ['_token' => 'replaceMe', 'return_to_edit' => 1]);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
}

View File

@@ -1,104 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class HelpControllerTest
*/
class HelpControllerTest 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();
}
/**
* Everything present and accounted for, and in cache:
*
* @covers FireflyIII\Http\Controllers\HelpController::show
*/
public function testGetHelpText()
{
// login
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock some stuff.
$interface = $this->mock('FireflyIII\Helpers\Help\HelpInterface');
$interface->shouldReceive('hasRoute')->once()->with('accounts.index')->andReturn(true);
$interface->shouldReceive('getFromCache')->once()->with('help.accounts.index.title')->andReturn('Title.');
$interface->shouldReceive('getFromCache')->once()->with('help.accounts.index.text')->andReturn('Text');
$interface->shouldReceive('inCache')->andReturn(true);
$this->call('GET', '/help/accounts.index');
$this->assertResponseOk();
}
/**
* Everything present and accounted for, but not cached
*
* @covers FireflyIII\Http\Controllers\HelpController::show
*/
public function testGetHelpTextNoCache()
{
// login
$user = FactoryMuffin::create('FireflyIII\User');
$content = ['title' => 'Bla', 'text' => 'Bla'];
$this->be($user);
// mock some stuff.
$interface = $this->mock('FireflyIII\Helpers\Help\HelpInterface');
$interface->shouldReceive('hasRoute')->once()->with('accounts.index')->andReturn(true);
$interface->shouldReceive('getFromGithub')->once()->with('accounts.index')->andReturn($content);
$interface->shouldReceive('putInCache')->once()->withArgs(['accounts.index', $content]);
$interface->shouldReceive('inCache')->once()->andReturn(false);
$this->call('GET', '/help/accounts.index');
$this->assertResponseOk();
}
/**
* No such route.
*
* @covers FireflyIII\Http\Controllers\HelpController::show
*/
public function testGetHelpTextNoRoute()
{
// login
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock some stuff.
$interface = $this->mock('FireflyIII\Helpers\Help\HelpInterface');
$interface->shouldReceive('hasRoute')->once()->with('accounts.index')->andReturn(false);
$this->call('GET', '/help/accounts.index');
$this->assertResponseOk();
}
}

View File

@@ -1,159 +0,0 @@
<?php
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class HomeControllerTest
*/
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
*/
public function testDateRange()
{
$start = '2015-03-01';
$end = '2015-03-31';
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
$this->assertResponseOk();
$this->assertSessionHas('start');
$this->assertSessionHas('end');
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
*/
public function testDateRangeWarning()
{
$start = '2014-03-01';
$end = '2015-03-31';
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start, '_token' => 'replaceme']);
$this->assertResponseOk();
$this->assertSessionHas('start');
$this->assertSessionHas('end');
$this->assertSessionHas('warning');
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::flush
*/
public function testFlush()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// create at least one tag:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->tags()->save($tag);
$this->call('GET', '/flush');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::index
*/
public function testIndex()
{
$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);
$repository->shouldReceive('sumOfEverything')->once()->andReturn(1);
$repository->shouldReceive('getFrontpageTransactions')->once()->andReturn($journals);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
Amount::shouldReceive('getCurrencyCode')->andReturn('EUR');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('format')->andReturn('xxx');
Amount::shouldReceive('formatJournal')->with($journal)->andReturn('xxx');
$this->call('GET', '/');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::index
*/
public function testIndexEmpty()
{
$user = FactoryMuffin::create('FireflyIII\User');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$this->be($user);
// mock ALL THE THINGS!
$repository->shouldReceive('countAccounts')->once()->andReturn(0);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
$this->call('GET', '/');
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('new-user.index');
}
}

View File

@@ -1,228 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class JsonControllerTest
*/
class JsonControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::boxBillsPaid
*/
public function testBoxBillsPaid()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$creditCard = FactoryMuffin::create('FireflyIII\Models\Account');
$ccs = new Collection([$creditCard]);
$collection = new Collection([$bill]);
$ranges = [['start' => new Carbon, 'end' => new Carbon]];
$this->be($bill->user);
$bills = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// mock!
$bills->shouldReceive('getActiveBills')->andReturn($collection);
$bills->shouldReceive('getRanges')->andReturn($ranges);
$bills->shouldReceive('getJournalsInRange')->andReturn(new Collection);
$bills->shouldReceive('billPaymentsInRange')->andReturn(12);
$accounts->shouldReceive('getCreditCards')->andReturn($ccs);
$accounts->shouldReceive('getTransfersInRange')->andReturn(new Collection);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Steam::shouldReceive('balance')->andReturn(0);
$this->call('GET', '/json/box/bills-paid');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::boxBillsUnpaid
*/
public function testBoxBillsUnpaid()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$creditCard = FactoryMuffin::create('FireflyIII\Models\Account');
$ccs = new Collection([$creditCard]);
$collection = new Collection([$bill]);
$ranges = [['start' => new Carbon, 'end' => new Carbon]];
$this->be($bill->user);
$bills = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// mock!
$bills->shouldReceive('getActiveBills')->andReturn($collection);
$bills->shouldReceive('getRanges')->andReturn($ranges);
$bills->shouldReceive('getJournalsInRange')->andReturn(new Collection);
$bills->shouldReceive('createFakeBill')->andReturn($bill);
$accounts->shouldReceive('getCreditCards')->andReturn($ccs);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Steam::shouldReceive('balance')->andReturn(-1);
$this->call('GET', '/json/box/bills-unpaid');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::boxIn
*/
public function testBoxIn()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$repository = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
$repository->shouldReceive('incomeInPeriodCorrected')->andReturn(new Collection);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/json/box/in');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::boxOut
*/
public function testBoxOut()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$repository = $this->mock('FireflyIII\Helpers\Report\ReportQueryInterface');
$repository->shouldReceive('expenseInPeriodCorrected')->andReturn(new Collection);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/json/box/out');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::categories
*/
public function testCategories()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$categories = new Collection([$category]);
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$repository->shouldReceive('getCategories')->andReturn($categories);
$this->call('GET', '/json/categories');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::expenseAccounts
*/
public function testExpenseAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
$accounts = new Collection([$account]);
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->with(['Expense account', 'Beneficiary account'])->andReturn($accounts);
$this->call('GET', '/json/expense-accounts');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::revenueAccounts
*/
public function testRevenueAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
$accounts = new Collection([$account]);
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->with(['Revenue account'])->andReturn($accounts);
$this->call('GET', '/json/revenue-accounts');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::tags
*/
public function testTags()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->user()->associate($user);
$tag->save();
$this->be($tag->user);
$tags = new Collection([$tag]);
$repository = $this->mock('FireflyIII\Repositories\Tag\TagRepositoryInterface');
$repository->shouldReceive('get')->andReturn($tags);
$this->call('GET', '/json/tags');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\JsonController::transactionJournals
*/
public function testTransactionJournals()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$collection = new Collection([$journal]);
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
$repository->shouldReceive('getTransactionType')->with('withdrawal')->andReturn($type);
$repository->shouldReceive('getJournalsOfType')->with($type)->andReturn($collection);
$this->call('GET', '/json/transaction-journals/withdrawal');
$this->assertResponseOk();
}
}

View File

@@ -1,110 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class NewUserControllerTest
*/
class NewUserControllerTest 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\NewUserController::index
*/
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$this->be($user);
// mock ALL THE THINGS!
$repository->shouldReceive('countAccounts')->once()->andReturn(0);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/new-user');
$this->assertResponseStatus(200);
}
public function testIndexNoAccounts()
{
$user = FactoryMuffin::create('FireflyIII\User');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$this->be($user);
// mock ALL THE THINGS!
$repository->shouldReceive('countAccounts')->once()->andReturn(3);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
$this->call('GET', '/new-user');
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('index');
}
public function testPostIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$this->be($user);
$data = [
'_token' => 'replaceMe',
'bank_name' => 'Some Bank',
'bank_balance' => '100',
'balance_currency_id' => $currency->id,
'savings_balance' => '100',
'credit_card_limit' => '100',
];
$repository->shouldReceive('store')->andReturn($account);
$this->call('POST', '/new-user/submit', $data);
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('index');
}
}

View File

@@ -1,454 +0,0 @@
<?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;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class PiggyBankControllerTest
*/
class PiggyBankControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::add
*/
public function testAdd()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
// mock
/** @var Mockery\MockInterface $repository */
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('leftOnAccount')->withAnyArgs()->andReturn(12);
Amount::shouldReceive('format')->andReturn('XXxx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/piggy-banks/add/' . $piggyBank->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::create
*/
public function testCreate()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$collection = new Collection([$account]);
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
// also cover the view now that we've touched ExpandedForm:
ExpandedForm::shouldReceive('text')->andReturn('');
ExpandedForm::shouldReceive('select')->andReturn('');
ExpandedForm::shouldReceive('amount')->andReturn('');
ExpandedForm::shouldReceive('date')->andReturn('');
ExpandedForm::shouldReceive('checkbox')->andReturn('');
ExpandedForm::shouldReceive('optionsList')->andReturn('');
$this->call('GET', '/piggy-banks/create');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::delete
*/
public function testDelete()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$this->call('GET', '/piggy-banks/delete/' . $piggyBank->id);
$this->assertResponseOk();
$this->assertViewHas('subTitle', 'Delete piggy bank "' . e($piggyBank->name) . '"');
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::destroy
*/
public function testDestroy()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$repository = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$repository->shouldReceive('destroy')->once()->withAnyArgs()->andReturn(true);
$this->call('POST', '/piggy-banks/destroy/' . $piggyBank->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::edit
*/
public function testEdit()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank->targetdate = Carbon::now()->addYear();
$piggyBank->save();
$this->be($piggyBank->account->user);
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$collection = new Collection([$account]);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
// also cover the view now that we've touched ExpandedForm:
ExpandedForm::shouldReceive('text')->andReturn('');
ExpandedForm::shouldReceive('select')->andReturn('');
ExpandedForm::shouldReceive('amount')->andReturn('');
ExpandedForm::shouldReceive('date')->andReturn('');
ExpandedForm::shouldReceive('checkbox')->andReturn('');
ExpandedForm::shouldReceive('optionsList')->andReturn('');
$this->call('GET', '/piggy-banks/edit/' . $piggyBank->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::edit
*/
public function testEditNullDate()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBank->targetdate = null;
$piggyBank->save();
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$collection = new Collection([$account]);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getAccounts')->once()->with(['Default account', 'Asset account'])->andReturn($collection);
ExpandedForm::shouldReceive('makeSelectList')->with($collection)->andReturn([]);
// also cover the view now that we've touched ExpandedForm:
ExpandedForm::shouldReceive('text')->andReturn('');
ExpandedForm::shouldReceive('select')->andReturn('');
ExpandedForm::shouldReceive('amount')->andReturn('');
ExpandedForm::shouldReceive('date')->andReturn('');
ExpandedForm::shouldReceive('checkbox')->andReturn('');
ExpandedForm::shouldReceive('optionsList')->andReturn('');
$this->call('GET', '/piggy-banks/edit/' . $piggyBank->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::index
*/
public function testIndex()
{
$piggyBank1 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank2 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank3 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank2->account_id = $piggyBank1->account_id;
$user = FactoryMuffin::create('FireflyIII\User');
$piggyBank2->save();
$collection = new Collection([$piggyBank1, $piggyBank2, $piggyBank3]);
$this->be($user);
// mock!
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
// act!
$piggyBanks->shouldReceive('getPiggyBanks')->once()->andReturn($collection);
Steam::shouldReceive('balance')->andReturn(20);
$accounts->shouldReceive('leftOnAccount')->andReturn(12);
Amount::shouldReceive('format')->andReturn('123');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/piggy-banks');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::order
*/
public function testOrder()
{
$piggyBank1 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank2 = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('reset')->once();
$piggyBanks->shouldReceive('setOrder');
$array = [
$piggyBank1->id => 0,
$piggyBank2->id => 1,
];
$this->call('POST', '/piggy-banks/sort', ['_token' => 'replaceMe', 'order' => $array]);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::postAdd
*/
public function testPostAdd()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
// mock!
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$accounts->shouldReceive('leftOnAccount')->andReturn(20);
$piggyBanks->shouldReceive('createEvent')->once();
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('POST', '/piggy-banks/add/' . $piggyBank->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::postAdd
*/
public function testPostAddOverdraw()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
// mock!
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$accounts->shouldReceive('leftOnAccount')->andReturn(20);
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('POST', '/piggy-banks/add/' . $piggyBank->id, ['_token' => 'replaceMe', 'amount' => '10000']);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::postRemove
*/
public function testPostRemove()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
// mock!
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$accounts->shouldReceive('leftOnAccount')->andReturn(20);
$piggyBanks->shouldReceive('createEvent')->once();
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
$this->call('POST', '/piggy-banks/remove/' . $piggyBank->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
}
public function testPostRemoveOverdraw()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
// mock!
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$accounts->shouldReceive('leftOnAccount')->andReturn(20);
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
$this->call('POST', '/piggy-banks/remove/' . $piggyBank->id, ['_token' => 'replaceMe', 'amount' => '10000']);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::remove
*/
public function testRemove()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
$this->call('GET', '/piggy-banks/remove/' . $piggyBank->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::show
*/
public function testShow()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('getEvents')->andReturn(new Collection);
Amount::shouldReceive('format')->andReturn('something');
Amount::shouldReceive('getCurrencySymbol')->andReturn('something');
Amount::shouldReceive('getCurrencyCode')->andReturn('something');
$this->call('GET', '/piggy-banks/show/' . $piggyBank->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::store
*/
public function testStore()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBankData = [
'name' => 'Some name' . rand(1, 100),
'account_id' => $piggyBank->account_id,
'targetamount' => 100,
'targetdate' => '',
'_token' => 'replaceMe'
];
// mock!
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('store')->once()->andReturn($piggyBank);
$this->call('POST', '/piggy-banks/store', $piggyBankData);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::store
*/
public function testStoreCreateAnother()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBankData = [
'name' => 'Some name' . rand(1, 100),
'account_id' => $piggyBank->account_id,
'targetamount' => 100,
'targetdate' => '',
'create_another' => 1,
'_token' => 'replaceMe'
];
// mock!
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('store')->once()->andReturn($piggyBank);
$this->call('POST', '/piggy-banks/store', $piggyBankData);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::update
*/
public function testUpdate()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBankData = [
'name' => 'Some name' . rand(1, 100),
'account_id' => $piggyBank->account_id,
'targetamount' => 200,
'targetdate' => '',
'_token' => 'replaceMe'
];
// mock!
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('update')->once()->andReturn($piggyBank);
$this->call('POST', '/piggy-banks/update/' . $piggyBank->id, $piggyBankData);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\PiggyBankController::update
*/
public function testUpdateReturnToEdit()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$piggyBankData = [
'name' => 'Some name' . rand(1, 100),
'account_id' => $piggyBank->account_id,
'targetamount' => 200,
'targetdate' => '',
'return_to_edit' => 1,
'_token' => 'replaceMe'
];
// mock!
$piggyBanks = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
$piggyBanks->shouldReceive('update')->once()->andReturn($piggyBank);
$this->call('POST', '/piggy-banks/update/' . $piggyBank->id, $piggyBankData);
$this->assertResponseStatus(302);
}
}

View File

@@ -1,121 +0,0 @@
<?php
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class PreferencesControllerTest
*/
class PreferencesControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\PreferencesController::index
*/
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
// mock:
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->with(['Default account', 'Asset account'])->andReturn(new Collection);
Preferences::shouldReceive('get')->once()->withArgs(['viewRange', '1M'])->andReturn($pref);
Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($pref);
Preferences::shouldReceive('get')->once()->withArgs(['budgetMaximum', 1000])->andReturn($pref);
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($pref);
Amount::shouldReceive('format')->andReturn('xx');
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$this->call('GET', '/preferences');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\PreferencesController::postIndex
*/
public function testPostIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$data = [
'frontPageAccounts' => [1, 2, 3],
'_token' => 'replaceMe',
'viewRange' => '1M',
'language' => 'en',
];
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
Preferences::shouldReceive('set')->once()->withArgs(['frontPageAccounts', [1, 2, 3]]);
Preferences::shouldReceive('set')->once()->withArgs(['viewRange', '1M']);
Preferences::shouldReceive('set')->once()->withArgs(['budgetMaximum', 0]);
Preferences::shouldReceive('set')->once()->withArgs(['language', 'en']);
Preferences::shouldReceive('mark')->once()->andReturn(true);
// language preference:
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
$language->save();
Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
$this->call('POST', '/preferences', $data);
$this->assertResponseStatus(302);
}
}

View File

@@ -1,195 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ProfileControllerTest
*/
class ProfileControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::changePassword
*/
public function testChangePassword()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/profile/change-password');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::deleteAccount
*/
public function testDeleteAccount()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/profile/delete-account');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::index
*/
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/profile');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePassword()
{
$user = FactoryMuffin::create('FireflyIII\User');
$user->password = bcrypt('current');
$user->save();
$this->be($user);
$post = [
'current_password' => 'current',
'new_password' => 'something',
'new_password_confirmation' => 'something',
'_token' => 'replaceMe'
];
$this->call('POST', '/profile/change-password', $post);
$this->assertRedirectedToRoute('profile');
$this->assertSessionHas('success', 'Password changed!');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordInvalidCurrent()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$post = [
'current_password' => 'currentWrong',
'new_password' => 'something',
'new_password_confirmation' => 'something',
'_token' => 'replaceMe'
];
$this->call('POST', '/profile/change-password', $post);
$this->assertRedirectedToRoute('profile.change-password');
$this->assertSessionHas('error', 'Invalid current password!');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::postChangePassword
* @covers FireflyIII\Http\Controllers\ProfileController::validatePassword
*/
public function testPostChangePasswordNoNewPassword()
{
$user = FactoryMuffin::create('FireflyIII\User');
$user->password = bcrypt('current');
$user->save();
$this->be($user);
$post = [
'current_password' => 'current',
'new_password' => 'current',
'new_password_confirmation' => 'current',
'_token' => 'replaceMe'
];
$this->call('POST', '/profile/change-password', $post);
$this->assertSessionHas('error', 'The idea is to change your password.');
$this->assertResponseStatus(302);
$this->assertRedirectedToRoute('profile.change-password');
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
*/
public function testPostDeleteAccount()
{
$user = FactoryMuffin::create('FireflyIII\User');
$user->password = bcrypt('current');
$user->save();
$this->be($user);
$post = [
'password' => 'current',
'_token' => 'replaceMe'
];
$this->call('POST', '/profile/delete-account', $post);
$this->assertRedirectedToRoute('index');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\ProfileController::postDeleteAccount
*/
public function testPostDeleteAccountInvalidPassword()
{
$user = FactoryMuffin::create('FireflyIII\User');
$user->password = bcrypt('current');
$user->save();
$this->be($user);
$post = [
'password' => 'currentXX',
'_token' => 'replaceMe'
];
$this->call('POST', '/profile/delete-account', $post);
$this->assertRedirectedToRoute('profile.delete-account');
$this->assertSessionHas('error', 'Invalid password!');
$this->assertResponseStatus(302);
}
}

View File

@@ -1,172 +0,0 @@
<?php
use FireflyIII\Models\AccountMeta;
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();
}
/**
* @covers FireflyIII\Http\Controllers\ReportController::index
*/
public function testIndex()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock stuff
$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'
]
);
$helper->shouldReceive('listOfMonths')->andReturn([]);
$helper->shouldReceive('listOfYears')->andReturn([]);
$repository->shouldReceive('getAccounts')->andReturn(new Collection([$account]));
$this->call('GET', '/reports');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ReportController::month
*/
public function testMonth()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\Account');
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget1->queryAmount = 12;
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget2->queryAmount = 0;
$this->be($user);
// mock!
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
// fake!
$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);
$helper->shouldReceive('getBillReport')->andReturn(new Collection);
$this->call('GET', '/reports/2015/1');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ReportController::month
*/
public function testMonthShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\Account');
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget1->queryAmount = 12;
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget2->queryAmount = 0;
$this->be($user);
// mock!
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
// fake!
$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);
$helper->shouldReceive('getBillReport')->andReturn(new Collection);
$this->call('GET', '/reports/2015/1/shared');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\ReportController::year
*/
public function testYear()
{
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// make shared:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'accountRole',
'data' => 'sharedAsset'
]
);
new Collection([$journal]);
$this->be($user);
$helper = $this->mock('FireflyIII\Helpers\Report\ReportHelperInterface');
$helper->shouldReceive('getAccountReport')->once()->withAnyArgs()->andReturn([]);
$helper->shouldReceive('getIncomeReport')->once()->withAnyArgs()->andReturn([]);
$helper->shouldReceive('getExpenseReport')->once()->withAnyArgs()->andReturn([]);
// mock stuff!
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('format')->andReturn('X');
$this->call('GET', '/reports/2015/shared');
$this->assertResponseOk();
}
}

View File

@@ -1,58 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class SearchControllerTest
*/
class SearchControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\SearchController::index
*/
public function testSearch()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$words = ['Something'];
// mock!
$repository = $this->mock('FireflyIII\Support\Search\SearchInterface');
$repository->shouldReceive('searchTransactions')->with($words)->once()->andReturn([]);
$repository->shouldReceive('searchAccounts')->with($words)->once()->andReturn([]);
$repository->shouldReceive('searchCategories')->with($words)->once()->andReturn([]);
$repository->shouldReceive('searchBudgets')->with($words)->once()->andReturn([]);
$repository->shouldReceive('searchTags')->with($words)->once()->andReturn([]);
$this->call('GET', '/search?q=Something');
$this->assertResponseOk();
}
}

View File

@@ -1,296 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class TagControllerTest
*/
class TagControllerTest 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();
FactoryMuffin::create('FireflyIII\User');
}
/**
* 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();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::create
*/
public function testCreate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/tags/create');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::delete
*/
public function testDelete()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('GET', '/tags/delete/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::destroy
*/
public function testDestroy()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('POST', '/tags/destroy/' . $tag->id, ['_token' => 'replaceMe']);
$this->assertSessionHas('success');
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\TagController::edit
*/
public function testEdit()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('GET', '/tags/edit/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::edit
*/
public function testEditBalancingAct()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type->type = 'Transfer';
$type->save();
$journal->transactionType()->associate($type);
$journal->save();
$tag->transactionJournals()->save($journal);
$tag->tagMode = 'balancingAct';
$tag->save();
$this->be($tag->user);
$this->call('GET', '/tags/edit/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::edit
*/
public function testEditThreeExpenses()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type->type = 'Withdrawal';
$type->save();
for ($i = 0; $i < 3; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transactionType()->associate($type);
$journal->save();
$tag->transactionJournals()->save($journal);
}
$tag->tagMode = 'nothing';
$tag->save();
$this->be($tag->user);
$this->call('GET', '/tags/edit/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::hideTagHelp
*/
public function testHideTagHelp()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('POST', '/tags/hideTagHelp/true', ['_token' => 'replaceMe']);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::index
*/
public function testIndex()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('GET', '/tags');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::edit
*/
public function testMultipleDeposits()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
for ($i = 0; $i < 3; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $type->id;
$journal->save();
$tag->transactionJournals()->save($journal);
}
$tag->tagMode = 'nothing';
$tag->save();
$this->be($tag->user);
$this->call('GET', '/tags/edit/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::show
*/
public function testShow()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$this->call('GET', '/tags/show/' . $tag->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TagController::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$data = [
'_token' => 'replaceMe',
'tag' => 'BlaBla' . rand(1, 1000),
'tagMode' => 'nothing'
];
$this->call('POST', '/tags/store/', $data);
$this->assertResponseStatus(302);
}
/**
* @covers FireflyIII\Http\Controllers\TagController::store
*/
public function testStoreWithLocation()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$data = [
'_token' => 'replaceMe',
'tag' => 'BlaBla' . rand(1, 1000),
'tagMode' => 'nothing',
'latitude' => 12,
'longitude' => 13,
'zoomLevel' => 3,
'setTag' => 'true',
'create_another' => 1,
];
$this->call('POST', '/tags/store/', $data);
$this->assertResponseStatus(302);
}
public function testUpdate()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$data = [
'_token' => 'replaceMe',
'tag' => 'BlaBla' . rand(1, 1000),
'tagMode' => 'nothing',
'id' => $tag->id,
];
$this->call('POST', '/tags/update/' . $tag->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
public function testUpdateNoNameChange()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$data = [
'_token' => 'replaceMe',
'tag' => $tag->tag,
'tagMode' => 'nothing',
'id' => $tag->id,
];
$this->call('POST', '/tags/update/' . $tag->id, $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\TagController::update
*/
public function testUpdateWithLocation()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->be($tag->user);
$data = [
'_token' => 'replaceMe',
'tag' => 'BlaBla' . rand(1, 1000),
'tagMode' => 'nothing',
'id' => $tag->id,
'latitude' => 12,
'setTag' => 'true',
'longitude' => 13,
'zoomLevel' => 3,
'return_to_edit' => 1,
];
$this->call('POST', '/tags/update/' . $tag->id, $data);
$this->assertResponseStatus(302);
}
}

View File

@@ -1,598 +0,0 @@
<?php
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Class TransactionControllerTest
*/
class TransactionControllerTest 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();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::create
*/
public function testCreate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transactions/create/withdrawal?account_id=12');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::delete
*/
public function testDelete()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
$this->call('GET', '/transaction/delete/' . $journal->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::destroy
*/
public function testDestroy()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('delete')->andReturn(true);
$this->call('POST', '/transaction/destroy/' . $journal->id, ['_token' => 'replaceMe']);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEdit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make complete journal:
$accountType = FactoryMuffin::create('FireflyIII\Models\AccountType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$transaction1 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$transaction2 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$accountType->type = 'Asset account';
$account->account_type_id = $accountType->id;
$account->save();
$transaction1->account_id = $account->id;
$transaction1->transaction_journal_id = $journal->id;
$transaction1->save();
$transaction2->account_id = $account->id;
$transaction2->transaction_journal_id = $journal->id;
$transaction2->save();
// also add some tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->transactionJournals()->save($journal);
// and a category and a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$category->transactionJournals()->save($journal);
$budget->transactionJournals()->save($journal);
// and a piggy bank event:
$pbEvent = FactoryMuffin::create('FireflyIII\Models\PiggyBankEvent');
$pbEvent->transaction_journal_id = $journal->id;
$pbEvent->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transaction/edit/' . $journal->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditCashDestination()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make complete journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
//$expense = FactoryMuffin::create('FireflyIII\Models\Account'); // expense account
//$revenue = FactoryMuffin::create('FireflyIII\Models\Account'); // revenue account
$asset = FactoryMuffin::create('FireflyIII\Models\Account'); // asset account
$cash = FactoryMuffin::create('FireflyIII\Models\Account'); // cash account
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->amount = -300;
$journal->transactions[0]->save();
$journal->transactions[0]->account_id = $cash->id;
$journal->transactions[0]->amount = 300;
$journal->transactions[0]->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transaction/edit/' . $journal->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::edit
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testEditDeposit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make complete journal:
$accountType = FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$transaction1 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$transaction2 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$accountType->type = 'Asset account';
$account->account_type_id = $accountType->id;
$account->save();
$transaction1->account_id = $account->id;
$transaction1->transaction_journal_id = $journal->id;
$transaction1->save();
$transaction2->account_id = $account->id;
$transaction2->transaction_journal_id = $journal->id;
$transaction2->save();
// also add some tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->transactionJournals()->save($journal);
// and a category and a budget:
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$category->transactionJournals()->save($journal);
$budget->transactionJournals()->save($journal);
// and a piggy bank event:
$pbEvent = FactoryMuffin::create('FireflyIII\Models\PiggyBankEvent');
$pbEvent->transaction_journal_id = $journal->id;
$pbEvent->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->andReturn(new Collection);
$this->call('GET', '/transaction/edit/' . $journal->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::index
*/
public function testIndexRevenue()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('getJournalsOfTypes')->withArgs([['Deposit'], 0, 0])->andReturn(new LengthAwarePaginator(new Collection, 0, 50));
$this->call('GET', '/transactions/deposit');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::index
*/
public function testIndexTransfer()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('getJournalsOfTypes')->withArgs([['Transfer'], 0, 0])->andReturn(new LengthAwarePaginator(new Collection, 0, 50));
$this->call('GET', '/transactions/transfers');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::index
*/
public function testIndexWithdrawal()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('getJournalsOfTypes')->withArgs([['Withdrawal'], 0, 0])->andReturn(new LengthAwarePaginator(new Collection, 0, 50));
$this->call('GET', '/transactions/withdrawal');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::reorder
*/
public function testReorder()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('getWithDate')->withAnyArgs()->andReturn($journal);
$data = [
'items' => [$journal->id],
'date' => $journal->date->format('Y-m-d'),
'_token' => 'replaceMe'
];
$this->call('POST', '/transaction/reorder', $data);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\TransactionController::show
*/
public function testShow()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$transaction1 = FactoryMuffin::create('FireflyIII\Models\Transaction');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$transaction1->transaction_journal_id = $journal->id;
$transaction1->save();
$this->be($journal->user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('getAmountBefore')->withAnyArgs()->andReturn(5);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
Amount::shouldReceive('getCurrencyCode')->andReturn('X');
Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
Amount::shouldReceive('formatTransaction')->andReturn('X');
Amount::shouldReceive('format')->andReturn('X');
$this->call('GET', '/transaction/show/' . $journal->id);
$this->assertResponseOk();
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::store
*/
public function testStore()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$this->be($account->user);
$data = [
'what' => 'withdrawal',
'description' => 'Bla bla bla',
'account_id' => $account->id,
'expense_account' => 'Bla bla',
'amount' => '100',
'amount_currency_id' => $currency->id,
'date' => '2015-05-05',
'budget_id' => '0',
'category' => '',
'tags' => 'fat-test',
'piggy_bank_id' => '0',
'_token' => 'replaceMe',
];
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('store')->andReturn($journal);
$this->call('POST', '/transactions/store/withdrawal', $data);
//$this->assertSessionHas('errors','bla');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::store
*/
public function testStoreCreateAnother()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$this->be($account->user);
$data = [
'what' => 'withdrawal',
'description' => 'Bla bla bla',
'account_id' => $account->id,
'expense_account' => 'Bla bla',
'amount' => '100',
'amount_currency_id' => $currency->id,
'date' => '2015-05-05',
'budget_id' => '0',
'create_another' => '1',
'category' => '',
'tags' => 'fat-test',
'piggy_bank_id' => '0',
'_token' => 'replaceMe',
];
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('store')->andReturn($journal);
$this->call('POST', '/transactions/store/withdrawal', $data);
//$this->assertSessionHas('errors','bla');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::store
*/
public function testStoreTransfer()
{
// account types:
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$piggy = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($account->user);
$account2->user_id = $account->user_id;
$account->account_type_id = $asset->id;
$account2->account_type_id = $asset->id;
$piggy->account_id = $account->id;
$account->save();
$account2->save();
$piggy->save();
$data = [
'what' => 'transfer',
'description' => 'Bla bla bla',
'account_from_id' => $account->id,
'account_to_id' => $account2->id,
'amount' => '100',
'amount_currency_id' => $currency->id,
'date' => '2015-05-05',
'budget_id' => '0',
'create_another' => '1',
'category' => '',
'tags' => 'fat-test',
'piggy_bank_id' => $piggy->id,
'_token' => 'replaceMe',
];
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('store')->andReturn($journal);
$this->call('POST', '/transactions/store/withdrawal', $data);
//$this->assertSessionHas('errors','bla');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::update
*/
public function testUpdate()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$this->be($journal->user);
$account->user_id = $journal->user_id;
$account->save();
$data = [
'_token' => 'replaceMe',
'id' => $journal->id,
'what' => 'withdrawal',
'description' => 'LunchX',
'account_id' => $account->id,
'expense_account' => 'Lunch House',
'amount' => '4.72',
'amount_currency_id' => $currency->id,
'date' => '2015-05-31',
'budget_id' => '0',
'category' => 'Lunch',
'tags' => 'fat-test',
'piggy_bank_id' => '0',
];
$this->call('POST', '/transactions/store/withdrawal', $data);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('update')->andReturn($journal);
$this->call('POST', '/transaction/update/' . $journal->id, $data);
//$this->assertSessionHas('errors','bla');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Http\Controllers\TransactionController::update
*/
public function testUpdateWithRedirect()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$this->be($journal->user);
$account->user_id = $journal->user_id;
$account->save();
$data = [
'_token' => 'replaceMe',
'id' => $journal->id,
'what' => 'withdrawal',
'description' => 'LunchX',
'account_id' => $account->id,
'expense_account' => 'Lunch House',
'amount' => '4.72',
'amount_currency_id' => $currency->id,
'date' => '2015-05-31',
'budget_id' => '0',
'category' => 'Lunch',
'return_to_edit' => 1,
'tags' => 'fat-test',
'piggy_bank_id' => '0',
];
$this->call('POST', '/transactions/store/withdrawal', $data);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
// fake!
$repository->shouldReceive('update')->andReturn($journal);
$this->call('POST', '/transaction/update/' . $journal->id, $data);
//$this->assertSessionHas('errors','bla');
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
}

View File

@@ -1,134 +0,0 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\AccountMeta;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartAccountControllerTest
*/
class ChartAccountControllerTest 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\Chart\AccountController::all
*/
public function testAll()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$one = FactoryMuffin::create('FireflyIII\Models\Account');
$two = FactoryMuffin::create('FireflyIII\Models\Account');
$one->account_type_id = $asset->id;
$two->account_type_id = $asset->id;
$one->save();
$two->save();
$accounts = new Collection([$one, $two]);
$date = new Carbon;
$this->be($user);
// make one shared:
AccountMeta::create(
[
'account_id' => $one->id,
'name' => 'accountRole',
'data' => 'sharedAsset'
]
);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->once()->andReturn($accounts);
$this->call('GET', '/chart/account/month/' . $date->format('Y/m'));
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\AccountController::all
*/
public function testAllShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$accounts = new Collection([$account]);
$date = new Carbon;
$this->be($user);
// make it shared:
AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'accountRole',
'data' => 'sharedAsset'
]
);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getAccounts')->once()->andReturn($accounts);
$this->call('GET', '/chart/account/month/' . $date->format('Y/m') . '/shared');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\AccountController::frontpage
*/
public function testFrontpage()
{
$accounts = new Collection([FactoryMuffin::create('FireflyIII\Models\Account')]);
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getFrontpageAccounts')->andReturn($accounts);
$this->call('GET', '/chart/account/frontpage');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\AccountController::single
*/
public function testSingle()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
$this->call('GET', '/chart/account/' . $account->id);
$this->assertResponseOk();
}
}

View File

@@ -1,100 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartBillControllerTest
*/
class ChartBillControllerTest 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()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BillController::frontpage
*/
public function testFrontpage()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// set!
$bills = new Collection([FactoryMuffin::create('FireflyIII\Models\Bill'), FactoryMuffin::create('FireflyIII\Models\Bill')]);
$journals = new Collection(
[FactoryMuffin::create('FireflyIII\Models\TransactionJournal'), FactoryMuffin::create('FireflyIII\Models\TransactionJournal')]
);
$creditCards = new Collection([FactoryMuffin::create('FireflyIII\Models\Account'), FactoryMuffin::create('FireflyIII\Models\Account')]);
$ranges = [['start' => new Carbon, 'end' => new Carbon]];
// mock!
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$accounts = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
// fake!
$repository->shouldReceive('getActiveBills')->andReturn($bills);
$repository->shouldReceive('getRanges')->andReturn($ranges);
$repository->shouldReceive('getJournalsInRange')->andReturn(new Collection, $journals);
$accounts->shouldReceive('getCreditCards')->andReturn($creditCards);
$accounts->shouldReceive('getTransfersInRange')->andReturn(new Collection);
$repository->shouldReceive('createFakeBill')->andReturn($bills->first());
Steam::shouldReceive('balance')->andReturn(-10, 0);
$lastActivity = FactoryMuffin::create('FireflyIII\Models\Preference');
$lastActivity->data = microtime();
Preferences::shouldReceive('lastActivity')->andReturn($lastActivity);
$language = FactoryMuffin::create('FireflyIII\Models\Preference');
$language->data = 'en';
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($language);
$this->call('GET', '/chart/bill/frontpage');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BillController::single
*/
public function testSingle()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
// set
$journals = new Collection([FactoryMuffin::create('FireflyIII\Models\TransactionJournal')]);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
$repository->shouldReceive('getJournals')->andReturn($journals);
// fake!
$this->call('GET', '/chart/bill/' . $bill->id);
$this->assertResponseOk();
}
}

View File

@@ -1,164 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartBudgetControllerTest
*/
class ChartBudgetControllerTest 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\Chart\BudgetController::budget
*/
public function testBudget()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->be($budget->user);
$this->call('GET', '/chart/budget/' . $budget->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BudgetController::budgetLimit
*/
public function testBudgetLimit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
/** @var \FireflyIII\Models\BudgetLimit $limit */
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
/** @var \FireflyIII\Models\LimitRepetition $repetition */
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$budget->user_id = $user->id;
$limit->budget_id = $budget->id;
$limit->startdate = $start;
$repetition->budget_limit_id = $limit->id;
$repetition->startdate = $start;
$repetition->enddate = $end;
$budget->save();
$limit->save();
$repetition->save();
$this->be($user);
$this->call('GET', '/chart/budget/' . $budget->id . '/' . $repetition->id);
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BudgetController::frontpage
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testFrontpage()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$budgets = new Collection;
$limits = [];
$repetitions = [];
for ($i = 0; $i < 5; $i++) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$budgets->push($budget);
/** @var \FireflyIII\Models\BudgetLimit $limit */
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$limit->budget_id = $budget->id;
$limit->startdate = $start;
$limit->save();
$set = new Collection([$limit]);
$limits[] = $set;
/** @var \FireflyIII\Models\LimitRepetition $repetition */
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$repetition->budget_limit_id = $limit->id;
$repetition->startdate = $start;
$repetition->enddate = $end;
$repetition->save();
$set = new Collection([$repetition]);
$repetitions[] = $set;
}
// mock!
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
// fake!
$repository->shouldReceive('getBudgets')->andReturn($budgets);
$repository->shouldReceive('getBudgetLimitRepetitions')->andReturn($repetitions[0], $repetitions[1], new Collection);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(10);
$repository->shouldReceive('getWithoutBudgetSum')->andReturn(10);
$this->call('GET', '/chart/budget/frontpage');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BudgetController::year
*/
public function testYear()
{
$user = FactoryMuffin::create('FireflyIII\User');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$collection = new Collection([$budget]);
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
// fake!
$repository->shouldReceive('getBudgets')->andReturn($collection);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(0);
$this->call('GET', '/chart/budget/year/2015');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\BudgetController::year
*/
public function testYearShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/chart/budget/year/2015/shared');
$this->assertResponseOk();
}
}

View File

@@ -1,125 +0,0 @@
<?php
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartCategoryControllerTest
*/
class ChartCategoryControllerTest 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\Chart\CategoryController::all
*/
public function testAll()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$this->call('GET', '/chart/category/' . $category->id . '/all');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\CategoryController::frontpage
*/
public function testFrontpage()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make data:
$set = [
['name' => 'Something', 'sum' => 100],
['name' => 'Something Else', 'sum' => 200],
['name' => 'Something Else Entirely', 'sum' => 200]
];
// mock!
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
// fake!
$repository->shouldReceive('getCategoriesAndExpensesCorrected')->andReturn($set);
//getCategoriesAndExpensesCorrected
$this->call('GET', '/chart/category/frontpage');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\CategoryController::month
*/
public function testMonth()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$this->call('GET', '/chart/category/' . $category->id . '/month');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\CategoryController::year
*/
public function testYear()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$categories = new Collection([FactoryMuffin::create('FireflyIII\Models\Category')]);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
// fake!
$repository->shouldReceive('getCategories')->andReturn($categories);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(0);
$this->call('GET', '/chart/category/year/2015');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\CategoryController::year
*/
public function testYearShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$categories = new Collection([FactoryMuffin::create('FireflyIII\Models\Category')]);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
// fake!
$repository->shouldReceive('getCategories')->andReturn($categories);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(0);
$this->call('GET', '/chart/category/year/2015/shared');
$this->assertResponseOk();
}
}

View File

@@ -1,53 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartPiggyBankControllerTest
*/
class ChartPiggyBankControllerTest 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\Chart\PiggyBankController::history
*/
public function testHistory()
{
$piggy = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggy->account->user);
// data:
$obj = new stdClass;
$obj->sum = 100;
$obj->date = '2015-01-01';
$set = [
$obj
];
// mock!
$repository = $this->mock('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
// fake!
$repository->shouldReceive('getEventSummarySet')->andReturn($set);
$this->call('GET', '/chart/piggyBank/' . $piggy->id);
$this->assertResponseOk();
}
}

View File

@@ -1,77 +0,0 @@
<?php
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartReportControllerTest
*/
class ChartReportControllerTest 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\Chart\ReportController::yearInOut
*/
public function testYearInOut()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/chart/report/in-out/2015');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOut
*/
public function testYearInOutShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/chart/report/in-out/2015/shared');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOutSummarized
*/
public function testYearInOutSummarized()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/chart/report/in-out-sum/2015');
$this->assertResponseOk();
}
/**
* @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOutSummarized
*/
public function testYearInOutSummarizedShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->call('GET', '/chart/report/in-out-sum/2015/shared');
$this->assertResponseOk();
}
}