mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup and tests.
This commit is contained in:
parent
8bb7d5de3f
commit
f85ab74e2b
@ -27,11 +27,10 @@ use Route;
|
||||
*/
|
||||
class Help implements HelpInterface
|
||||
{
|
||||
const CACHEKEY = 'help_%s_%s';
|
||||
/** @var string */
|
||||
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
|
||||
|
||||
const CACHEKEY = 'help_%s_%s';
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
|
@ -138,14 +138,14 @@ class HomeController extends Controller
|
||||
}
|
||||
|
||||
return view(
|
||||
'index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount')
|
||||
'index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage', 'billCount')
|
||||
);
|
||||
}
|
||||
|
||||
public function routes()
|
||||
{
|
||||
$set = RouteFacade::getRoutes();
|
||||
$ignore = ['chart.','javascript.','json.','report-data.','popup.','debugbar.'];
|
||||
$ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.'];
|
||||
/** @var Route $route */
|
||||
foreach ($set as $route) {
|
||||
$name = $route->getName();
|
||||
@ -157,7 +157,7 @@ class HomeController extends Controller
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
echo 'touch '.$route->getName() . '.md;';
|
||||
echo 'touch ' . $route->getName() . '.md;';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class PiggyBankController extends Controller
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
$leftOnAccount = $piggyBank->leftOnAccount($date);
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount?? '0';
|
||||
$savedSoFar = $piggyBank->currentRelevantRep()->currentamount ?? '0';
|
||||
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
|
||||
$maxAmount = min($leftOnAccount, $leftToSave);
|
||||
|
||||
|
@ -213,11 +213,11 @@ class MassController extends Controller
|
||||
if ($journal) {
|
||||
// get optional fields:
|
||||
$what = strtolower($journal->transactionTypeStr());
|
||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||
$sourceAccountId = $request->get('source_account_id')[$journal->id] ?? 0;
|
||||
$sourceAccountName = $request->get('source_account_name')[$journal->id] ?? '';
|
||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||
$destAccountId = $request->get('destination_account_id')[$journal->id] ?? 0;
|
||||
$destAccountName = $request->get('destination_account_name')[$journal->id] ?? '';
|
||||
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
|
||||
$budgetId = $request->get('budget_id')[$journal->id] ?? 0;
|
||||
$category = $request->get('category')[$journal->id];
|
||||
$tags = $journal->tags->pluck('tag')->toArray();
|
||||
$amount = round($request->get('amount')[$journal->id], 12);
|
||||
|
@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DaveJamesMiller\Breadcrumbs\Generator as BreadCrumbGenerator;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
|
@ -180,8 +180,8 @@ class ImportBill
|
||||
|
||||
Log::debug('Finding a mapped bill based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$bill = $this->repository->find($search);
|
||||
$search = intval($array['mapped']);
|
||||
$bill = $this->repository->find($search);
|
||||
|
||||
if (is_null($bill->id)) {
|
||||
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
@ -180,7 +180,7 @@ class ImportBudget
|
||||
|
||||
Log::debug('Finding a mapped budget based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$search = intval($array['mapped']);
|
||||
$budget = $this->repository->find($search);
|
||||
|
||||
if (is_null($budget->id)) {
|
||||
|
@ -174,7 +174,7 @@ class ImportCategory
|
||||
|
||||
Log::debug('Finding a mapped category based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$search = intval($array['mapped']);
|
||||
$category = $this->repository->find($search);
|
||||
|
||||
if (is_null($category->id)) {
|
||||
|
@ -65,19 +65,6 @@ class ImportJournal
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if ($this->description === '') {
|
||||
return '(no description)';
|
||||
}
|
||||
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ImportEntry constructor.
|
||||
*/
|
||||
@ -157,6 +144,18 @@ class ImportJournal
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if ($this->description === '') {
|
||||
return '(no description)';
|
||||
}
|
||||
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
*/
|
||||
|
@ -474,31 +474,32 @@ class ImportStorage
|
||||
private function verifyDoubleTransfer(TransactionType $transactionType, ImportJournal $importJournal): bool
|
||||
{
|
||||
if ($transactionType->type === TransactionType::TRANSFER) {
|
||||
$amount = Steam::positive($importJournal->getAmount());
|
||||
$date = $importJournal->getDate($this->dateFormat);
|
||||
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin(
|
||||
'transactions AS source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where(
|
||||
'destination.amount', '>', 0
|
||||
);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id')
|
||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->where('destination.amount', $amount)
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name']
|
||||
);
|
||||
$amount = Steam::positive($importJournal->getAmount());
|
||||
$date = $importJournal->getDate($this->dateFormat);
|
||||
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin(
|
||||
'transactions AS source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where(
|
||||
'destination.amount', '>', 0
|
||||
);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id')
|
||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->where('destination.amount', $amount)
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name']
|
||||
);
|
||||
|
||||
return $this->filterTransferSet($set, $importJournal);
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ class Amount
|
||||
$coloured = false;
|
||||
$format = '<span class="text-info">%s</span>';
|
||||
}
|
||||
if($transaction->transaction_type_type === TransactionType::OPENING_BALANCE) {
|
||||
if ($transaction->transaction_type_type === TransactionType::OPENING_BALANCE) {
|
||||
$amount = strval($transaction->transaction_amount);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class Roles implements ConfigurationInterface
|
||||
$count = $config['column-count'];
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$role = $config['column-roles'][$i] ?? '_ignore';
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
|
||||
if ($role === '_ignore' && $mapping === true) {
|
||||
$mapping = false;
|
||||
@ -160,7 +160,7 @@ class Roles implements ConfigurationInterface
|
||||
$count = $config['column-count'];
|
||||
$toBeMapped = 0;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
$mapping = $config['column-do-mapping'][$i] ?? false;
|
||||
if ($mapping === true) {
|
||||
$toBeMapped++;
|
||||
}
|
||||
|
@ -249,21 +249,6 @@ class Steam
|
||||
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function tryDecrypt($value)
|
||||
{
|
||||
try {
|
||||
$value = Crypt::decrypt($value);
|
||||
} catch (DecryptException $e) {
|
||||
// do not care.
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accounts
|
||||
@ -361,4 +346,20 @@ class Steam
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function tryDecrypt($value)
|
||||
{
|
||||
try {
|
||||
$value = Crypt::decrypt($value);
|
||||
} catch (DecryptException $e) {
|
||||
// do not care.
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,10 +41,6 @@ class TwoFactorControllerTest extends TestCase
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
|
||||
$falsePref = new Preference;
|
||||
$falsePref->data = false;
|
||||
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once();
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
@ -61,7 +57,6 @@ class TwoFactorControllerTest extends TestCase
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePreference)->once();
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(302);
|
||||
@ -84,10 +79,6 @@ class TwoFactorControllerTest extends TestCase
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference)->once();
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference)->once();
|
||||
|
||||
$falsePref = new Preference;
|
||||
$falsePref->data = false;
|
||||
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.index', false])->andReturn($falsePref)->once();
|
||||
|
||||
$response = $this->get(route('two-factor.index'));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
@ -107,10 +98,6 @@ class TwoFactorControllerTest extends TestCase
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn($secretPreference);
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn($secretPreference);
|
||||
|
||||
$falsePref = new Preference;
|
||||
$falsePref->data = false;
|
||||
Preferences::shouldReceive('get')->withArgs(['shown_demo_two-factor.lost', false])->andReturn($falsePref)->once();
|
||||
|
||||
$response = $this->get(route('two-factor.lost'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
@ -56,12 +56,9 @@ class HelpControllerTest extends TestCase
|
||||
$help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
|
||||
|
||||
// is US in cache?
|
||||
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->twice();
|
||||
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(true)->once();
|
||||
$help->shouldReceive('getFromCache')->withArgs(['index', 'en_US'])->andReturn('US from cache.')->once();
|
||||
|
||||
// put US in cache:
|
||||
$help->shouldReceive('putInCache')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('help.show', ['index']));
|
||||
$response->assertStatus(200);
|
||||
@ -87,12 +84,9 @@ class HelpControllerTest extends TestCase
|
||||
$help->shouldReceive('getFromGithub')->withArgs(['index', 'nl_NL'])->andReturn('')->once();
|
||||
|
||||
// is US in cache?
|
||||
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->twice();
|
||||
$help->shouldReceive('inCache')->withArgs(['index', 'en_US'])->andReturn(false)->once();
|
||||
$help->shouldReceive('getFromGithub')->withArgs(['index', 'en_US'])->andReturn('')->once();
|
||||
|
||||
// put US in cache:
|
||||
$help->shouldReceive('putInCache')->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('help.show', ['index']));
|
||||
$response->assertStatus(200);
|
||||
|
Loading…
Reference in New Issue
Block a user