Code cleanup and tests.

This commit is contained in:
James Cole 2017-07-23 08:32:51 +02:00
parent 8bb7d5de3f
commit f85ab74e2b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
15 changed files with 72 additions and 90 deletions

View File

@ -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

View File

@ -10,6 +10,7 @@
*/
declare(strict_types=1);
use Carbon\Carbon;
use DaveJamesMiller\Breadcrumbs\Generator as BreadCrumbGenerator;
use FireflyIII\Exceptions\FireflyException;

View File

@ -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
*/

View File

@ -499,6 +499,7 @@ class ImportStorage
['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);
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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);