Reversed codeception.

This commit is contained in:
James Cole 2015-07-03 07:27:01 +02:00
parent e139664301
commit d88919474b
77 changed files with 12793 additions and 2511 deletions

View File

@ -1,21 +0,0 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql

View File

@ -39,11 +39,7 @@
"mockery/mockery": "0.9.*",
"league/factory-muffin": "~2.1",
"codeclimate/php-test-reporter": "^0.1.2",
"fzaninotto/faker": "^1.4",
"codeception/codeception": "*"
"fzaninotto/faker": "^1.4"
},
"autoload": {
"classmap": [

35
phpunit.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<!-- code coverage
<logging>
<log type="coverage-clover" target="./build/logs/clover.xml" charset="UTF-8" />
</logging>
-->
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>

40
pu.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# set testing environment
cp .env.testing .env
# test!
if [ -z "$1" ]
then
phpunit --verbose
fi
# directories to look in:
dirs=("controllers" "database" "factories" "generators" "helpers" "models" "middleware" "repositories" "support")
if [ ! -z "$1" ]
then
for i in "${dirs[@]}"
do
firstFile="./tests/$i/$1.php"
secondFile="./tests/$i/$1Test.php"
if [ -f "$firstFile" ]
then
# run it!
phpunit --verbose $firstFile
exit $?
fi
if [ -f "$secondFile" ]
then
# run it!
phpunit --verbose $secondFile
exit $?
fi
done
fi
# restore .env file
cp .env.local .env

View File

@ -33,6 +33,40 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
{
parent::setUp();
// if the database copy does not exist, call migrate.
$copy = __DIR__ . '/../storage/database/testing-copy.db';
$original = __DIR__ . '/../storage/database/testing.db';
FactoryMuffin::loadFactories(__DIR__ . '/factories');
if (!file_exists($copy)) {
touch($original);
Artisan::call('migrate');
// create EUR currency
/** @var TransactionCurrency $currency */
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$currency->code = 'EUR';
$currency->save();
copy($original, $copy);
} else {
if (file_exists($copy)) {
copy($copy, $original);
}
}
// if the database copy does exists, copy back as original.
$this->session(
[
'start' => Carbon::now()->startOfMonth(),
'end' => Carbon::now()->endOfMonth(),
'first' => Carbon::now()->startOfYear()
]
);
}
/**
@ -53,6 +87,10 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
{
parent::tearDown();
// delete copy original.
//$original = __DIR__.'/../storage/database/testing.db';
//unlink($original);
}
/**

View File

@ -1,2 +0,0 @@
<?php
// This is global bootstrap for autoloading

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,26 +0,0 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}

View File

@ -1,26 +0,0 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}

View File

@ -1,9 +0,0 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}

View File

@ -1,9 +0,0 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}

View File

@ -1,9 +0,0 @@
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}

View File

@ -1,26 +0,0 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
<?php //[STAMP] 65f4e005f3be69d169e0f598e3c24741
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
use Helper\Functional;
trait FunctionalTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
}

View File

@ -1,348 +0,0 @@
<?php //[STAMP] 8e21b279d98b0140a061bf94fd91c121
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
use Codeception\Module\Asserts;
use Helper\Unit;
trait UnitTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are equal.
*
* @param $expected
* @param $actual
* @param string $message
*
* @return mixed
* @see \Codeception\Module\Asserts::assertEquals()
*/
public function assertEquals($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not equal
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotEquals()
*/
public function assertNotEquals($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are same
*
* @param $expected
* @param $actual
* @param string $message
*
* @return mixed
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not same
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotSame()
*/
public function assertNotSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThan()
*/
public function assertGreaterThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @deprecated
* @see \Codeception\Module\Asserts::assertGreaterThen()
*/
public function assertGreaterThen($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThen', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
*/
public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @deprecated
* @see \Codeception\Module\Asserts::assertGreaterThenOrEqual()
*/
public function assertGreaterThenOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThenOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThan()
*/
public function assertLessThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThanOrEqual()
*/
public function assertLessThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack contains needle
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertContains()
*/
public function assertContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack doesn't contain needle.
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertNotContains()
*/
public function assertNotContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertRegExp()
*/
public function assertRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string not match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertNotRegExp()
*/
public function assertNotRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertEmpty()
*/
public function assertEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotEmpty()
*/
public function assertNotEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNull()
*/
public function assertNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotNull()
*/
public function assertNotNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is positive.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertTrue()
*/
public function assertTrue($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is negative.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertFalse()
*/
public function assertFalse($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file exists
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileExists()
*/
public function assertFileExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file doesn't exists
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileNotExists()
*/
public function assertFileNotExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Fails the test with message.
*
* @param $message
* @see \Codeception\Module\Asserts::fail()
*/
public function fail($message) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
}
}

View File

@ -1,12 +0,0 @@
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://localhost/myapp
- \Helper\Acceptance

View File

@ -1,2 +0,0 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

@ -0,0 +1,353 @@
<?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

@ -0,0 +1,78 @@
<?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

@ -0,0 +1,273 @@
<?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

@ -0,0 +1,435 @@
<?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

@ -0,0 +1,263 @@
<?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

@ -0,0 +1,279 @@
<?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

@ -0,0 +1,104 @@
<?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

@ -0,0 +1,159 @@
<?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

@ -0,0 +1,228 @@
<?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

@ -0,0 +1,110 @@
<?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

@ -0,0 +1,454 @@
<?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

@ -0,0 +1,121 @@
<?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

@ -0,0 +1,195 @@
<?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

@ -0,0 +1,172 @@
<?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

@ -0,0 +1,58 @@
<?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

@ -0,0 +1,296 @@
<?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

@ -0,0 +1,598 @@
<?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

@ -0,0 +1,134 @@
<?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

@ -0,0 +1,100 @@
<?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

@ -0,0 +1,164 @@
<?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

@ -0,0 +1,125 @@
<?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

@ -0,0 +1,53 @@
<?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

@ -0,0 +1,77 @@
<?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();
}
}

321
tests/factories/all.php Normal file
View File

@ -0,0 +1,321 @@
<?php
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use League\FactoryMuffin\Facade as FactoryMuffin;
if (!class_exists('RandomString')) {
/**
* Class RandomString
*/
class RandomString
{
public static $count = 0;
public static $set = [];
/**
* @param int $length
*
* @return string
*/
public static function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
while (in_array($randomString, self::$set)) {
// create another if its in the current $set:
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
}
self::$set[] = $randomString;
return $randomString;
}
}
}
FactoryMuffin::define(
'FireflyIII\Models\Role',
[
'name' => 'word',
]
);
FactoryMuffin::define(
'FireflyIII\Models\Bill',
[
'user_id' => 'factory|FireflyIII\User',
'name' => 'sentence',
'match' => function () {
$words = [];
for ($i = 0; $i < 3; $i++) {
$words[] = RandomString::generateRandomString(5);
}
return join(',', $words);
},
'amount_min' => 10,
'amount_max' => 20,
'date' => 'date',
'active' => 1,
'automatch' => 1,
'repeat_freq' => 'monthly',
'skip' => 0,
'name_encrypted' => 1,
'match_encrypted' => 1,
]
);
FactoryMuffin::define(
'FireflyIII\Models\Account',
[
'user_id' => 'factory|FireflyIII\User',
'account_type_id' => 'factory|FireflyIII\Models\AccountType',
'name' => 'word',
'active' => 'boolean',
'encrypted' => function () {
return true;
},
'virtual_balance' => 0
]
);
FactoryMuffin::define(
'FireflyIII\Models\Tag',
[
'description' => 'sentence',
'user_id' => 'factory|FireflyIII\User',
'tag' => function () {
return RandomString::generateRandomString(20);
},
'tagMode' => 'nothing',
'date' => 'date',
'latitude' => 12,
'longitude' => 13,
'zoomLevel' => 3,
]
);
FactoryMuffin::define(
'FireflyIII\Models\Budget',
[
'user_id' => 'factory|FireflyIII\User',
'name' => 'sentence',
'active' => 'boolean',
'encrypted' => 1,
]
);
FactoryMuffin::define(
'FireflyIII\Models\TransactionGroup',
[
'user_id' => 'factory|FireflyIII\User',
'relation' => 'balance',
]
);
FactoryMuffin::define(
'FireflyIII\Models\Category',
[
'user_id' => 'factory|FireflyIII\User',
'name' => 'sentence',
'encrypted' => 1,
]
);
FactoryMuffin::define(
'FireflyIII\Models\LimitRepetition',
[
'budget_limit_id' => 'factory|FireflyIII\Models\BudgetLimit',
'startdate' => 'date',
'enddate' => 'date',
'amount' => function () {
return rand(1, 100);
},
]
);
FactoryMuffin::define(
'FireflyIII\Models\BudgetLimit',
[
'budget_id' => 'factory|FireflyIII\Models\Budget',
'startdate' => 'date',
'amount' => function () {
return rand(1, 100);
},
'repeats' => 'false',
'repeat_freq' => 'monthly',
]
);
FactoryMuffin::define(
'FireflyIII\Models\Preference',
[
'name' => 'word',
'data' => 'sentence',
'user_id' => 'factory|FireflyIII\User',
]
);
FactoryMuffin::define(
'FireflyIII\Models\AccountType',
[
'type' => function () {
$types = ['Expense account', 'Revenue account', 'Asset account', 'Cash account'];
$count = DB::table('account_types')->count();
if ($count < 4) {
return $types[$count];
} else {
return RandomString::generateRandomString(10);
}
},
'editable' => 1,
]
);
FactoryMuffin::define(
'FireflyIII\Models\TransactionCurrency',
[
'code' => function () {
return RandomString::generateRandomString(3);
},
'symbol' => function () {
return RandomString::generateRandomString(8);
},
'name' => 'word'
]
);
FactoryMuffin::define(
'FireflyIII\User',
[
'email' => function () {
$first = RandomString::generateRandomString(20);
$second = RandomString::generateRandomString(20);
$domain = RandomString::generateRandomString(30);
$email = $first . '.' . $second . '@' . $domain . '.com';
return $email;
},
'password' => bcrypt('james'),
]
);
FactoryMuffin::define(
'FireflyIII\Models\Transaction',
[
'transaction_journal_id' => 'factory|FireflyIII\Models\TransactionJournal',
'amount' => function () {
return rand(1, 100);
},
'description' => 'sentence',
'account_id' => 'factory|FireflyIII\Models\Account'
]
);
FactoryMuffin::define(
'FireflyIII\Models\PiggyBank',
[
'account_id' => 'factory|FireflyIII\Models\Account',
'name' => 'sentence',
'targetamount' => function () {
return rand(1, 100);
},
'startdate' => 'date',
'targetdate' => 'date',
'remind_me' => false,
'reminder_skip' => 0,
'order' => 0,
]
);
FactoryMuffin::define(
'FireflyIII\Models\PiggyBankRepetition',
[
'piggy_bank_id' => 'factory|FireflyIII\Models\PiggyBank',
'startdate' => 'date',
'targetdate' => 'date',
'currentamount' => function () {
return rand(1, 100);
},
]
);
FactoryMuffin::define(
'FireflyIII\Models\PiggyBankEvent',
[
'piggy_bank_id' => 'factory|FireflyIII\Models\PiggyBank',
'transaction_journal_id' => 'factory|FireflyIII\Models\TransactionJournal',
'date' => 'date',
'amount' => function () {
return rand(1, 100);
},
]
);
FactoryMuffin::define(
'FireflyIII\Models\TransactionType',
[
'type' => function () {
$types = ['Withdrawal', 'Deposit', 'Transfer'];
$count = DB::table('transaction_types')->count();
if ($count < 3) {
return $types[$count];
} else {
return RandomString::generateRandomString(10);
}
}
]
);
FactoryMuffin::define(
'FireflyIII\Models\TransactionJournal',
[
'user_id' => 'factory|FireflyIII\User',
'transaction_type_id' => 'factory|FireflyIII\Models\TransactionType',
'transaction_currency_id' => 'factory|FireflyIII\Models\TransactionCurrency',
'description' => 'sentence',
'completed' => '1',
'date' => 'date',
'encrypted' => '1',
'order' => '0',
], function (TransactionJournal $object, $saved) {
if ($saved) {
$one = FactoryMuffin::create('FireflyIII\Models\Account');
$two = FactoryMuffin::create('FireflyIII\Models\Account');
Transaction::create(
[
'account_id' => $one->id,
'transaction_journal_id' => $object->id,
'amount' => 100
]
);
Transaction::create(
[
'account_id' => $two->id,
'transaction_journal_id' => $object->id,
'amount' => -100
]
);
}
}
);

View File

@ -1,11 +0,0 @@
# Codeception Test Suite Configuration
#
# Suite for functional (integration) tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional

View File

@ -1,2 +0,0 @@
<?php
// Here you can initialize variables that will be available to your tests

View File

@ -0,0 +1,114 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartJsAccountChartGeneratorTest
*/
class ChartJsAccountChartGeneratorTest extends TestCase
{
/**
* @var ChartJsAccountChartGenerator
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new ChartJsAccountChartGenerator;
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();
}
/**
* @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::frontpage
*/
public function testFrontpage()
{
// be somebody
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// create some accounts:
$accounts = new Collection;
for ($i = 0; $i < 5; $i++) {
$accounts->push(FactoryMuffin::create('FireflyIII\Models\Account'));
}
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// data for call:
$start = Carbon::createFromDate(2015, 1, 1);
$end = Carbon::createFromDate(2015, 1, 15);
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// mock Steam::balance
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
// call
$result = $this->object->frontpage($accounts, $start, $end);
$this->assertEquals($accounts->count(), $result['count']);
$this->assertCount(15, $result['labels']);
$this->assertCount($accounts->count(), $result['datasets']);
}
/**
* @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::single
*/
public function testSingle()
{
// be somebody
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// mock Steam::balance
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
// data for call:
$start = Carbon::createFromDate(2015, 1, 1);
$end = Carbon::createFromDate(2015, 1, 15);
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// call
$result = $this->object->single($account, $start, $end);
// test
$this->assertCount(15, $result['labels']);
$this->assertEquals($account->name, $result['datasets'][0]['label']);
$this->assertCount(15, $result['datasets'][0]['data']);
}
}

View File

@ -0,0 +1,100 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleBillChartGeneratorTest
*/
class ChartJsBillChartGeneratorTest extends TestCase
{
/** @var ChartJsBillChartGenerator */
protected $object;
/**
* 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->object = new ChartJsBillChartGenerator();
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator::frontpage
*/
public function testFrontpage()
{
// to test frontpage, we generate the exact fake entries
// needed:
$paid = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass();
$obj->description = 'Something';
$obj->amount = 100;
$paid->push($obj);
}
$unpaid = new Collection;
$sum = 0;
for ($i = 0; $i < 5; $i++) {
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$date = new Carbon;
$sum += (($bill->amount_max + $bill->amount_min) / 2);
$unpaid->push([$bill, $date]);
}
$data = $this->object->frontpage($paid, $unpaid);
$this->assertCount(2, $data);
$this->assertEquals($sum, $data[0]['value']);
$this->assertEquals(500, $data[1]['value']);
}
/**
* @covers FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator::single
*/
public function testSingle()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$entries = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass;
$obj->amount = 100;
$obj->date = new Carbon;
$entries->push($obj);
}
$data = $this->object->single($bill, $entries);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][1]['data']);
$this->assertEquals(100, $data['datasets'][1]['data'][0]); // see if first is equal.
}
}

View File

@ -0,0 +1,113 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartJsBudgetChartGeneratorTest
*/
class ChartJsBudgetChartGeneratorTest extends TestCase
{
/** @var ChartJsBudgetChartGenerator */
protected $object;
/**
* 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->object = new ChartJsBudgetChartGenerator();
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::budget
*/
public function testBudget()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// make a collection with some amounts in them.
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 100]);
}
$data = $this->object->budget($collection);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][0]['data']);
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
}
/**
* @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::frontpage
*/
public function testFrontpage()
{
// make a collection with some amounts in them.
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push(['Some label', 100, 200, 300]);
}
$data = $this->object->frontpage($collection);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][0]['data']);
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
$this->assertEquals(200, $data['datasets'][1]['data'][0]);
$this->assertEquals(300, $data['datasets'][2]['data'][0]);
}
/**
* @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::year
*/
public function testYear()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
$budgets = new Collection;
$entries = new Collection;
// make some budgets:
for ($i = 0; $i < 5; $i++) {
$budgets->push(FactoryMuffin::create('FireflyIII\Models\Budget'));
$entries->push([new Carbon, 100, 100, 100]);
}
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
$data = $this->object->year($budgets, $entries);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets']);
$this->assertCount(3, $data['datasets'][0]['data']);
}
}

View File

@ -0,0 +1,114 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartJsCategoryChartGeneratorTest
*/
class ChartJsCategoryChartGeneratorTest extends TestCase
{
/** @var ChartJsCategoryChartGenerator */
protected $object;
/**
* 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->object = new ChartJsCategoryChartGenerator;
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::all
*/
public function testAll()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// make a collection of stuff:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 100]);
}
$data = $this->object->all($collection);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][0]['data']);
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
}
/**
* @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::frontpage
*/
public function testFrontpage()
{
// make a collection of stuff:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push(['name' => 'Something', 'sum' => 100]);
}
$data = $this->object->frontpage($collection);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][0]['data']);
$this->assertEquals('Something', $data['labels'][0]);
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
}
/**
* @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::year
*/
public function testYear()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// make a collection of stuff:
$collection = new Collection;
$categories = new Collection;
for ($i = 0; $i < 5; $i++) {
$categories->push(FactoryMuffin::create('FireflyIII\Models\Category'));
$collection->push([new Carbon, 100, 100, 100]);
}
$data = $this->object->year($categories, $collection);
$this->assertCount(5, $data['labels']);
$this->assertEquals($categories->first()->name, $data['labels'][0]);
$this->assertCount(3, $data['datasets'][0]['data']);
}
}

View File

@ -0,0 +1,66 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartJsPiggyBankChartGeneratorTest
*/
class ChartJsPiggyBankChartGeneratorTest extends TestCase
{
/** @var ChartJsPiggyBankChartGenerator */
protected $object;
/**
* 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->object = new ChartJsPiggyBankChartGenerator;
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator::history
*/
public function testHistory()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// create a set
$set = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass;
$obj->date = new Carbon;
$obj->sum = 100;
$set->push($obj);
}
$data = $this->object->history($set);
$this->assertCount(5, $data['labels']);
$this->assertCount(5, $data['datasets'][0]['data']);
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
$this->assertEquals(500, $data['datasets'][0]['data'][4]);
}
}

View File

@ -0,0 +1,80 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ChartJsReportChartGeneratorTest
*/
class ChartJsReportChartGeneratorTest extends TestCase
{
/** @var ChartJsReportChartGenerator */
protected $object;
/**
* 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->object = new ChartJsReportChartGenerator;
}
/**
* 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();
}
/**
* FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator::yearInOut
*/
public function testYearInOut()
{
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'en';
$preference->save();
// mock language preference:
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
// make set:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 200, 100]);
}
$data = $this->object->yearInOut($collection);
$this->assertEquals(200, $data['datasets'][0]['data'][0]);
$this->assertEquals(100, $data['datasets'][1]['data'][0]);
$this->assertCount(5, $data['labels']);
}
/**
* FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator::yearInOutSummarized
*/
public function testYearInOutSummarized()
{
// make set:
$income = 2400;
$expense = 1200;
$data = $this->object->yearInOutSummarized($income, $expense, 12);
$this->assertEquals(200, $data['datasets'][0]['data'][1]);
$this->assertEquals(100, $data['datasets'][1]['data'][1]);
}
}

View File

@ -0,0 +1,120 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator;
use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleAccountChartGeneratorTest
*/
class GoogleAccountChartGeneratorTest extends TestCase
{
/** @var GoogleAccountChartGenerator */
protected $object;
/**
* 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->object = new GoogleAccountChartGenerator;
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator::all
*/
public function testAll()
{
// be somebody
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// create some accounts:
$accounts = new Collection;
for ($i = 0; $i < 5; $i++) {
$accounts->push(FactoryMuffin::create('FireflyIII\Models\Account'));
}
// data for call:
$start = Carbon::createFromDate(2015, 1, 1);
$end = Carbon::createFromDate(2015, 1, 15);
// mock Steam::balance
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
$data = $this->object->all($accounts, $start, $end);
$this->assertCount(11, $data['cols']); // accounts * 2 + date.
// fifteen days,
$this->assertCount(16, $data['rows']); // 15 + 1?
}
/**
* @covers FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator::frontpage
*/
public function testFrontpage()
{
// be somebody
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// create some accounts:
$accounts = new Collection;
for ($i = 0; $i < 5; $i++) {
$accounts->push(FactoryMuffin::create('FireflyIII\Models\Account'));
}
// data for call:
$start = Carbon::createFromDate(2015, 1, 1);
$end = Carbon::createFromDate(2015, 1, 15);
// mock Steam::balance
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
$data = $this->object->frontpage($accounts, $start, $end);
$this->assertCount(11, $data['cols']); // accounts * 2 + date.
// fifteen days,
$this->assertCount(16, $data['rows']); // 15 + 1?
}
/**
* @covers FireflyIII\Generator\Chart\Account\GoogleAccountChartGenerator::single
*/
public function testSingle()
{
// be somebody
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// data for call:
$start = Carbon::createFromDate(2015, 1, 1);
$end = Carbon::createFromDate(2015, 1, 15);
// mock Steam::balance
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
$data = $this->object->single($account, $start, $end);
$this->assertCount(3, $data['cols']); // account, date, certainty
// fifteen days,
$this->assertCount(15, $data['rows']); // 15 days
}
}

View File

@ -0,0 +1,90 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Bill\GoogleBillChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleBillChartGeneratorTest
*/
class GoogleBillChartGeneratorTest extends TestCase
{
/** @var GoogleBillChartGenerator */
protected $object;
/**
* 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->object = new GoogleBillChartGenerator;
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Bill\GoogleBillChartGenerator::frontpage
*/
public function testFrontpage()
{
// to test frontpage, we generate the exact fake entries
// needed:
$paid = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass();
$obj->description = 'Something';
$obj->amount = 100;
$paid->push($obj);
}
$unpaid = new Collection;
$sum = 0;
for ($i = 0; $i < 5; $i++) {
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$date = new Carbon;
$sum += (($bill->amount_max + $bill->amount_min) / 2);
$unpaid->push([$bill, $date]);
}
$data = $this->object->frontpage($paid, $unpaid);
$this->assertCount(2, $data['cols']);
$this->assertCount(2, $data['rows']); // two rows, two columns.
}
/**
* @covers FireflyIII\Generator\Chart\Bill\GoogleBillChartGenerator::single
*/
public function testSingle()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$entries = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass;
$obj->amount = 100;
$obj->date = new Carbon;
$entries->push($obj);
}
$data = $this->object->single($bill, $entries);
$this->assertCount(5, $data['rows']);
$this->assertCount(4, $data['cols']);
$this->assertEquals(100, $data['rows'][0]['c'][3]['v']);
}
}

View File

@ -0,0 +1,99 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleBudgetChartGeneratorTest
*/
class GoogleBudgetChartGeneratorTest extends TestCase
{
/** @var GoogleBudgetChartGenerator */
protected $object;
/**
* 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->object = new GoogleBudgetChartGenerator();
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator::budget
*/
public function testBudget()
{
// make a collection with some amounts in them.
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 100]);
}
$data = $this->object->budget($collection);
$this->assertCount(5, $data['rows']);
$this->assertCount(2, $data['cols']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
}
/**
* @covers FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator::frontpage
*/
public function testFrontpage()
{
// make a collection with some amounts in them.
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push(['Some label', 100, 200, 300]);
}
$data = $this->object->frontpage($collection);
$this->assertCount(5, $data['rows']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
$this->assertEquals(200, $data['rows'][0]['c'][2]['v']);
$this->assertEquals(300, $data['rows'][0]['c'][3]['v']);
}
/**
* @covers FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator::year
*/
public function testYear()
{
$budgets = new Collection;
$entries = new Collection;
// make some budgets:
for ($i = 0; $i < 5; $i++) {
$budgets->push(FactoryMuffin::create('FireflyIII\Models\Budget'));
$entries->push([new Carbon, 100, 100, 100]);
}
$data = $this->object->year($budgets, $entries);
$this->assertCount(5, $data['rows']);
$this->assertCount(6, $data['cols']);
}
}

View File

@ -0,0 +1,116 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleCategoryChartGeneratorTest
*/
class GoogleCategoryChartGeneratorTest extends TestCase
{
/** @var GoogleCategoryChartGenerator */
protected $object;
/**
* 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->object = new GoogleCategoryChartGenerator();
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator::all
*/
public function testAll()
{
// make a collection of stuff:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 100]);
}
$data = $this->object->all($collection);
$this->assertCount(5, $data['rows']);
$this->assertCount(2, $data['cols']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
}
/**
* @covers FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator::frontpage
*/
public function testFrontpage()
{
// make a collection of stuff:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push(['name' => 'Something', 'sum' => 100]);
}
$data = $this->object->frontpage($collection);
$this->assertCount(5, $data['rows']);
$this->assertCount(2, $data['cols']);
$this->assertEquals('Something', $data['rows'][0]['c'][0]['v']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
}
/**
* @covers FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator::month
*/
public function testMonth()
{
// make a collection of stuff:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 100]);
}
$data = $this->object->month($collection);
$this->assertCount(5, $data['rows']);
$this->assertCount(2, $data['cols']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
}
/**
* @covers FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator::year
*/
public function testYear()
{
// make a collection of stuff:
$collection = new Collection;
$categories = new Collection;
for ($i = 0; $i < 5; $i++) {
$categories->push(FactoryMuffin::create('FireflyIII\Models\Category'));
$collection->push([new Carbon, 100, 100, 100]);
}
$data = $this->object->year($categories, $collection);
$this->assertCount(5, $data['rows']);
$this->assertEquals($categories->first()->name, $data['cols'][1]['label']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
}
}

View File

@ -0,0 +1,58 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator;
use Illuminate\Support\Collection;
/**
* Class GooglePiggyBankChartGeneratorTest
*/
class GooglePiggyBankChartGeneratorTest extends TestCase
{
/** @var GooglePiggyBankChartGenerator */
protected $object;
/**
* 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->object = new GooglePiggyBankChartGenerator();
}
/**
* 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();
}
/**
* @covers FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator::history
*/
public function testHistory()
{
// create a set
$set = new Collection;
for ($i = 0; $i < 5; $i++) {
$obj = new stdClass;
$obj->date = new Carbon;
$obj->sum = 100;
$set->push($obj);
}
$data = $this->object->history($set);
$this->assertCount(5, $data['rows']);
$this->assertCount(2, $data['cols']);
$this->assertEquals(100, $data['rows'][0]['c'][1]['v']);
$this->assertEquals(500, $data['rows'][4]['c'][1]['v']);
}
}

View File

@ -0,0 +1,69 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator;
use Illuminate\Support\Collection;
/**
* Class GoogleReportChartGeneratorTest
*/
class GoogleReportChartGeneratorTest extends TestCase
{
/** @var GoogleReportChartGenerator */
protected $object;
/**
* 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->object = new GoogleReportChartGenerator;
}
/**
* 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();
}
/**
* FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator::yearInOut
*/
public function testYearInOut()
{
// make set:
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push([new Carbon, 200, 100]);
}
$data = $this->object->yearInOut($collection);
$this->assertCount(5, $data['rows']);
$this->assertEquals(200, $data['rows'][0]['c'][1]['v']);
$this->assertEquals(100, $data['rows'][0]['c'][2]['v']);
}
/**
* FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator::yearInOutSummarized
*/
public function testYearInOutSummarized()
{
// make set:
$income = 2400;
$expense = 1200;
$data = $this->object->yearInOutSummarized($income, $expense, 12);
$this->assertEquals(200, $data['rows'][1]['c'][1]['v']);
$this->assertEquals(100, $data['rows'][1]['c'][2]['v']);
}
}

View File

@ -0,0 +1,139 @@
<?php
use FireflyIII\Events\JournalCreated;
use FireflyIII\Handlers\Events\ConnectJournalToPiggyBank;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\Transaction;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ConnectJournalToPiggyBankTest
*/
class ConnectJournalToPiggyBankTest extends TestCase
{
//event(new JournalCreated($journal, intval($request->get('piggy_bank_id'))));
/**
* 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();
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
*/
public function testNoRepetition()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var \FireflyIII\Models\PiggyBank $piggyBank */
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->user_id = $user->id;
$account2->user_id = $user->id;
$piggyBank->account_id = $account1->id;
$account1->save();
$account2->save();
$piggyBank->save();
// because the event handler responds to this piggy bank, we must remove
// the piggy bank repetition:
/** @var \FireflyIII\Models\PiggyBankRepetition $rep */
foreach ($piggyBank->piggyBankRepetitions()->get() as $rep) {
$rep->forceDelete();
}
$event = new JournalCreated($journal, $piggyBank->id);
$class = new ConnectJournalToPiggyBank();
$result = $class->handle($event);
$this->assertFalse($result);
}
/**
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
*/
public function testNoSuchPiggy()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$event = new JournalCreated($journal, 1);
$class = new ConnectJournalToPiggyBank();
$result = $class->handle($event);
$this->assertFalse($result);
}
/**
* @covers FireflyIII\Handlers\Events\ConnectJournalToPiggyBank::handle
*/
public function testWithRepetition()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$journal->user_id = $user->id;
$journal->save();
// create piggy bank event to continue handler:
$start = clone $journal->date;
$end = clone $journal->date;
$start->subDay();
$end->addDay();
PiggyBankRepetition::create(
[
'piggy_bank_id' => $piggyBank->id,
'startdate' => $start->format('Y-m-d'),
'targetdate' => $end->format('Y-m-d'),
'currentamount' => 0,
]
);
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
if ($transaction->amount < 0) {
$piggyBank->account_id = $transaction->account_id;
$account = $transaction->account;
$account->user_id = $user->id;
$account->save();
$piggyBank->account_id = $account->id;
$piggyBank->save();
}
}
$event = new JournalCreated($journal, $piggyBank->id);
$class = new ConnectJournalToPiggyBank();
$result = $class->handle($event);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,329 @@
<?php
use Carbon\Carbon;
use FireflyIII\Helpers\Collection\Account as AccountCollection;
use FireflyIII\Helpers\Report\ReportHelper;
use FireflyIII\Models\AccountMeta;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ReportHelperTest
*/
class ReportHelperTest extends TestCase
{
/**
* @var ReportHelper
*/
protected $object;
/**
* 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');
$query = new \FireflyIII\Helpers\Report\ReportQuery();
$this->object = new ReportHelper($query);
}
/**
* 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\Helpers\Report\ReportHelper::getAccountReport
*/
public function testGetAccountReport()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$cash = FactoryMuffin::create('FireflyIII\Models\AccountType');
$user = FactoryMuffin::create('FireflyIII\User');
for ($i = 0; $i < 5; $i++) {
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->user_id = $user->id;
$account->account_type_id = $asset->id;
$account->save();
}
$cashAccount = FactoryMuffin::create('FireflyIII\Models\Account');
$cashAccount->user_id = $user->id;
$cashAccount->account_type_id = $cash->id;
$cashAccount->save();
$this->be($user);
/** @var AccountCollection $object */
$object = $this->object->getAccountReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false);
$this->assertCount(5, $object->getAccounts());
$this->assertEquals(0, $object->getDifference());
$this->assertEquals(0, $object->getEnd());
$this->assertEquals(0, $object->getStart());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getBalanceReport
*/
public function testGetBalanceReport()
{
// factory!
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$user = FactoryMuffin::create('FireflyIII\User');
$rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
for ($i = 0; $i < 5; $i++) {
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->user_id = $user->id;
$account->account_type_id = $asset->id;
$account->save();
}
$set = new Collection;
for ($i = 0; $i < 5; $i++) {
$set->push(FactoryMuffin::create('FireflyIII\Models\Budget'));
}
$this->be($user);
// mock!
$budgetRepos = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$tagRepos = $this->mock('FireflyIII\Repositories\Tag\TagRepositoryInterface');
// fake!
$budgetRepos->shouldReceive('getBudgets')->andReturn($set);
$budgetRepos->shouldReceive('getCurrentRepetition')->andReturn($rep);
$tagRepos->shouldReceive('coveredByBalancingActs')->andReturn(0);
// test!
$object = $this->object->getBalanceReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false);
$this->assertCount(8, $object->getBalanceLines());
$this->assertCount(5, $object->getBalanceHeader()->getAccounts());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getBillReport
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetBillReport()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// factory!
$set = new Collection;
$journals = new Collection;
FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\Models\Account');
for ($i = 0; $i < 5; $i++) {
$set->push(FactoryMuffin::create('FireflyIII\Models\Bill'));
}
for ($i = 0; $i < 5; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journals->push($journal);
}
// mock!
$repository = $this->mock('FireflyIII\Repositories\Bill\BillRepositoryInterface');
// fake!
$repository->shouldReceive('getBills')->andReturn($set);
$repository->shouldReceive('getJournalsInRange')->withAnyArgs()->andReturn(new Collection, $journals);
// test!
$object = $this->object->getBillReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false);
$this->assertCount(5, $object->getBills());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getBudgetReport
*/
public function testGetBudgetReport()
{
// factory!
$user = FactoryMuffin::create('FireflyIII\User');
$set = new Collection;
$rep1 = new Collection;
$rep2 = new Collection;
for ($i = 0; $i < 5; $i++) {
$set->push(FactoryMuffin::create('FireflyIII\Models\Budget'));
}
for ($i = 0; $i < 5; $i++) {
$rep1->push(FactoryMuffin::create('FireflyIII\Models\LimitRepetition'));
}
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
// fake!
$repository->shouldReceive('getBudgets')->andReturn($set);
$repository->shouldReceive('getBudgetLimitRepetitions')->andReturn($rep1, $rep2);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(rand(0, 100));
$repository->shouldReceive('getWithoutBudgetSum')->andReturn(rand(0, 100));
// test!
$object = $this->object->getBudgetReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false);
$this->assertCount(10, $object->getBudgetLines());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getCategoryReport
*/
public function testGetCategoryReport()
{
// factory!
$user = FactoryMuffin::create('FireflyIII\User');
$set = new Collection;
for ($i = 0; $i < 5; $i++) {
$set->push(FactoryMuffin::create('FireflyIII\Models\Category'));
}
$this->be($user);
// mock!
$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
// fake!
$repository->shouldReceive('getCategories')->andReturn($set);
$repository->shouldReceive('spentInPeriodCorrected')->andReturn(rand(1, 100));
// test!
$object = $this->object->getCategoryReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), false);
$this->assertCount(5, $object->getCategories());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getExpenseReport
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetExpenseReport()
{
// factory!
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
// create five journals in this month for the report:
$date = Carbon::now()->startOfMonth()->addDay();
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$left = FactoryMuffin::create('FireflyIII\Models\Account');
$right = FactoryMuffin::create('FireflyIII\Models\Account');
$left->account_type_id = $asset->id;
$right->account_type_id = $asset->id;
$right->save();
$left->save();
// save meta for account:
AccountMeta::create(
[
'account_id' => $left->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
AccountMeta::create(
[
'account_id' => $right->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
for ($i = 0; $i < 5; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->transaction_type_id = $type->id;
$journal->user_id = $user->id;
$journal->save();
}
// test!
$object = $this->object->getExpenseReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
$this->assertCount(5, $object->getExpenses());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::getIncomeReport
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetIncomeReport()
{
// factory!
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
// create five journals in this month for the report:
$date = Carbon::now()->startOfMonth()->addDay();
$left = FactoryMuffin::create('FireflyIII\Models\Account');
$right = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$left->account_type_id = $asset->id;
$right->account_type_id = $asset->id;
// save meta for account:
AccountMeta::create(
[
'account_id' => $left->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
AccountMeta::create(
[
'account_id' => $right->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
$right->save();
$left->save();
for ($i = 0; $i < 5; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->transaction_type_id = $type->id;
$journal->user_id = $user->id;
$journal->save();
}
// test!
$object = $this->object->getIncomeReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
$this->assertCount(5, $object->getIncomes());
}
/**
* @covers FireflyIII\Helpers\Report\ReportHelper::listOfMonths
*/
public function testListOfMonths()
{
// start of year up until now
$date = new Carbon('2015-01-01');
$now = new Carbon;
$diff = $now->diffInMonths($date) + 1; // the month itself.
$result = $this->object->listOfMonths($date);
$this->assertCount($diff, $result[2015]);
}
}

View File

@ -0,0 +1,397 @@
<?php
use Carbon\Carbon;
use FireflyIII\Helpers\Report\ReportQuery;
use FireflyIII\Models\AccountMeta;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ReportQueryTest
*/
class ReportQueryTest extends TestCase
{
/**
* @var ReportQuery
*/
protected $object;
/**
* 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->object = new ReportQuery;
}
/**
* 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\Helpers\Report\ReportQuery::expenseInPeriodCorrected
* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExpenseInPeriodCorrected()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$date = new Carbon('2015-01-12');
for ($i = 0; $i < 10; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->user_id = $user->id;
$journal->transaction_type_id = $type->id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->account_type_id = $asset->id;
$account1->user_id = $user->id;
$account2->account_type_id = $expense->id;
$account2->user_id = $user->id;
$account1->save();
$account2->save();
AccountMeta::create(
[
'account_id' => $account1->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
$amount = 100;
if ($i == 8) {
$amount = 0; // at least one "empty" journal.
}
// update both transactions
$journal->transactions[0]->account_id = $account1->id;
$journal->transactions[0]->amount = $amount * -1;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $account2->id;
$journal->transactions[1]->amount = $amount;
$journal->transactions[1]->save();
}
$this->be($user);
$set = $this->object->expenseInPeriodCorrected($start, $end, false);
$this->assertCount(9, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::expenseInPeriodCorrected
* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExpenseInPeriodCorrectedShared()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$date = new Carbon('2015-01-12');
for ($i = 0; $i < 10; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->user_id = $user->id;
$journal->transaction_type_id = $type->id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->account_type_id = $asset->id;
$account1->user_id = $user->id;
$account2->account_type_id = $expense->id;
$account2->user_id = $user->id;
$account1->save();
$account2->save();
AccountMeta::create(
[
'account_id' => $account1->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
$amount = 100;
if ($i == 8) {
$amount = 0; // at least one "empty" journal.
}
// update both transactions
$journal->transactions[0]->account_id = $account1->id;
$journal->transactions[0]->amount = $amount * -1;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $account2->id;
$journal->transactions[1]->amount = $amount;
$journal->transactions[1]->save();
}
$this->be($user);
$set = $this->object->expenseInPeriodCorrected($start, $end, true);
$this->assertCount(9, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts
*/
public function testGetAllAccounts()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
for ($i = 0; $i < 10; $i++) {
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->account_type_id = $asset->id;
$account->user_id = $user->id;
$account->save();
}
Steam::shouldReceive('balance')->andReturn(0);
$this->be($user);
$set = $this->object->getAllAccounts($start, $end, false);
$this->assertCount(10, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts
*/
public function testGetAllAccountsShared()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
for ($i = 0; $i < 10; $i++) {
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->account_type_id = $asset->id;
$account->user_id = $user->id;
$account->save();
}
Steam::shouldReceive('balance')->andReturn(0);
$this->be($user);
$set = $this->object->getAllAccounts($start, $end, true);
$this->assertCount(10, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected
* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testIncomeInPeriodCorrected()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$date = new Carbon('2015-01-12');
for ($i = 0; $i < 10; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->user_id = $user->id;
$journal->transaction_type_id = $type->id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->account_type_id = $asset->id;
$account1->user_id = $user->id;
$account2->account_type_id = $expense->id;
$account2->user_id = $user->id;
$account1->save();
$account2->save();
AccountMeta::create(
[
'account_id' => $account1->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
$amount = 100;
if ($i == 8) {
$amount = 0; // at least one "empty" journal.
}
// update both transactions
$journal->transactions[0]->account_id = $account1->id;
$journal->transactions[0]->amount = $amount;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $account2->id;
$journal->transactions[1]->amount = $amount * -1;
$journal->transactions[1]->save();
}
$this->be($user);
$set = $this->object->incomeInPeriodCorrected($start, $end, false);
$this->assertCount(9, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected
* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testIncomeInPeriodCorrectedShared()
{
$start = new Carbon('2015-01-01');
$end = new Carbon('2015-02-01');
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$expense = FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$date = new Carbon('2015-01-12');
for ($i = 0; $i < 10; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->user_id = $user->id;
$journal->transaction_type_id = $type->id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->account_type_id = $asset->id;
$account1->user_id = $user->id;
$account2->account_type_id = $expense->id;
$account2->user_id = $user->id;
$account1->save();
$account2->save();
AccountMeta::create(
[
'account_id' => $account1->id,
'name' => 'accountRole',
'data' => 'defaultAsset'
]
);
$amount = 100;
if ($i == 8) {
$amount = 0; // at least one "empty" journal.
}
// update both transactions
$journal->transactions[0]->account_id = $account1->id;
$journal->transactions[0]->amount = $amount * -1;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $account2->id;
$journal->transactions[1]->amount = $amount;
$journal->transactions[1]->save();
}
$this->be($user);
$set = $this->object->incomeInPeriodCorrected($start, $end, true);
$this->assertCount(9, $set);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::spentInBudgetCorrected
*/
public function testSpentInBudgetCorrected()
{
$user = FactoryMuffin::create('FireflyIII\User');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->user_id = $user->id;
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget->user_id = $user->id;
$account->save();
$budget->save();
$this->be($user);
$result = $this->object->spentInBudgetCorrected($account, $budget, new Carbon, new Carbon);
$this->assertEquals(0, $result);
}
/**
* @covers FireflyIII\Helpers\Report\ReportQuery::spentNoBudget
*/
public function testSpentNoBudget()
{
$user = FactoryMuffin::create('FireflyIII\User');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->user_id = $user->id;
$account->save();
$this->be($user);
$result = $this->object->spentNoBudget($account, new Carbon, new Carbon);
$this->assertEquals(0, $result);
}
}

View File

@ -0,0 +1,162 @@
<?php
use FireflyIII\Models\Account;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class AccountModelTest
*/
class AccountModelTest 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\Models\Account::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncrypted()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// search for account with the same properties:
$search = [
'name' => $account->name,
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id
];
$result = Account::firstOrCreateEncrypted($search);
// should be the same account:
$this->assertEquals($account->id, $result->id);
}
/**
* @covers FireflyIII\Models\Account::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncryptedNew()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\User');
// search for account with the same properties:
$search = [
'name' => 'Some new account',
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id,
'active' => 1,
];
$result = Account::firstOrCreateEncrypted($search);
// should not be the same account:
$this->assertNotEquals($account->id, $result->id);
}
/**
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
*/
public function testFirstOrNullEncrypted()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// search for account with the same properties:
$search = [
'name' => $account->name,
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id
];
$result = Account::firstOrNullEncrypted($search);
// should be the same account:
$this->assertEquals($account->id, $result->id);
}
/**
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
*/
public function testFirstOrNullEncryptedNew()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\User');
// search for account with the same properties:
$search = [
'name' => 'Some new account',
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id,
'active' => 1,
];
$result = Account::firstOrNullEncrypted($search);
// should not be the same account:
$this->assertNull($result);
}
/**
* @covers FireflyIII\Models\Account::getNameForEditformAttribute
*/
public function testGetNameForEditformAttribute()
{
// normal name is normal
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->assertEquals($account->name, $account->getNameForEditformAttribute());
}
/**
* @covers FireflyIII\Models\Account::getNameForEditformAttribute
*/
public function testGetNameForEditformAttributeCash()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
// cash name is empty
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->assertEquals('', $account->getNameForEditformAttribute());
}
}

View File

@ -0,0 +1,76 @@
<?php
use FireflyIII\Models\Category;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class CategoryModelTest
*/
class CategoryModelTest 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\Models\Category::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncrypted()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$search = [
'name' => $category->name,
'user_id' => $category->user_id
];
$result = Category::firstOrCreateEncrypted($search);
$this->assertEquals($result->id, $category->id);
}
/**
* @covers FireflyIII\Models\Category::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncryptedNew()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$search = [
'name' => 'Some category name',
'user_id' => $category->user_id
];
$result = Category::firstOrCreateEncrypted($search);
$this->assertNotEquals($result->id, $category->id);
}
}

View File

@ -0,0 +1,95 @@
<?php
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class TagModelTest
*/
class TagModelTest 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\Models\Tag::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncrypted()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$search = [
'tagMode' => 'something',
'tag' => $tag->tag,
'user_id' => $tag->user_id,
];
$result = Tag::firstOrCreateEncrypted($search);
$this->assertEquals($tag->id, $result->id);
}
/**
* @covers FireflyIII\Models\Tag::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncryptedNew()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$search = [
'tagMode' => 'something',
'tag' => 'Something else',
'user_id' => $tag->user_id,
];
$result = Tag::firstOrCreateEncrypted($search);
$this->assertNotEquals($tag->id, $result->id);
}
/**
* @covers FireflyIII\Models\Tag::save
*/
public function testSave()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
// connect some transaction journals to the tag:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->tags()->save($tag);
$tag->save();
$journal = TransactionJournal::find($journal->id);
$this->assertEquals(1, $journal->tag_count);
}
}

View File

@ -0,0 +1,636 @@
<?php
use FireflyIII\Models\TransactionJournal;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class TransactionJournalModelTest
* @SuppressWarnings(PHPMD.TooManyMethods)
*/
class TransactionJournalModelTest 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\Models\TransactionJournal::getActualAmountAttribute
*/
public function testGetActualAmountAttribute()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transactions[0]->amount = '123.45';
$journal->transactions[0]->save();
$journal->transactions[1]->amount = '-123.45';
$journal->transactions[1]->save();
$amount = $journal->actual_amount;
$this->assertEquals('123.45', $amount);
}
/**
* Journal has one tag.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::save
* @covers FireflyIII\Models\TransactionJournal::amountByTags
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetAmountAttributeAdvancePayment()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make types:
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
// make tag
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'advancePayment';
$tag->save();
// make withdrawal
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
// make deposit
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$deposit->transaction_type_id = $depositType->id;
$deposit->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
// transactions are already in place, update them:
$withdrawal->transactions[0]->account_id = $asset->id;
$withdrawal->transactions[0]->amount = -300;
$withdrawal->transactions[0]->save();
$withdrawal->transactions[1]->account_id = $expense->id;
$withdrawal->transactions[1]->amount = 300;
$withdrawal->transactions[1]->save();
$deposit->transactions[0]->account_id = $revenue->id;
$deposit->transactions[0]->amount = -89.88;
$deposit->transactions[0]->save();
$deposit->transactions[1]->account_id = $asset->id;
$deposit->transactions[1]->amount = 89.88;
$deposit->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
$tag->transactionJournals()->save($deposit);
$withdrawal->save();
$deposit->save();
$withdrawal = TransactionJournal::find($withdrawal->id);
$deposit = TransactionJournal::find($deposit->id);
// amount should be 210.12:
$this->assertEquals('210.12', $withdrawal->amount);
$this->assertEquals('0', $deposit->amount);
}
/**
* Journal has one tag.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetAmountAttributeBalancingAct()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// make types:
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
// make a tag
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'balancingAct';
$tag->save();
// make a withdrawal and a transfer
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$transfer->transaction_type_id = $transferType->id;
$transfer->save();
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
$tag->transactionJournals()->save($transfer);
// make accounts:
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$revenue->account_type_id = $asset->account_type_id;
$revenue->save();
// transactions are already in place, update them:
$withdrawal->transactions[0]->account_id = $asset->id;
$withdrawal->transactions[0]->amount = -123.45;
$withdrawal->transactions[0]->save();
$withdrawal->transactions[1]->account_id = $expense->id;
$withdrawal->transactions[1]->amount = 123.45;
$withdrawal->transactions[1]->save();
$transfer->transactions[0]->account_id = $revenue->id;
$transfer->transactions[0]->amount = -123.45;
$transfer->transactions[0]->save();
$transfer->transactions[1]->account_id = $asset->id;
$transfer->transactions[1]->amount = 123.45;
$transfer->transactions[1]->save();
$withdrawal->save();
$withdrawal = TransactionJournal::find($withdrawal->id);
$amount = $withdrawal->amount;
$this->assertEquals('0', $amount);
}
/**
* Journal has no tags.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeNoTags()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transactions[0]->amount = 123.45;
$journal->transactions[0]->save();
$journal->transactions[1]->amount = -123.45;
$journal->transactions[1]->save();
$amount = $journal->amount;
$this->assertEquals('123.45', $amount);
}
/**
*
* Journal has one tag.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeTag()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// has a normal tag, but nothing special.
// make tag
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->save();
// make withdrawal
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$withdrawal->transactions[0]->amount = -300;
$withdrawal->transactions[0]->account_id = $asset->id;
$withdrawal->transactions[0]->save();
$withdrawal->transactions[1]->amount = 300;
$withdrawal->transactions[1]->account_id = $expense->id;
$withdrawal->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
$withdrawal->save();
$withdrawal = TransactionJournal::find($withdrawal->id);
$this->assertEquals('300', $withdrawal->amount);
}
/**
* Journal has multiple tags, withdrawal. All default tag.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeTags()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// has two normal tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->save();
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag2->tagMode = 'nothing';
$tag2->save();
// make withdrawal
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$withdrawal->transactions[0]->amount = -300;
$withdrawal->transactions[0]->account_id = $asset->id;
$withdrawal->transactions[0]->save();
$withdrawal->transactions[1]->amount = 300;
$withdrawal->transactions[1]->account_id = $expense->id;
$withdrawal->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
$tag2->transactionJournals()->save($withdrawal);
// grab withdrawal again to update tag count:
$withdrawal->save();
$withdrawal = TransactionJournal::find($withdrawal->id);
$this->assertEquals('300', $withdrawal->amount);
}
/**
* Multiple tags, transfer, and one is a balancing act
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeTagsTransfer()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// has two normal tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'balancingAct';
$tag->save();
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag2->tagMode = 'nothing';
$tag2->save();
// make withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$transfer->transaction_type_id = $transferType->id;
$transfer->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$transfer->transactions[0]->amount = -300;
$transfer->transactions[0]->account_id = $asset->id;
$transfer->transactions[0]->save();
$transfer->transactions[1]->amount = 300;
$transfer->transactions[1]->account_id = $expense->id;
$transfer->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($transfer);
$tag2->transactionJournals()->save($transfer);
$transfer->save();
$transfer = TransactionJournal::find($transfer->id);
$this->assertEquals('300', $transfer->amount);
}
/**
* Multiple tags, transfer, and one is a advance payment.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeTagsTransferAdvance()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// has two normal tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'advancePayment';
$tag->save();
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag2->tagMode = 'nothing';
$tag2->save();
// make withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transferType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$transfer->transaction_type_id = $transferType->id;
$transfer->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$transfer->transactions[0]->amount = -300;
$transfer->transactions[0]->account_id = $asset->id;
$transfer->transactions[0]->save();
$transfer->transactions[1]->amount = 300;
$transfer->transactions[1]->account_id = $expense->id;
$transfer->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($transfer);
$tag2->transactionJournals()->save($transfer);
$transfer->save();
$transfer = TransactionJournal::find($transfer->id);
$this->assertEquals('300', $transfer->amount);
}
/**
* Multiple tags, withdrawal, and one is a balancingAct.
*
* @covers FireflyIII\Models\TransactionJournal::getAmountAttribute
* @covers FireflyIII\Models\TransactionJournal::amountByTag
* @covers FireflyIII\Models\TransactionJournal::amountByTags
*/
public function testGetAmountAttributeTagsWithdrawalAdvance()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// has two normal tags:
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'balancingAct';
$tag->save();
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag2->tagMode = 'nothing';
$tag2->save();
// make withdrawal
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$withdrawal->transaction_type_id = $withdrawalType->id;
$withdrawal->save();
// make accounts
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$withdrawal->transactions[0]->amount = -300;
$withdrawal->transactions[0]->account_id = $asset->id;
$withdrawal->transactions[0]->save();
$withdrawal->transactions[1]->amount = 300;
$withdrawal->transactions[1]->account_id = $expense->id;
$withdrawal->transactions[1]->save();
// connect to tag:
$tag->transactionJournals()->save($withdrawal);
$tag2->transactionJournals()->save($withdrawal);
$withdrawal->save();
$withdrawal = TransactionJournal::find($withdrawal->id);
$this->assertEquals('300', $withdrawal->amount);
}
/**
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
*/
public function testGetCorrectAmountAttribute()
{
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
// make accounts
FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
// make withdrawal
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $withdrawal->id;
$journal->save();
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->amount = 300;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $revenue->id;
$journal->transactions[1]->amount = -300;
$journal->transactions[1]->save();
// get asset account:
$result = $journal->correct_amount;
$this->assertEquals(-300, $result);
}
/**
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
*/
public function testGetCorrectAmountAttributeDeposit()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
// make accounts
FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
// make withdrawal
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $deposit->id;
$journal->save();
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->amount = 300;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $revenue->id;
$journal->transactions[1]->amount = -300;
$journal->transactions[1]->save();
// get asset account:
$result = $journal->correct_amount;
$this->assertEquals(300, $result);
}
/**
* @covers FireflyIII\Models\TransactionJournal::getCorrectAmountAttribute
*/
public function testGetCorrectAmountAttributeTransfer()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
// make accounts
FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
// make withdrawal
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $transfer->id;
$journal->save();
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->amount = 300;
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $revenue->id;
$journal->transactions[1]->amount = -300;
$journal->transactions[1]->save();
// get asset account:
$result = $journal->correct_amount;
$this->assertEquals('300', $result);
}
/**
* @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute
*/
public function testGetDestinationAccountAttribute()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$deposit->transaction_type_id = $depositType->id;
$deposit->save();
// make accounts
FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$deposit->transactions[0]->account_id = $asset->id;
$deposit->transactions[0]->amount = 300;
$deposit->transactions[0]->save();
$deposit->transactions[1]->account_id = $revenue->id;
$deposit->transactions[1]->amount = -300;
$deposit->transactions[1]->save();
// get asset account:
$result = $deposit->destination_account;
$this->assertEquals($asset->id, $result->id);
}
/**
* @covers FireflyIII\Models\TransactionJournal::getSourceAccountAttribute
*/
public function testGetSourceAccountAttribute()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$deposit->transaction_type_id = $depositType->id;
$deposit->save();
// make accounts
FactoryMuffin::create('FireflyIII\Models\Account');
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
$deposit->transactions[0]->account_id = $asset->id;
$deposit->transactions[0]->amount = 300;
$deposit->transactions[0]->save();
$deposit->transactions[1]->account_id = $revenue->id;
$deposit->transactions[1]->amount = -300;
$deposit->transactions[1]->save();
// get asset account:
$result = $deposit->source_account;
$this->assertEquals($revenue->id, $result->id);
}
}

View File

@ -0,0 +1,891 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 16:33:55.
*/
class AccountRepositoryTest extends TestCase
{
/**
* @var AccountRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new AccountRepository;
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\Repositories\Account\AccountRepository::countAccounts
*/
public function testCountAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$type = $account->accountType->type;
$this->be($account->user);
$this->assertEquals(1, $this->object->countAccounts([$type]));
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::destroy
* @covers FireflyIII\Providers\EventServiceProvider::boot
* @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents
*/
public function testDestroy()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// create some transactions and attach them to the account:
for ($i = 0; $i < 5; $i++) {
$transaction = FactoryMuffin::create('FireflyIII\Models\Transaction');
$transaction->account_id = $account->id;
$transaction->save();
}
$accountId = $account->id;
$this->be($account->user);
$this->object->destroy($account);
// cannot find account:
$this->assertCount(0, Account::whereId($accountId)->whereNotNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getAccounts
*/
public function testGetAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$type = $account->accountType->type;
$this->be($account->user);
$this->assertCount(1, $this->object->getAccounts([$type]));
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getCreditCards
*/
public function testGetCreditCards()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// create account meta object:
$meta = new AccountMeta;
$meta->name = 'accountRole';
$meta->data = 'ccAsset';
$meta->account_id = $account->id;
$meta->save();
// meta account type
$meta = new AccountMeta;
$meta->name = 'ccType';
$meta->data = 'monthlyFull';
$meta->account_id = $account->id;
$meta->save();
// login
$this->be($account->user);
// test!
$this->assertCount(1, $this->object->getCreditCards());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFirstTransaction
*/
public function testGetFirstTransaction()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$first = $journal->transactions()->orderBy('date', 'DESC')->first();
$first->account_id = $account->id;
$first->save();
// login
$this->be($account->user);
$oldest = $this->object->getFirstTransaction($journal, $account);
$this->assertEquals($first->amount, $oldest->amount);
$this->assertEquals($first->id, $oldest->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts
*/
public function testGetFrontpageAccounts()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
// making two account types is kind of cheating but it works.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
/** @var Preference $preference */
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = [];
$preference->save();
$this->be($account->user);
$set = $this->object->getFrontpageAccounts($preference);
$this->assertEquals($account->id, $set->first()->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts
*/
public function testGetFrontpageAccountsWithPreference()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
// making two account types is kind of cheating but it works.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
/** @var Preference $preference */
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = [$account->id];
$preference->save();
$this->be($account->user);
$set = $this->object->getFrontpageAccounts($preference);
$this->assertEquals($account->id, $set->first()->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageTransactions
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetFrontpageTransactions()
{
// three journals
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// three dates (one is out of bounds)
$journal1->date = new Carbon('2012-01-02');
$journal1->user_id = $account->user_id;
$journal2->date = new Carbon('2012-01-09');
$journal2->user_id = $account->user_id;
$journal3->date = new Carbon('2012-02-02');
$journal3->user_id = $account->user_id;
// save all
$journal1->save();
$journal2->save();
$journal3->save();
$journal1->transactions[0]->account_id = $account->id;
$journal1->transactions[0]->save();
$journal2->transactions[0]->account_id = $account->id;
$journal2->transactions[0]->save();
$journal3->transactions[0]->account_id = $account->id;
$journal3->transactions[0]->save();
// be user
$this->be($journal1->user);
// get set:
$set = $this->object->getFrontpageTransactions($account, new Carbon('2012-01-01'), new Carbon('2012-01-31'));
// should have two left.
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getJournals
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetJournals()
{
$date = new Carbon;
// three journals
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// three dates (one is out of bounds)
$journal1->date = $date;
$journal1->user_id = $account->user_id;
$journal2->date = $date;
$journal2->user_id = $account->user_id;
$journal3->date = $date;
$journal3->user_id = $account->user_id;
// save all
$journal1->save();
$journal2->save();
$journal3->save();
$journal1->transactions[0]->account_id = $account->id;
$journal1->transactions[0]->save();
$journal2->transactions[0]->account_id = $account->id;
$journal2->transactions[0]->save();
$journal3->transactions[0]->account_id = $account->id;
$journal3->transactions[0]->save();
// be user
$this->be($journal1->user);
// get paginator:
/** @var LengthAwarePaginator $paginator */
$paginator = $this->object->getJournals($account, 1);
// should have three entries:
$this->assertEquals(3, $paginator->count());
$this->assertEquals(1, $paginator->currentPage());
$this->assertFalse($paginator->isEmpty());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getLastActivity
*/
public function testGetLastActivity()
{
$date = new Carbon('2012-02-02');
// one journal
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $date;
$journal->user_id = $account->user_id;
$journal->save();
$journal->transactions[0]->account_id = $account->id;
$journal->transactions[0]->save();
// be user
$this->be($journal->user);
$latest = $this->object->getLastActivity($account);
$this->assertEquals($date->format('Y-m-d'), $latest->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getLastActivity
*/
public function testGetLastActivityNoActivity()
{
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
$latest = $this->object->getLastActivity($account);
$this->assertnull($latest);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getPiggyBankAccounts
*/
public function testGetPiggyBankAccounts()
{
$date = Carbon::now()->startOfMonth()->addDays(3);
/*
* Quite the collection of objects for this one.
*/
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$piggyBankRepetition = $piggyBank->piggybankRepetitions()->first();
/*
* Update id's to match each other:
*/
$piggyBankRepetition->currentamount = rand(1, 100);
$piggyBankRepetition->startdate = $date;
$piggyBankRepetition->targetdate = $date;
$piggyBank->account_id = $account->id;
$piggyBankRepetition->save();
$piggyBank->save();
/*
* Put dates in session:
*/
$this->session(['start' => Carbon::now()->startOfMonth(), 'end' => Carbon::now()->endOfMonth()]);
/*
* Run method:
*/
$this->be($account->user);
$collection = $this->object->getPiggyBankAccounts();
$this->assertCount(1, $collection);
$this->assertEquals($collection->first()->id, $account->id);
$this->assertEquals($collection->first()->piggyBalance, $piggyBankRepetition->currentamount);
$this->assertEquals(0, $collection->first()->startBalance);
$this->assertEquals(0, $collection->first()->endBalance);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getSavingsAccounts
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetSavingsAccounts()
{
// create three accounts:
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$type = FactoryMuffin::create('FireflyIII\Models\AccountType');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account1->account_type_id = $type->id;
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2->account_type_id = $type->id;
$account3 = FactoryMuffin::create('FireflyIII\Models\Account');
$account3->account_type_id = $type->id;
// make them savings accounts:
$meta = new AccountMeta;
$meta->name = 'accountRole';
$meta->data = 'savingAsset';
$meta->account_id = $account1->id;
$meta->save();
$meta = new AccountMeta;
$meta->name = 'accountRole';
$meta->data = 'savingAsset';
$meta->account_id = $account2->id;
$meta->save();
$meta = new AccountMeta;
$meta->name = 'accountRole';
$meta->data = 'savingAsset';
$meta->account_id = $account3->id;
$meta->save();
// assign to the same user:
$account2->user_id = $account1->user_id;
$account3->user_id = $account1->user_id;
$account1->save();
$account2->save();
$account3->save();
$this->be($account1->user);
// mock steam balance:
Steam::shouldReceive('balance')->andReturn(0, 0, 1, 2, 4, 3);
// get the result from the method:
$result = $this->object->getSavingsAccounts();
$this->assertEquals(0, $result->get(0)->difference);
$this->assertEquals(1, $result->get(1)->difference);
$this->assertEquals(-1, $result->get(2)->difference);
$this->assertEquals(100, $result->get(0)->percentage);
$this->assertEquals(100, $result->get(1)->percentage);
$this->assertEquals(25, $result->get(2)->percentage);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getTransfersInRange
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetTransfersInRange()
{
FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
FactoryMuffin::create('FireflyIII\Models\AccountType'); // expense
FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
$user = FactoryMuffin::create('FireflyIII\User'); // user!
$accounts = [];
$opposings = []; // opposing accounts.
$journals = [];
// dates
$start = new Carbon('2014-01-01');
$end = new Carbon('2014-01-31');
$inRange = new Carbon('2014-01-15');
$before = new Carbon('2013-01-15');
// create two accounts:
for ($i = 0; $i < 2; $i++) {
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$account->account_type_id = $asset->id;
$account->user_id = $user->id;
$account->save();
$accounts[] = $account;
$opposing = FactoryMuffin::create('FireflyIII\Models\Account');
$opposing->account_type_id = $asset->id;
$opposing->user_id = $user->id;
$opposing->save();
$opposings[] = $opposing;
}
// for each account, create ten journals
foreach ($accounts as $index => $account) {
for ($i = 0; $i < 10; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->user_id = $user->id;
$journal->transaction_type_id = $transfer->id;
$journal->save();
// if $i < 6, transfer is in range:
if ($i < 6) {
$journal->date = $inRange;
} else {
$journal->date = $before;
}
/*
* Transfers can go either way (see the amount)
*/
if ($i < 4) {
$amount = 100;
} else {
$amount = -100;
}
$journal->transactions[0]->account_id = $account->id;
$journal->transactions[0]->amount = $amount;
$journal->transactions[1]->account_id = $opposings[$index]->id;
$journal->transactions[1]->amount = $amount * -1;
$journal->transactions[0]->save();
$journal->transactions[1]->save();
// save journal:
$journal->save();
$journals[] = $journal;
}
}
$this->be($user);
$set = $this->object->getTransfersInRange($accounts[0], $start, $end);
$this->assertEquals(4, $set->count());
$this->assertEquals(100, $set->first()->amount);
$this->assertEquals($journals[0]->description, $set->first()->description);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::leftOnAccount
*/
public function testLeftOnAccount()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBankRepetition = $piggyBank->piggybankRepetitions()->first();
$piggyBankRepetition->currentamount = rand(1, 100);
$piggyBankRepetition->save();
$this->be($piggyBank->account->user);
$result = $this->object->leftOnAccount($piggyBank->account, new Carbon);
$this->assertEquals($piggyBankRepetition->currentamount * -1, $result);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::openingBalanceTransaction
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testOpeningBalanceTransaction()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// dates
$one = new Carbon('2013-01-15');
$two = new Carbon('2015-01-15');
// journal 1 will match:
$journal1->date = $one;
$journal1->user_id = $account->user_id;
$journal2->date = $two;
$journal2->user_id = $account->user_id;
// add account things:
$journal1->transactions[0]->account_id = $account->id;
$journal1->transactions[1]->account_id = $account->id;
$journal2->transactions[0]->account_id = $account->id;
$journal2->transactions[1]->account_id = $account->id;
$journal1->transactions[0]->save();
$journal1->transactions[1]->save();
$journal2->transactions[0]->save();
$journal2->transactions[1]->save();
$journal1->save();
$journal2->save();
$this->be($account->user);
$result = $this->object->openingBalanceTransaction($account);
$this->assertEquals($journal1->id, $result->id);
$this->assertEquals($journal1->description, $result->description);
$this->assertEquals(100, $result->amount);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::openingBalanceTransaction
*/
public function testOpeningBalanceTransactionNull()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$this->be($account->user);
$result = $this->object->openingBalanceTransaction($account);
$this->assertNull($result);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::store
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
*
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$data = [
'accountType' => 'expense',
'user' => $user->id,
'name' => 'Test account #' . rand(1, 100),
'active' => true,
'accountRole' => 'testAccount',
'openingBalance' => 100,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$account = $this->object->store($data);
$this->assertEquals($data['name'], $account->name);
}
/**
* This function should give a big fat error, but it doesnt.
*
* @covers FireflyIII\Repositories\Account\AccountRepository::store
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
*/
public function testStoreWithExistingAccount()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account'); // expense
FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue
FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($account->user);
$data = [
'accountType' => 'expense',
'user' => $account->user->id,
'name' => $account->name,
'active' => $account->active,
'accountRole' => 'testAccount',
'openingBalance' => 0,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$newAccount = $this->object->store($data);
$this->assertEquals($account->name, $newAccount->name);
$this->assertEquals($account->id, $newAccount->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::store
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testStoreWithInvalidAccountData()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($account->user);
$data = [
'accountType' => 'expense',
'user' => $account->user->id + 12,
'name' => $account->name,
'active' => $account->active,
'accountRole' => 'testAccount',
'openingBalance' => 0,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$this->object->store($data);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::store
* @covers FireflyIII\Repositories\Account\AccountRepository::storeAccount
* @covers FireflyIII\Repositories\Account\AccountRepository::storeMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::storeInitialBalance
*/
public function testStoreWithNegativeInitialBalance()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$data = [
'accountType' => 'expense',
'user' => $user->id,
'name' => 'Test account #' . rand(1, 100),
'active' => true,
'accountRole' => 'testAccount',
'openingBalance' => -100,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$account = $this->object->store($data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(-100, $account->transactions()->first()->amount);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::sumOfEverything
*/
public function testSumOfEverything()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$this->assertEquals(0, $this->object->sumOfEverything());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::update
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUpdate()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$data = [
'accountType' => 'expense',
'user' => $user->id,
'name' => 'Test account #' . rand(1, 100),
'active' => true,
'accountRole' => 'testAccount',
'openingBalance' => 100,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$account = $this->object->store($data);
// now update that same account:
$data = [
'name' => 'New account name' . rand(0, 100),
'active' => 1,
'virtualBalance' => 0,
'openingBalance' => 50,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-02-02',
];
$newAccount = $this->object->update($account, $data);
$this->assertEquals($data['name'], $newAccount->name);
$this->assertEquals(50, $account->transactions()->first()->amount);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::update
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUpdateDeleteOpeningBalance()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$data = [
'accountType' => 'expense',
'user' => $user->id,
'name' => 'Test account #' . rand(1, 100),
'active' => true,
'accountRole' => 'testAccount',
'openingBalance' => 100,
'virtualBalance' => 0,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-01-01',
];
$account = $this->object->store($data);
// now update that same account:
$data = [
'name' => 'New account name' . rand(0, 100),
'active' => 1,
'user' => $user->id,
'accountRole' => 'testAccount',
'virtualBalance' => 0,
'openingBalance' => 0,
];
$newAccount = $this->object->update($account, $data);
$this->assertEquals($data['name'], $newAccount->name);
$this->assertEquals(0, $newAccount->transactions()->whereNull('deleted_at')->count());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::update
* @covers FireflyIII\Repositories\Account\AccountRepository::updateMetadata
* @covers FireflyIII\Repositories\Account\AccountRepository::updateInitialBalance
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUpdateNewOpeningBalance()
{
$user = FactoryMuffin::create('FireflyIII\User');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$this->be($user);
$data = [
'accountType' => 'expense',
'user' => $user->id,
'name' => 'Test account #' . rand(1, 100),
'active' => true,
'accountRole' => 'testAccount',
'openingBalance' => 0,
'virtualBalance' => 0,
];
$account = $this->object->store($data);
// now update that same account:
$data = [
'name' => 'New account name' . rand(0, 100),
'active' => 1,
'user' => $user->id,
'virtualBalance' => 0,
'accountRole' => 'testAccount',
'ccMonthlyPaymentDate' => '2015-01-01',
'openingBalance' => 51,
'openingBalanceCurrency' => $currency->id,
'openingBalanceDate' => '2015-02-02',
];
$newAccount = $this->object->update($account, $data);
$this->assertEquals($data['name'], $newAccount->name);
$this->assertEquals(51, $account->transactions()->first()->amount);
}
}

View File

@ -0,0 +1,467 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-08 at 10:43:42.
*/
class BillRepositoryTest extends TestCase
{
/**
* @var BillRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new BillRepository;
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();
}
public function testBillPaymentsInRange()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
// payment:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $start;
$journal->bill_id = $bill->id;
$journal->save();
$this->object->billPaymentsInRange($bill, $start, $end);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::createFakeBill
*/
public function testCreateFakeBill()
{
$description = 'Fake bill ' . rand(10, 100);
$date = new Carbon('2013-01-01');
$amount = 1200;
$bill = $this->object->createFakeBill($description, $date, $amount);
$this->assertEquals($amount, $bill->amount_max);
$this->assertEquals($amount, $bill->amount_min);
$this->assertNull($bill->id);
$this->assertEquals($description, $bill->name);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::destroy
*/
public function testDestroy()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$accountId = $bill->id;
$this->object->destroy($bill);
// cannot find bill:
$this->assertCount(0, Bill::whereId($accountId)->whereNotNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getActiveBills
*/
public function testGetActiveBills()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill2 = FactoryMuffin::create('FireflyIII\Models\Bill');
// update bills
$bill1->active = 1;
$bill2->active = 0;
$bill2->user_id = $bill1->user_id;
$bill1->save();
$bill2->save();
$this->be($bill1->user);
$set = $this->object->getActiveBills();
$this->assertCount(1, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getBills
*/
public function testGetBills()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill2 = FactoryMuffin::create('FireflyIII\Models\Bill');
// update bills
$bill1->active = 1;
$bill2->active = 0;
$bill2->user_id = $bill1->user_id;
$bill1->save();
$bill2->save();
$this->be($bill1->user);
$set = $this->object->getBills();
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getJournals
*/
public function testGetJournals()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
// update bills
$bill1->active = 1;
$bill1->save();
$this->be($bill1->user);
$set = $this->object->getJournals($bill1);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getJournalsInRange
*/
public function testGetJournalsInRange()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
// update bills
$bill1->active = 1;
$bill1->save();
$this->be($bill1->user);
$set = $this->object->getJournalsInRange($bill1, new Carbon, new Carbon);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getPossiblyRelatedJournals
*/
public function testGetPossiblyRelatedJournals()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$bill1->amount_min = 100;
$bill1->amount_max = 1000;
$account->user_id = $bill1->user_id;
$bill1->save();
$account->save();
// create some transactions to match our bill:
for ($i = 0; $i < 8; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->user_id = $bill1->user_id;
$journal->save();
$journal->transactions[0]->account_id = $account->id;
$journal->transactions[0]->save();
}
$this->be($bill1->user);
$set = $this->object->getPossiblyRelatedJournals($bill1);
$this->assertCount(8, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::getRanges
*/
public function testGetRanges()
{
$bill1 = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill1->date = new Carbon('2012-01-01');
$bill1->repeat_freq = 'monthly';
$bill1->save();
$set = $this->object->getRanges($bill1, new Carbon('2012-01-01'), new Carbon('2012-12-31'));
$this->assertCount(12, $set);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::lastFoundMatch
*/
public function testLastFoundMatch()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->bill_id = $bill->id;
$journal->user_id = $bill->user_id;
$journal->save();
$this->be($bill->user);
$date = $this->object->lastFoundMatch($bill);
$this->assertEquals($journal->date->format('Y-m-d'), $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::lastFoundMatch
*/
public function testLastFoundMatchNull()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$this->be($bill->user);
$date = $this->object->lastFoundMatch($bill);
$this->assertNull($date);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
*/
public function testNextExpectedMatch()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->date = new Carbon('2012-01-07');
$bill->repeat_freq = 'monthly';
$bill->save();
$this->be($bill->user);
// journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = Carbon::now()->format('Y-m-d');
$journal->user_id = $bill->user_id;
$journal->bill_id = $bill->id;
$journal->save();
$next = $this->object->nextExpectedMatch($bill);
$today = Carbon::now()->endOfMonth()->addDay();
$this->assertEquals($today->format('Y-m-d'), $next->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
*/
public function testNextExpectedMatchInactive()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->active = 0;
$bill->save();
$this->be($bill->user);
$this->assertNull($this->object->nextExpectedMatch($bill));
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::nextExpectedMatch
*/
public function testNextExpectedMatchNoJournals()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->date = new Carbon('2012-01-07');
$bill->repeat_freq = 'monthly';
$bill->save();
$this->be($bill->user);
$next = $this->object->nextExpectedMatch($bill);
$today = Carbon::now()->startOfMonth();
$this->assertEquals($today->format('Y-m-d'), $next->format('Y-m-d'));
}
/**
* One
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
* @covers FireflyIII\Repositories\Bill\BillRepository::doWordMatch
* @covers FireflyIII\Repositories\Bill\BillRepository::doAmountMatch
*/
public function testScanMatch()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->date = new Carbon('2012-01-07');
$bill->repeat_freq = 'monthly';
$bill->match = 'jemoeder';
$bill->amount_min = 90;
$bill->amount_max = 110;
$bill->save();
$this->be($bill->user);
// journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = Carbon::now()->format('Y-m-d');
$journal->description = 'jemoeder';
$journal->user_id = $bill->user_id;
$journal->save();
$this->object->scan($bill, $journal);
$newJournal = TransactionJournal::find($journal->id);
$this->assertEquals($bill->id, $newJournal->bill_id);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
* @covers FireflyIII\Repositories\Bill\BillRepository::doWordMatch
* @covers FireflyIII\Repositories\Bill\BillRepository::doAmountMatch
*/
public function testScanNoMatch()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->date = new Carbon('2012-01-07');
$bill->repeat_freq = 'monthly';
$bill->save();
$this->be($bill->user);
// journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = Carbon::now()->format('Y-m-d');
$journal->user_id = $bill->user_id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
Transaction::create(
[
'account_id' => $account2->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
$this->object->scan($bill, $journal);
$newJournal = TransactionJournal::find($journal->id);
$this->assertNull($newJournal->bill_id);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::scan
* @covers FireflyIII\Repositories\Bill\BillRepository::doWordMatch
* @covers FireflyIII\Repositories\Bill\BillRepository::doAmountMatch
*/
public function testScanNoMatchButAttached()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$bill->date = new Carbon('2012-01-07');
$bill->match = 'blablabla';
$bill->repeat_freq = 'monthly';
$bill->save();
$this->be($bill->user);
// journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = Carbon::now()->format('Y-m-d');
$journal->user_id = $bill->user_id;
$journal->bill_id = $bill->id;
$journal->save();
// two transactions:
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
Transaction::create(
[
'account_id' => $account2->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
$this->object->scan($bill, $journal);
$newJournal = TransactionJournal::find($journal->id);
$this->assertNull($newJournal->bill_id);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'name' => 'Something',
'match' => 'Something',
'amount_min' => 100,
'user' => $user->id,
'amount_max' => 110,
'date' => new Carbon,
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 1,
'active' => 1,
];
$bill = $this->object->store($data);
$this->assertEquals($data['name'], $bill->name);
}
/**
* @covers FireflyIII\Repositories\Bill\BillRepository::update
*/
public function testUpdate()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$data = [
'name' => 'new Name',
'match' => $bill->match,
'amount_min' => 100,
'amount_max' => 110,
'date' => new Carbon,
'repeat_freq' => 'monthly',
'skip' => 0,
'automatch' => 1,
'active' => 1,
];
$newBill = $this->object->update($bill, $data);
$this->assertEquals($data['name'], $newBill->name);
$this->assertEquals($bill->match, $newBill->match);
}
}

View File

@ -0,0 +1,399 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:16:07.
*/
class BudgetRepositoryTest extends TestCase
{
/**
* @var BudgetRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new BudgetRepository;
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\Repositories\Budget\BudgetRepository::cleanupBudgets
* @covers FireflyIII\Providers\EventServiceProvider::boot
*/
public function testCleanupBudgets()
{
// create some budgets:
for ($i = 0; $i < 3; $i++) {
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$limit->budget_id = $budget->id;
$limit->amount = 0;
$limit->save();
}
$this->object->cleanupBudgets();
$this->assertCount(0, BudgetLimit::get());
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::destroy
*/
public function testDestroy()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->object->destroy($budget);
$this->assertCount(0, Budget::where('id', $budget->id)->whereNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::expensesOnDayCorrected
*/
public function testExpensesOnDayCorrected()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$result = $this->object->expensesOnDayCorrected($budget, new Carbon);
$this->assertEquals(0, $result);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getActiveBudgets
*/
public function testGetActiveBudgets()
{
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget1->active = 1;
$budget2->active = 0;
$budget2->user_id = $budget1->user_id;
$budget1->save();
$budget2->save();
$this->be($budget1->user);
$set = $this->object->getActiveBudgets();
$this->assertCount(1, $set);
$this->assertEquals($set->first()->id, $budget1->id);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgetLimitRepetitions
*/
public function testGetBudgetLimitRepetitions()
{
$rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$limit = $rep->budgetlimit;
$limit->startdate = new Carbon('2015-02-02');
$rep->startdate = new Carbon('2015-02-02');
$rep->enddate = new Carbon('2015-02-28');
$limit->save();
$rep->save();
$set = $this->object->getBudgetLimitRepetitions($rep->budgetlimit->budget, new Carbon('2015-02-01'), new Carbon('2015-02-28'));
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgetLimits
*/
public function testGetBudgetLimits()
{
/** @var Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$set = $this->object->getBudgetLimits($budget);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgets
*/
public function testGetBudgets()
{
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget1->active = 1;
$budget2->active = 0;
$budget2->user_id = $budget1->user_id;
$budget1->save();
$budget2->save();
$this->be($budget1->user);
$set = $this->object->getBudgets();
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getCurrentRepetition
*/
public function testGetCurrentRepetition()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
/** @var Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$rep = $this->object->getCurrentRepetition($budget, new Carbon);
$this->assertNull($rep);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getFirstBudgetLimitDate
*/
public function testGetFirstBudgetLimitDate()
{
/** @var BudgetLimit $budget */
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$date = $this->object->getFirstBudgetLimitDate($limit->budget);
$this->assertEquals($date->format('Y-m-d'), $limit->startdate->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getFirstBudgetLimitDate
*/
public function testGetFirstBudgetLimitDateNull()
{
/** @var Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$date = $this->object->getFirstBudgetLimitDate($budget);
$ownDate = Carbon::now()->startOfYear();
$this->assertEquals($date->format('Y-m-d'), $ownDate->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getInactiveBudgets
*/
public function testGetInactiveBudgets()
{
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
$budget1->active = 1;
$budget2->active = 0;
$budget2->user_id = $budget1->user_id;
$budget1->save();
$budget2->save();
$this->be($budget1->user);
$set = $this->object->getInactiveBudgets();
$this->assertCount(1, $set);
$this->assertEquals($set->first()->id, $budget2->id);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getJournals
*/
public function testGetJournals()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$set = $this->object->getJournals($repetition->budgetlimit->budget, $repetition);
$this->assertTrue($set instanceof LengthAwarePaginator);
$this->assertCount(0, $set);
$this->assertEquals(1, $set->currentPage());
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate
*/
public function testGetLastBudgetLimitDate()
{
/** @var BudgetLimit $budget */
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$date = $this->object->getLastBudgetLimitDate($limit->budget);
$this->assertEquals($date->format('Y-m-d'), $limit->startdate->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate
*/
public function testGetLastBudgetLimitDateNull()
{
/** @var Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$date = $this->object->getLastBudgetLimitDate($budget);
$ownDate = Carbon::now()->startOfYear();
$this->assertEquals($date->format('Y-m-d'), $ownDate->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate
*/
public function testGetLimitAmountOnDate()
{
$rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$amount = $this->object->getLimitAmountOnDate($rep->budgetlimit->budget, $rep->startdate);
$this->assertEquals($rep->amount, $amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate
*/
public function testGetLimitAmountOnDateNull()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->getLimitAmountOnDate($budget, new Carbon);
$this->assertNull($amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudget
*/
public function testGetWithoutBudget()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$set = $this->object->getWithoutBudget(new Carbon, new Carbon);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudgetSum
*/
public function testGetWithoutBudgetSum()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$sum = $this->object->getWithoutBudgetSum(new Carbon, new Carbon);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected
* @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod
*/
public function testSpentInPeriodCorrected()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, false);
$this->assertEquals(0, $amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected
* @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod
*/
public function testSpentInPeriodCorrectedShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, true);
$this->assertEquals(0, $amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'name' => 'new budget ' . rand(1, 100),
'user' => $user->id
];
$result = $this->object->store($data);
$this->assertTrue($result instanceof Budget);
$this->assertEquals($result->name, $data['name']);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::update
*/
public function testUpdate()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$data = [
'name' => 'update budget ' . rand(1, 100),
'active' => true
];
$result = $this->object->update($budget, $data);
$this->assertTrue($result instanceof Budget);
$this->assertEquals($result->name, $data['name']);
$this->assertEquals($result->id, $budget->id);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
*/
public function testUpdateLimitAmount()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$result = $this->object->updateLimitAmount($budget, new Carbon, 100);
$this->assertTrue($result instanceof BudgetLimit);
$this->assertEquals($result->amount, 100);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
*/
public function testUpdateLimitAmountExisting()
{
$budgetLimit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$result = $this->object->updateLimitAmount($budgetLimit->budget, $budgetLimit->startdate, 100);
$this->assertTrue($result instanceof BudgetLimit);
$this->assertEquals($result->amount, 100);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
*/
public function testUpdateLimitAmountZero()
{
$budgetLimit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$result = $this->object->updateLimitAmount($budgetLimit->budget, $budgetLimit->startdate, 0);
$this->assertTrue($result instanceof BudgetLimit);
}
}

View File

@ -0,0 +1,290 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class CategoryRepositoryTest extends TestCase
{
/**
* @var CategoryRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new CategoryRepository;
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\Repositories\Category\CategoryRepository::countJournals
*/
public function testCountJournals()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$result = $this->object->countJournals($category);
$this->assertEquals(0, $result);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::destroy
*/
public function testDestroy()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->object->destroy($category);
$count = Category::where('id', $category->id)->whereNull('deleted_at')->count();
$this->assertEquals(0, $count);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategories
*/
public function testGetCategories()
{
$user = FactoryMuffin::create('FireflyIII\User');
$cat1 = FactoryMuffin::create('FireflyIII\Models\Category');
$cat2 = FactoryMuffin::create('FireflyIII\Models\Category');
$cat1->name = 'BBBBB';
$cat2->name = 'AAAAA';
$cat1->user_id = $user->id;
$cat2->user_id = $user->id;
$cat1->save();
$cat2->save();
$this->be($user);
$set = $this->object->getCategories();
$this->assertEquals('AAAAA', $set->first()->name);
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpensesCorrected
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetCategoriesAndExpensesCorrected()
{
$user = FactoryMuffin::create('FireflyIII\User');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); // something
// some dates:
$start = new Carbon('2014-01-01');
$end = new Carbon('2014-01-31');
$inRange = new Carbon('2014-01-12');
// generate three categories
// with ten journals each:
for ($i = 0; $i < 3; $i++) {
// category:
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$category->user_id = $user->id;
$category->save();
for ($j = 0; $j < 10; $j++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->user_id = $user->id;
$journal->transaction_currency_id = $currency->id;
$journal->transaction_type_id = $type->id; // make it a withdrawal
$journal->date = $inRange;
$journal->save();
// connect to category:
$category->transactionjournals()->save($journal);
}
}
$this->be($user);
$set = $this->object->getCategoriesAndExpensesCorrected($start, $end);
$this->assertCount(3, $set);
reset($set);
// 10 journals of 100 each = 1000.
$this->assertEquals('1000', current($set)['sum']);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getFirstActivityDate
*/
public function testGetFirstActivityDate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$category->user_id = $user->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
$this->be($user);
$date = $this->object->getFirstActivityDate($category);
$this->assertEquals('2015-02-11', $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getFirstActivityDate
*/
public function testGetFirstActivityDateNull()
{
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$date = $this->object->getFirstActivityDate($category);
$this->assertEquals(Carbon::now()->format('Y-m-d'), $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getJournals
*/
public function testGetJournals()
{
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$set = $this->object->getJournals($category, 1);
$this->assertEquals(0, $set->count());
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getLatestActivity
*/
public function testGetLatestActivity()
{
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$category->user_id = $user->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
$this->be($user);
$date = $this->object->getLatestActivity($category);
$this->assertEquals('2015-02-11', $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getWithoutCategory
*/
public function testGetWithoutCategory()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$set = $this->object->getWithoutCategory(new Carbon, new Carbon);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected
* @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod
*/
public function testSpentInPeriodSumCorrected()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, false);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected
* @covers FireflyIII\Repositories\Shared\ComponentRepository::spentInPeriod
*/
public function testSpentInPeriodSumCorrectedShared()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, true);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySumCorrected
*/
public function testSpentOnDaySumCorrected()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentOnDaySumCorrected($category, new Carbon);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'name' => 'New category' . rand(1, 100),
'user' => $user->id
];
$newCategory = $this->object->store($data);
$this->assertEquals($data['name'], $newCategory->name);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::update
*/
public function testUpdate()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$data = [
'name' => 'New category' . rand(1, 100),
];
$newCategory = $this->object->update($category, $data);
$this->assertEquals($data['name'], $newCategory->name);
}
public function testgetLatestActivityNull()
{
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$date = $this->object->getLatestActivity($category);
$this->assertNull($date);
}
}

View File

@ -0,0 +1,114 @@
<?php
use FireflyIII\Repositories\Currency\CurrencyRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class CurrencyRepositoryTest extends TestCase
{
/**
* @var CurrencyRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new CurrencyRepository;
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\Repositories\Currency\CurrencyRepository::countJournals
*/
public function testCountJournals()
{
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$count = $this->object->countJournals($currency);
$this->assertEquals(0, $count);
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::get
*/
public function testGet()
{
FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$set = $this->object->get();
$this->assertCount(3, $set); // EUR is already present.
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::getCurrencyByPreference
*/
public function testGetCurrencyByPreference()
{
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = $currency->code;
$preference->save();
$found = $this->object->getCurrencyByPreference($preference);
$this->assertEquals($currency->id, $found->id);
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::getCurrencyByPreference
*/
public function testGetCurrencyByPreferenceNull()
{
FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'ABC';
$preference->save();
$found = $this->object->getCurrencyByPreference($preference);
$this->assertEquals(1, $found->id); // EUR is first and will be set.
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::store
*/
public function testStore()
{
$data = [
'name' => 'Some Currency',
'code' => 'ABC',
'symbol' => 'S'
];
$currency = $this->object->store($data);
$this->assertEquals($data['name'], $currency->name);
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::update
*/
public function testUpdate()
{
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$data = [
'name' => 'Some Currency',
'code' => 'ABC',
'symbol' => 'S'
];
$newCurrency = $this->object->update($currency, $data);
$this->assertEquals($data['name'], $newCurrency->name);
$this->assertEquals($currency->id, $newCurrency->id);
}
}

View File

@ -0,0 +1,572 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class JournalRepositoryTest extends TestCase
{
/**
* @var JournalRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new JournalRepository;
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\Repositories\Journal\JournalRepository::delete
* @covers FireflyIII\Providers\EventServiceProvider::boot
* @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents
*/
public function testDelete()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$transaction = $journal->transactions[0];
$this->object->delete($journal);
$this->assertEquals(0, TransactionJournal::where('id', $journal->id)->whereNull('deleted_at')->count());
$this->assertEquals(0, Transaction::where('id', $transaction->id)->whereNull('deleted_at')->count());
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::first
*/
public function testFirst()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
$first = $this->object->first();
$this->assertEquals($journal->id, $first->id);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::getAmountBefore
*/
public function testGetAmountBefore()
{
// create some accounts:
$expense = FactoryMuffin::create('FireflyIII\Models\Account'); // expense
FactoryMuffin::create('FireflyIII\Models\Account'); // revenue
$asset = FactoryMuffin::create('FireflyIII\Models\Account'); // asset
// transaction type
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
// create five journals with incrementing dates:
$today = new Carbon('2015-01-01');
$journal = null;
for ($i = 0; $i < 5; $i++) {
// create journal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $withdrawal;
$journal->date = $today;
$journal->save();
// update transactions:
$journal->transactions[0]->amount = -100;
$journal->transactions[0]->account_id = $asset->id;
$journal->transactions[0]->save();
$journal->transactions[1]->amount = 100;
$journal->transactions[1]->account_id = $expense->id;
$journal->transactions[1]->save();
// connect to expense
$today->addDay();
}
$before = $this->object->getAmountBefore($journal, $journal->transactions[1]);
// five transactions, we check the last one, so amount should be 400.
$this->assertEquals(400, $before);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfType
*/
public function testGetJournalsOfType()
{
$user = FactoryMuffin::create('FireflyIII\User');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$this->be($user);
$result = $this->object->getJournalsOfType($type);
$this->assertCount(0, $result);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::getJournalsOfTypes
*/
public function testGetJournalsOfTypes()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$types = ['Withdrawal', 'Expense'];
$set = $this->object->getJournalsOfTypes($types, 0, 1);
$this->assertTrue($set instanceof LengthAwarePaginator);
$this->assertEquals(1, $set->currentPage());
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::getTransactionType
*/
public function testGetTransactionType()
{
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$otherType = $this->object->getTransactionType($type->type);
$this->assertEquals($type->id, $otherType->id);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::getWithDate
*/
public function testGetWithDate()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$this->be($journal->user);
$found = $this->object->getWithDate($journal->id, $journal->date);
$this->assertEquals($journal->id, $found->id);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::saveTags
*/
public function testSaveTags()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tags = ['one', 'two', 'three'];
$this->be($journal->user);
$this->object->saveTags($journal, $tags);
$this->assertCount(3, $journal->tags()->get());
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
*/
public function testStore()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'withdrawal',
'amount_currency_id' => $currency->id,
'account_id' => $account1->id,
'expense_account' => 'Some expense account',
'date' => '2014-01-01',
'category' => 'Some category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
*/
public function testStoreDeposit()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'deposit',
'amount_currency_id' => $currency->id,
'account_id' => $account1->id,
'revenue_account' => 'Some revenue account',
'date' => '2014-01-01',
'category' => 'Some category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
*/
public function testStoreExpenseWithCash()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'withdrawal',
'amount_currency_id' => $currency->id,
'account_id' => $account1->id,
'expense_account' => '',
'date' => '2014-01-01',
'category' => 'Some other category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testStoreInvalidFromAccount()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'transfer',
'amount_currency_id' => $currency->id,
'account_from_id' => $account1->id,
'account_to_id' => 17,
'date' => '2014-01-01',
'category' => 'Some other category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
* @expectedException Symfony\Component\HttpKernel\Exception\HttpException
*/
public function testStoreInvalidToAccount()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'transfer',
'amount_currency_id' => $currency->id,
'account_from_id' => 17,
'account_to_id' => $account1->id,
'date' => '2014-01-01',
'category' => 'Some other category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
*/
public function testStoreRevenueWithCash()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'deposit',
'amount_currency_id' => $currency->id,
'account_id' => $account1->id,
'revenue_account' => '',
'date' => '2014-01-01',
'category' => 'Some other category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::store
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeWithdrawalAccounts
* @covers FireflyIII\Repositories\Journal\JournalRepository::storeDepositAccounts
*/
public function testStoreTransfer()
{
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'description' => 'Some journal ' . rand(1, 100),
'user' => $user->id,
'what' => 'transfer',
'amount_currency_id' => $currency->id,
'account_from_id' => $account1->id,
'account_to_id' => $account2->id,
'date' => '2014-01-01',
'category' => 'Some other category',
'budget_id' => $budget->id,
'amount' => 100,
'tags' => ['one', 'two', 'three']
];
$journal = $this->object->store($data);
$this->assertEquals($data['description'], $journal->description);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::update
* @covers FireflyIII\Repositories\Journal\JournalRepository::updateTags
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUpdate()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
// two transactions
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => -100,
]
);
$data = [
'amount_currency_id' => $currency->id,
'description' => 'New description ' . rand(1, 100),
'date' => '2015-01-01',
'category' => 'SomenewCat',
'amount' => 50,
'user' => $journal->user_id,
'budget_id' => $budget->id,
'account_from_id' => $account1->id,
'account_to_id' => $account2->id,
'revenue_account' => 'Some revenue account',
'expense_account' => 'Some expense account',
'tags' => ['a', 'b', 'c']
];
$result = $this->object->update($journal, $data);
$this->assertEquals($result->description, $data['description']);
$this->assertEquals($result->amount, 50);
}
/**
* @covers FireflyIII\Repositories\Journal\JournalRepository::update
* @covers FireflyIII\Repositories\Journal\JournalRepository::updateTags
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testUpdateNoTags()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
for ($i = 0; $i < 4; $i++) {
FactoryMuffin::create('FireflyIII\Models\AccountType');
}
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
// two transactions
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
Transaction::create(
[
'account_id' => $account1->id,
'transaction_journal_id' => $journal->id,
'amount' => -100,
]
);
$data = [
'amount_currency_id' => $currency->id,
'description' => 'New description ' . rand(1, 100),
'date' => '2015-01-01',
'category' => 'SomenewCat',
'amount' => 50,
'user' => $journal->user_id,
'budget_id' => $budget->id,
'account_from_id' => $account1->id,
'account_to_id' => $account2->id,
'revenue_account' => 'Some revenue account',
'expense_account' => 'Some expense account',
'tags' => []
];
$result = $this->object->update($journal, $data);
$this->assertEquals($result->description, $data['description']);
$this->assertEquals($result->amount, 50);
}
}

View File

@ -0,0 +1,196 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class PiggyBankRepositoryTest extends TestCase
{
/**
* @var PiggyBankRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new PiggyBankRepository;
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\Repositories\PiggyBank\PiggyBankRepository::createEvent
*/
public function testCreateEvent()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->object->createEvent($piggyBank, 100);
$this->assertCount(1, $piggyBank->piggybankevents()->get());
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::destroy
* @covers FireflyIII\Providers\EventServiceProvider::boot
* @covers FireflyIII\Providers\EventServiceProvider::registerDeleteEvents
*/
public function testDestroy()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->object->destroy($piggyBank);
$this->assertCount(0, PiggyBank::where('id', $piggyBank->id)->whereNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEventSummarySet
*/
public function testGetEventSummarySet()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$set = $this->object->getEventSummarySet($piggyBank);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEvents
*/
public function testGetEvents()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$set = $this->object->getEvents($piggyBank);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getPiggyBanks
*/
public function testGetPiggyBanks()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$this->be($piggyBank->account->user);
$set = $this->object->getPiggyBanks();
$this->assertCount(1, $set);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::reset
*/
public function testReset()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank->order = 4;
$piggyBank->save();
$this->be($piggyBank->account->user);
$this->object->reset();
$this->assertCount(1, PiggyBank::where('order', 0)->get());
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::setOrder
*/
public function testSetOrder()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$piggyBank->order = 4;
$this->be($piggyBank->account->user);
$piggyBank->save();
$this->object->setOrder($piggyBank->id, 3);
$newPiggy = PiggyBank::find($piggyBank->id);
$this->assertEquals(3, $newPiggy->order);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store
* @covers FireflyIII\Providers\EventServiceProvider::boot
* @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents
*/
public function testStore()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$data = [
'account_id' => $account->id,
'name' => 'Some piggy',
'targetamount' => 100,
'order' => 1,
'remind_me' => false,
'reminder_skip' => 0,
];
$piggyBank = $this->object->store($data);
$this->assertEquals(1, $piggyBank->id);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store
* @covers FireflyIII\Providers\EventServiceProvider::boot
* @covers FireflyIII\Providers\EventServiceProvider::registerCreateEvents
*/
public function testStoreRedirect()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$data = [
'account_id' => $account->id,
'name' => 'Some piggy',
'targetamount' => 100,
'create_another' => 1,
'order' => 1,
'remind_me' => false,
'reminder_skip' => 0,
];
$piggyBank = $this->object->store($data);
$this->assertEquals(1, $piggyBank->id);
}
/**
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::update
*/
public function testUpdate()
{
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
$data = [
'name' => 'Update piggy ' . rand(1, 100),
'account_id' => $piggyBank->account_id,
'targetamount' => 101,
'targetdate' => new Carbon,
'startdate' => new Carbon,
];
$new = $this->object->update($piggyBank, $data);
$this->assertEquals($data['name'], $new->name);
$this->assertEquals($piggyBank->id, $new->id);
}
}

View File

@ -0,0 +1,182 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class TagRepositoryBasicTest extends TestCase
{
/**
* @var TagRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new TagRepository;
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\Repositories\Tag\TagRepository::update
*/
public function testUpdate()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$data = [
'tag' => 'Hello' . rand(1, 100),
'date' => '2012-01-01',
'description' => 'Some',
'latitude' => 12,
'longitude' => 13,
'zoomLevel' => 4,
'tagMode' => 'nothing'
];
$this->be($tag->user);
$newTag = $this->object->update($tag, $data);
$this->assertEquals($data['tag'], $newTag->tag);
$this->assertEquals($tag->id, $newTag->id);
}
/**
* @covers FireflyIII\Repositories\Tag\TagRepository::store
*/
public function testStore()
{
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'tag' => 'Hello' . rand(1, 100),
'date' => '2012-01-01',
'description' => 'Some',
'latitude' => 12,
'longitude' => 13,
'zoomLevel' => 4,
'tagMode' => 'nothing'
];
$this->be($user);
$tag = $this->object->store($data);
$this->assertEquals($data['tag'], $tag->tag);
}
/**
* @covers FireflyIII\Repositories\Tag\TagRepository::destroy
*/
public function testDestroy()
{
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$this->object->destroy($tag);
$this->assertCount(0, Tag::where('id', $tag->id)->whereNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\Tag\TagRepository::get
*/
public function testGet()
{
$user = FactoryMuffin::create('FireflyIII\User');
$tag1 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag2 = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag1->tag = 'BBB';
$tag2->tag = 'AAA';
$tag1->user_id = $user->id;
$tag2->user_id = $user->id;
$tag1->save();
$tag2->save();
$this->be($user);
$set = $this->object->get();
$this->assertCount(2, $set);
$this->assertEquals('AAA', $set->first()->tag);
}
/**
* @covers FireflyIII\Repositories\Tag\TagRepository::coveredByBalancingActs
*/
public function testCoveredByBalancingActs()
{
// create a user:
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// create transaction and account types:
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
FactoryMuffin::create('FireflyIII\Models\AccountType'); // expense
FactoryMuffin::create('FireflyIII\Models\AccountType'); // revenue
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType'); // asset
// create two accounts:
$fromAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset
$toAccount = FactoryMuffin::create('FireflyIII\Models\Account'); // asset
$fromAccount->account_type_id = $asset->id;
$toAccount->account_type_id = $asset->id;
$fromAccount->save();
$toAccount->save();
// create a tag
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'balancingAct';
$tag->user_id = $user->id;
$tag->save();
// date
$today = new Carbon('2014-01-12');
$start = new Carbon('2014-01-01');
$end = new Carbon('2014-01-31');
// store five journals
for ($i = 0; $i < 5; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); // deposit!
// set date:
$journal->date = $today;
$journal->user_id = $user->id;
$journal->transaction_type_id = $transfer->id;
$journal->tags()->save($tag);
$journal->save();
// update accounts:
$journal->transactions[0]->account_id = $fromAccount->id;
$journal->transactions[0]->amount = '-100';
$journal->transactions[0]->save();
$journal->transactions[1]->account_id = $toAccount->id;
$journal->transactions[1]->amount = '100';
$journal->transactions[1]->save();
}
$amount = $this->object->coveredByBalancingActs($toAccount, $start, $end);
// five transactions, 100 each.
$this->assertEquals('500', $amount);
}
}

View File

@ -0,0 +1,656 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class TagRepositoryTest extends TestCase
{
/**
* @var TagRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new TagRepository;
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();
}
/**
* Already connected tag and transaction journal returns FALSE.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
*/
public function testConnectAlreadyConnected()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->tags()->save($tag);
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* A deposit cannot be connected to a balancing act.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
*/
public function testConnectBalancingOneDeposit()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $deposit->id;
$tag->tagMode = 'balancingAct';
$tag->save();
$journal->save();
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* Connecting a single transfer to a balancing act is possible if there are no
* other transfers already connected.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
*/
public function testConnectBalancingOneTransfer()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $transfer->id;
$tag->tagMode = 'balancingAct';
$tag->save();
$journal->save();
$result = $this->object->connect($journal, $tag);
$this->assertTrue($result);
}
/**
* Connecting a single withdrawal to a balancing act is possible if there are
* not other withdrawals already connected.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectBalancingAct
*/
public function testConnectBalancingOneWithdrawal()
{
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $withdrawal->id;
$tag->tagMode = 'balancingAct';
$tag->save();
$journal->save();
$result = $this->object->connect($journal, $tag);
$this->assertTrue($result);
}
/**
* Default connection between a journal and a tag.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
*/
public function testConnectDefault()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->save();
$result = $this->object->connect($journal, $tag);
$this->assertTrue($result);
}
/**
* Fallback for connect then the tag mode is unknown
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
*/
public function testConnectInvalidType()
{
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'Idontknow';
$tag->save();
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* Once one or more journals have been accepted by the tag, others must match the asset account
* id. For this to work, we must also create an asset account, and a transaction.
*
* Connecting a deposit to a tag that already has a withdrawal.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentMultipleMatch()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// transactions for both:
$journal1->transactions[0]->account_id = $account->id;
$journal2->transactions[0]->account_id = $account->id;
$journal1->transactions[1]->account_id = $account->id;
$journal2->transactions[1]->account_id = $account->id;
$journal1->transactions[0]->save();
$journal2->transactions[0]->save();
$journal1->transactions[1]->save();
$journal2->transactions[1]->save();
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal1->transaction_type_id = $withdrawal->id;
$journal2->transaction_type_id = $deposit->id;
$tag->tagMode = 'advancePayment';
$account->account_type_id = $asset->id;
$tag->save();
$journal1->save();
$journal2->save();
$account->save();
// connect journal1:
$journal1->tags()->save($tag);
$result = $this->object->connect($journal2, $tag);
$this->assertTrue($result);
}
/**
* Once one or more journals have been accepted by the tag, others must match the asset account
* id. For this to work, we must also create an asset account, and a transaction.
*
* This covers the advance payment
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentNoMatch()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// transactions for both:
$journal1->transactions[0]->account_id = $account1->id;
$journal2->transactions[0]->account_id = $account2->id;
$journal1->transactions[1]->account_id = $account1->id;
$journal2->transactions[1]->account_id = $account2->id;
$journal1->transactions[0]->save();
$journal2->transactions[0]->save();
$journal1->transactions[1]->save();
$journal2->transactions[1]->save();
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal1->transaction_type_id = $withdrawal->id;
$journal2->transaction_type_id = $deposit->id;
$tag->tagMode = 'advancePayment';
$account1->account_type_id = $asset->id;
$account2->account_type_id = $asset->id;
$tag->save();
$journal1->save();
$journal2->save();
$account1->save();
$account2->save();
// connect journal1:
$journal1->tags()->save($tag);
$result = $this->object->connect($journal2, $tag);
// account1 and account2 are different, so false:
$this->assertFalse($result);
}
/**
* Once one or more journals have been accepted by the tag, others must match the asset account
* id. For this to work, we must also create an asset account, and a transaction.
*
* This covers the advance payment
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentNoMatchDeposit()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
$asset = FactoryMuffin::create('FireflyIII\Models\AccountType');
$account1 = FactoryMuffin::create('FireflyIII\Models\Account');
$account2 = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// transactions for both:
$journal1->transactions[0]->account_id = $account1->id;
$journal2->transactions[0]->account_id = $account2->id;
$journal1->transactions[1]->account_id = $account1->id;
$journal2->transactions[1]->account_id = $account2->id;
$journal1->transactions[0]->save();
$journal2->transactions[0]->save();
$journal1->transactions[1]->save();
$journal2->transactions[1]->save();
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal1->transaction_type_id = $withdrawal->id;
$journal2->transaction_type_id = $deposit->id;
$tag->tagMode = 'advancePayment';
$account1->account_type_id = $asset->id;
$account2->account_type_id = $asset->id;
$tag->save();
$journal1->save();
$journal2->save();
$account1->save();
$account2->save();
// connect journal1:
$journal2->tags()->save($tag);
$result = $this->object->connect($journal1, $tag);
// account1 and account2 are different, so false:
$this->assertFalse($result);
}
/**
* An advance payment accepts no transfers.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentOneTransfer()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $transfer->id;
$tag->tagMode = 'advancePayment';
$tag->save();
$journal->save();
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* An advance payment accepts only one withdrawal, not two.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentOneWithdrawal()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $withdrawal->id;
$tag->tagMode = 'advancePayment';
$tag->save();
$journal->save();
$result = $this->object->connect($journal, $tag);
$this->assertTrue($result);
}
/**
* An advance payment accepts only one withdrawal, not two.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentTwoWithdrawals()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$otherJournal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $withdrawal->id;
$otherJournal->transaction_type_id = $withdrawal->id;
$tag->tagMode = 'advancePayment';
$tag->save();
$journal->save();
$otherJournal->save();
$otherJournal->tags()->save($tag);
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* An advance payment accepts only one withdrawal, not two, even not
* if the accounts are the same
*
* @covers FireflyIII\Repositories\Tag\TagRepository::connect
* @covers FireflyIII\Repositories\Tag\TagRepository::connectAdvancePayment
* @covers FireflyIII\Repositories\Tag\TagRepository::matchAll
*/
public function testConnectPaymentTwoWithdrawalsSameAccounts()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
FactoryMuffin::create('FireflyIII\Models\TransactionType');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$otherJournal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$journal->transaction_type_id = $withdrawal->id;
$otherJournal->transaction_type_id = $withdrawal->id;
// match up accounts:
$otherJournal->transactions[0]->account_id = $journal->transactions[0]->account_id;
$otherJournal->transactions[1]->account_id = $journal->transactions[1]->account_id;
$otherJournal->transactions[0]->save();
$otherJournal->transactions[1]->save();
$tag->tagMode = 'advancePayment';
$tag->save();
$journal->save();
$otherJournal->save();
$otherJournal->tags()->save($tag);
$result = $this->object->connect($journal, $tag);
$this->assertFalse($result);
}
/**
* By default, any tag can become an advancePayment
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance
*/
public function testTagAllowAdvance()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
$result = $this->object->tagAllowAdvance($tag);
$this->assertTrue($result);
}
/**
* If the tag has one transfer, it can NOT become an advance payment.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance
*/
public function testTagAllowAdvanceWithTransfer()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
$transfer = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // transfer
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
// create withdrawal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $transfer->id;
$journal->save();
$journal->tags()->save($tag);
$result = $this->object->tagAllowAdvance($tag);
$this->assertFalse($result);
}
/**
* If the tag has one withdrawal, it can still become an advance payment.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance
*/
public function testTagAllowAdvanceWithWithdrawal()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
// create withdrawal:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->tags()->save($tag);
$result = $this->object->tagAllowAdvance($tag);
$this->assertTrue($result);
}
/**
* If the tag has two withdrawals, it CANNOT become an advance payment.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowAdvance
*/
public function testTagAllowAdvanceWithWithdrawals()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionType');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
// create withdrawals
for ($i = 0; $i < 2; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $withdrawal->id;
$journal->save();
$journal->tags()->save($tag);
}
$result = $this->object->tagAllowAdvance($tag);
$this->assertFalse($result);
}
/**
* By default, an empty tag can become a balancing act.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing
*/
public function testTagAllowBalancing()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
$result = $this->object->tagAllowBalancing($tag);
$this->assertTrue($result);
}
/**
* When the tag has one deposit, it can NOT become a balancing act.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing
*/
public function testTagAllowBalancingDeposit()
{
// create a tag
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
// create three journals and connect them:
for ($i = 0; $i < 1; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->transaction_type_id = $deposit->id;
$journal->save();
$journal->tags()->save($tag);
}
$result = $this->object->tagAllowBalancing($tag);
$this->assertFalse($result);
}
/**
* When the tag has more than 2 transactions connected to it, it cannot become abalancing act.
*
* @covers FireflyIII\Repositories\Tag\TagRepository::tagAllowBalancing
*/
public function testTagAllowBalancingManyJournals()
{
// create a tag
$user = FactoryMuffin::create('FireflyIII\User');
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
$tag->tagMode = 'nothing';
$tag->user_id = $user->id;
$tag->save();
// create three journals and connect them:
for ($i = 0; $i < 3; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->tags()->save($tag);
}
$result = $this->object->tagAllowBalancing($tag);
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,300 @@
<?php
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Amount;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @SuppressWarnings(PHPMD.TooManyMethods)
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 16:33:55.
*/
class AmountSupportTest extends TestCase
{
/**
* @var Amount
*/
protected $object;
/**
* 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->object = new Amount;
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
}
/**
* 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\Support\Amount::format
* @covers FireflyIII\Support\Amount::getCurrencySymbol
*/
public function testFormat()
{
$amount = '123';
$result = $this->object->format($amount, true);
$this->assertTrue(str_contains($result, $amount));
}
/**
* @covers FireflyIII\Support\Amount::formatJournal
*/
public function testFormatJournalColouredTransfer()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
/** @var \FireflyIII\Models\TransactionJournal $journal */
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$symbol = $journal->transactionCurrency->symbol;
$result = $this->object->formatJournal($journal, true);
// transfer is blue:
$this->assertTrue(str_contains($result, '<span class="text-info">'));
// transfer contains currency code:
$this->assertTrue(str_contains($result, $symbol));
// all amounts are 100.
$this->assertTrue(str_contains($result, '100'));
}
/**
* @covers FireflyIII\Support\Amount::formatJournal
*/
public function testFormatJournalUncolouredTransfer()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // deposit
/** @var \FireflyIII\Models\TransactionJournal $journal */
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$symbol = $journal->transactionCurrency->symbol;
$result = $this->object->formatJournal($journal, false);
// transfer is not blue:
$this->assertFalse(str_contains($result, '<span class="text-info">'));
// transfer contains currency code:
$this->assertTrue(str_contains($result, $symbol));
// all amounts are 100.
$this->assertTrue(str_contains($result, '100'));
}
/**
* @covers FireflyIII\Support\Amount::formatJournal
*/
public function testFormatJournalWithSymbol()
{
FactoryMuffin::create('FireflyIII\Models\TransactionType'); // withdrawal
/** @var \FireflyIII\Models\TransactionJournal $journal */
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$symbol = $journal->transactionCurrency->symbol;
$journal->symbol = $symbol;
$result = $this->object->formatJournal($journal, true);
// transfer is not blue:
$this->assertFalse(str_contains($result, '<span class="text-danger">'));
// transfer contains currency code:
$this->assertTrue(str_contains($result, $symbol));
// all amounts are 100.
$this->assertTrue(str_contains($result, '100'));
}
/**
* @covers FireflyIII\Support\Amount::formatJournal
*/
public function testFormatJournalWithdrawal()
{
/** @var \FireflyIII\Models\TransactionJournal $journal */
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$symbol = $journal->transactionCurrency->symbol;
$result = $this->object->formatJournal($journal, true);
// transfer is not blue:
$this->assertFalse(str_contains($result, '<span class="text-success">'));
// transfer contains currency code:
$this->assertTrue(str_contains($result, $symbol));
// all amounts are 100.
$this->assertTrue(str_contains($result, '100'));
}
/**
* @covers FireflyIII\Support\Amount::formatTransaction
*/
public function testFormatTransaction()
{
// is a withdrawal.
$transaction = FactoryMuffin::create('FireflyIII\Models\Transaction');
$transaction->amount = -100;
$transaction->save();
$result = $this->object->formatTransaction($transaction, true);
// withdrawal is red:
$this->assertTrue(str_contains($result, '<span class="text-danger">'));
// all amounts are 100.
$this->assertTrue(str_contains($result, '100'));
}
/**
* @covers FireflyIII\Support\Amount::formatWithSymbol
*/
public function testFormatWithSymbolColouredAboveZero()
{
$amount = 123;
$symbol = 'top';
$coloured = true;
$result = $this->object->formatWithSymbol($symbol, $amount, $coloured);
// has colour:
$this->assertTrue(str_contains($result, '<span class="text-success">'));
// has symbol:
$this->assertTrue(str_contains($result, $symbol));
// has amount:
$this->assertTrue(str_contains($result, '123'));
}
/**
* @covers FireflyIII\Support\Amount::formatWithSymbol
*/
public function testFormatWithSymbolColouredBelowZero()
{
$amount = -123;
$symbol = 'top';
$coloured = true;
$result = $this->object->formatWithSymbol($symbol, $amount, $coloured);
// has colour:
$this->assertTrue(str_contains($result, '<span class="text-danger">'));
// has symbol:
$this->assertTrue(str_contains($result, $symbol));
// has amount:
$this->assertTrue(str_contains($result, '123'));
}
/**
* @covers FireflyIII\Support\Amount::formatWithSymbol
*/
public function testFormatWithSymbolColouredZero()
{
$amount = 0.0;
$symbol = 'top';
$coloured = true;
$result = $this->object->formatWithSymbol($symbol, $amount, $coloured);
// has colour:
$this->assertTrue(str_contains($result, '#999'));
// has symbol:
$this->assertTrue(str_contains($result, $symbol));
// has amount:
$this->assertTrue(str_contains($result, '0'));
}
/**
* @covers FireflyIII\Support\Amount::formatWithSymbol
*/
public function testFormatWithSymbolNotColoured()
{
$amount = 0;
$symbol = 'top';
$coloured = false;
$result = $this->object->formatWithSymbol($symbol, $amount, $coloured);
// has symbol:
$this->assertTrue(str_contains($result, $symbol));
// has amount:
$this->assertTrue(str_contains($result, '0'));
}
/**
* @covers FireflyIII\Support\Amount::getAllCurrencies
*/
public function testGetAllCurrencies()
{
$size = TransactionCurrency::count();
$list = $this->object->getAllCurrencies();
$this->assertCount($size, $list);
}
/**
* @covers FireflyIII\Support\Amount::getCurrencyCode
*/
public function testGetCurrencyCode()
{
$code = $this->object->getCurrencyCode();
$this->assertEquals('EUR', $code);
}
/**
* @covers FireflyIII\Support\Amount::getCurrencyCode
*/
public function testGetCurrencyCodeNoSuchCurrency()
{
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
// delete any currency preferences:
Preference::where('user_id', $user->id)->delete();
// delete transaction currencies:
foreach (TransactionCurrency::get() as $c) {
$c->delete();
}
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->user_id = $user->id;
$preference->name = 'currencyPreference';
$preference->data = 'SOM';
$preference->save();
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($preference);
$code = $this->object->getCurrencyCode();
$this->assertEquals('EUR', $code);
}
/**
* @covers FireflyIII\Support\Amount::getCurrencySymbol
*/
public function testGetCurrencySymbol()
{
// will the the euro:
$eur = TransactionCurrency::whereCode('EUR')->first();
$result = $this->object->getCurrencySymbol();
$this->assertEquals($eur->symbol, $result);
}
/**
* @covers FireflyIII\Support\Amount::getDefaultCurrency
*/
public function testGetDefaultCurrency()
{
// will the the euro:
$eur = TransactionCurrency::whereCode('EUR')->first();
$result = $this->object->getDefaultCurrency();
$this->assertEquals($eur->id, $result->id);
}
}

View File

@ -0,0 +1,202 @@
<?php
use FireflyIII\Support\ExpandedForm;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class ExpandedFormTest
*/
class ExpandedFormTest extends TestCase
{
/**
* @var ExpandedForm
*/
protected $object;
/**
* 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->object = new ExpandedForm;
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
}
/**
* @covers FireflyIII\Support\ExpandedForm::amount
* @covers FireflyIII\Support\ExpandedForm::label
* @covers FireflyIII\Support\ExpandedForm::expandOptionArray
* @covers FireflyIII\Support\ExpandedForm::getHolderClasses
* @covers FireflyIII\Support\ExpandedForm::fillFieldValue
*/
public function testAmount()
{
$result = $this->object->amount('abcde', '12.23', ['label' => 'Some Label']);
$this->assertTrue(str_contains($result, '23'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::balance
* @covers FireflyIII\Support\ExpandedForm::label
*/
public function testBalance()
{
$result = $this->object->balance('abcde', '12.23', []);
$this->assertTrue(str_contains($result, '23'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::checkbox
* @covers FireflyIII\Support\ExpandedForm::getHolderClasses
*/
public function testCheckbox()
{
// add error to session for this thing:
$errors = new MessageBag;
$errors->add('abcde', 'Some error here.');
$this->session(['errors' => $errors]);
$result = $this->object->checkbox('abcde', 1, true);
$this->assertTrue(str_contains($result, 'checked="checked"'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::date
* @covers FireflyIII\Support\ExpandedForm::fillFieldValue
*/
public function testDate()
{
$preFilled = [
'abcde' => '1998-01-01'
];
$this->session(['preFilled' => $preFilled]);
$result = $this->object->date('abcde');
$this->assertTrue(str_contains($result, '1998'));
$this->assertTrue(str_contains($result, 'type="date"'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::integer
*/
public function testInteger()
{
$result = $this->object->integer('abcde', 12345);
$this->assertTrue(str_contains($result, '12345'));
$this->assertTrue(str_contains($result, 'type="number"'));
$this->assertTrue(str_contains($result, 'step="1"'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::location
*/
public function testLocation()
{
$result = $this->object->location('abcde');
$this->assertTrue(str_contains($result, 'id="clearLocation"'));
$this->assertTrue(str_contains($result, 'id="map-canvas"'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::makeSelectList
*/
public function testMakeSelectList()
{
$collection = new Collection;
for ($i = 0; $i < 5; $i++) {
$collection->push(FactoryMuffin::create('FireflyIII\Models\Account'));
}
$result = $this->object->makeSelectList($collection, true);
$this->assertCount(6, $result);
}
/**
* @covers FireflyIII\Support\ExpandedForm::multiRadio
*/
public function testMultiRadio()
{
$list = [
'some' => 'BlaBla',
'other' => 'ThisIsCool'
];
$result = $this->object->multiRadio('abcde', $list);
$this->assertTrue(str_contains($result, 'ThisIsCool'));
$this->assertTrue(str_contains($result, 'other'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::optionsList
*/
public function testOptionsList()
{
$result = $this->object->optionsList('update', 'MotorCycle');
$this->assertTrue(str_contains($result, 'MotorCycle'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::select
*/
public function testSelect()
{
$list = [
'some' => 'BlaBla',
'other' => 'ThisIsCool'
];
$result = $this->object->select('abcde', $list);
$this->assertTrue(str_contains($result, 'ThisIsCool'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::tags
*/
public function testTags()
{
$result = $this->object->tags('abcde', 'some,tags');
$this->assertTrue(str_contains($result, 'data-role="tagsinput"'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::text
*/
public function testText()
{
$result = $this->object->text('abcde', 'MotorBike!');
$this->assertTrue(str_contains($result, 'MotorBike!'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
/**
* @covers FireflyIII\Support\ExpandedForm::textarea
*/
public function testTextarea()
{
$result = $this->object->textarea('abcde', 'Pillow fight!');
$this->assertTrue(str_contains($result, 'Pillow fight!'));
$this->assertTrue(str_contains($result, 'abcde_holder'));
}
}

View File

@ -0,0 +1,287 @@
<?php
use Carbon\Carbon;
use FireflyIII\Support\Navigation;
/**
* Class NavigationTest
*/
class NavigationTest extends TestCase
{
/**
* @var Navigation
*/
protected $object;
/**
* 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->object = new Navigation;
}
/**
* @covers FireflyIII\Support\Navigation::addPeriod
*/
public function testAddPeriod()
{
$date = new Carbon('2015-01-01');
$result = $this->object->addPeriod($date, 'quarter', 0);
$this->assertEquals('2015-04-01', $result->format('Y-m-d'));
}
/**
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage Cannot do addPeriod for $repeat_freq "something"
* @covers FireflyIII\Support\Navigation::addPeriod
*/
public function testAddPeriodError()
{
$date = new Carbon('2015-01-01');
$this->object->addPeriod($date, 'something', 0);
}
/**
* @covers FireflyIII\Support\Navigation::endOfPeriod
*/
public function testEndOfPeriod()
{
$date = new Carbon('2015-01-01');
$result = $this->object->endOfPeriod($date, '1D');
$this->assertEquals('2015-01-02', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::endOfPeriod
*/
public function testEndOfPeriodModifier()
{
$date = new Carbon('2015-01-01');
$result = $this->object->endOfPeriod($date, 'quarter');
$this->assertEquals('2015-03-31', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::endOfPeriod
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage Cannot do endOfPeriod for $repeat_freq "something"
*/
public function testEndOfPeriodModifierError()
{
$date = new Carbon('2015-01-01');
$this->object->endOfPeriod($date, 'something');
}
/**
* @covers FireflyIII\Support\Navigation::endOfX
*/
public function testEndOfX()
{
$date = new Carbon('2015-01-01');
$maxEnd = new Carbon('2016-01-01');
$result = $this->object->endOfX($date, 'month', $maxEnd);
$this->assertEquals('2015-01-31', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::endOfX
*/
public function testEndOfXBeyondMax()
{
$date = new Carbon('2015-01-01');
$maxEnd = new Carbon('2015-01-15');
$result = $this->object->endOfX($date, 'monthly', $maxEnd);
$this->assertEquals('2015-01-15', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::periodShow
*/
public function testPeriodShow()
{
$date = new Carbon('2015-01-01');
$result = $this->object->periodShow($date, 'month');
$this->assertEquals('January 2015', $result);
}
/**
* @covers FireflyIII\Support\Navigation::periodShow
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage No date formats for frequency "something"
*/
public function testPeriodShowError()
{
$date = new Carbon('2015-01-01');
$this->object->periodShow($date, 'something');
}
/**
* @covers FireflyIII\Support\Navigation::startOfPeriod
*/
public function testStartOfPeriod()
{
$date = new Carbon('2015-01-15');
$result = $this->object->startOfPeriod($date, 'month');
$this->assertEquals('2015-01-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::startOfPeriod
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage Cannot do startOfPeriod for $repeat_freq "something"
*/
public function testStartOfPeriodError()
{
$date = new Carbon('2015-08-15');
$this->object->startOfPeriod($date, 'something');
}
/**
* @covers FireflyIII\Support\Navigation::startOfPeriod
*/
public function testStartOfPeriodHalfYear()
{
$date = new Carbon('2015-01-15');
$result = $this->object->startOfPeriod($date, 'half-year');
$this->assertEquals('2015-01-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::startOfPeriod
*/
public function testStartOfPeriodHalfYearSecondHalf()
{
$date = new Carbon('2015-08-15');
$result = $this->object->startOfPeriod($date, 'half-year');
$this->assertEquals('2015-07-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::subtractPeriod
*/
public function testSubtractPeriod()
{
$date = new Carbon('2015-01-01');
$result = $this->object->subtractPeriod($date, 'month');
$this->assertEquals('2014-12-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::subtractPeriod
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage Cannot do subtractPeriod for $repeat_freq "something"
*/
public function testSubtractPeriodError()
{
$date = new Carbon('2015-01-01');
$this->object->subtractPeriod($date, 'something');
}
/**
* @covers FireflyIII\Support\Navigation::subtractPeriod
*/
public function testSubtractPeriodQuarter()
{
$date = new Carbon('2015-01-01');
$result = $this->object->subtractPeriod($date, 'quarter');
$this->assertEquals('2014-10-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateEndDate
*/
public function testUpdateEndDate()
{
$date = new Carbon('2015-01-15');
$result = $this->object->updateEndDate('1M', $date);
$this->assertEquals('2015-01-31', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateEndDate
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage updateEndDate cannot handle $range "something"
*/
public function testUpdateEndDateError()
{
$date = new Carbon('2015-01-15');
$this->object->updateEndDate('something', $date);
}
/**
* @covers FireflyIII\Support\Navigation::updateEndDate
*/
public function testUpdateEndDateHalf()
{
$date = new Carbon('2015-01-15');
$result = $this->object->updateEndDate('6M', $date);
$this->assertEquals('2015-07-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateEndDate
*/
public function testUpdateEndDateSecondHalf()
{
$date = new Carbon('2015-08-15');
$result = $this->object->updateEndDate('6M', $date);
$this->assertEquals('2015-12-31', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateStartDate
*/
public function testUpdateStartDate()
{
$date = new Carbon('2015-01-15');
$result = $this->object->updateStartDate('1M', $date);
$this->assertEquals('2015-01-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateStartDate
*/
public function testUpdateStartDateHalf()
{
$date = new Carbon('2015-01-15');
$result = $this->object->updateStartDate('6M', $date);
$this->assertEquals('2015-01-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateStartDate
*/
public function testUpdateStartDateSecondHalf()
{
$date = new Carbon('2015-09-15');
$result = $this->object->updateStartDate('6M', $date);
$this->assertEquals('2015-07-01', $result->format('Y-m-d'));
}
/**
* @covers FireflyIII\Support\Navigation::updateStartDate
* @expectedException FireflyIII\Exceptions\FireflyException
* @expectedExceptionMessage updateStartDate cannot handle $range "something"
*/
public function testUpdateStartDateError()
{
$date = new Carbon('2015-09-15');
$this->object->updateStartDate('something', $date);
}
}

View File

@ -1,9 +0,0 @@
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit

View File

@ -1,2 +0,0 @@
<?php
// Here you can initialize variables that will be available to your tests