mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 02:52:44 +00:00
Fix test coverage.
This commit is contained in:
@@ -44,7 +44,7 @@ class InterestingMessage
|
|||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next)
|
public function handle(Request $request, Closure $next)
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('Interesting Message middleware for URI %s', $request->url()));
|
//Log::debug(sprintf('Interesting Message middleware for URI %s', $request->url()));
|
||||||
if ($this->testing()) {
|
if ($this->testing()) {
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ use FireflyIII\Models\Budget;
|
|||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
use Illuminate\Contracts\Validation\Rule;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BelongsUser
|
* Class BelongsUser
|
||||||
@@ -78,6 +79,7 @@ class BelongsUser implements Rule
|
|||||||
return true; // @codeCoverageIgnore
|
return true; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$attribute = (string)$attribute;
|
$attribute = (string)$attribute;
|
||||||
|
Log::debug(sprintf('Going to validate %s', $attribute));
|
||||||
switch ($attribute) {
|
switch ($attribute) {
|
||||||
case 'piggy_bank_id':
|
case 'piggy_bank_id':
|
||||||
return $this->validatePiggyBankId((int)$value);
|
return $this->validatePiggyBankId((int)$value);
|
||||||
@@ -112,6 +114,7 @@ class BelongsUser implements Rule
|
|||||||
*/
|
*/
|
||||||
protected function countField(string $class, string $field, string $value): int
|
protected function countField(string $class, string $field, string $value): int
|
||||||
{
|
{
|
||||||
|
$value = trim($value);
|
||||||
$objects = [];
|
$objects = [];
|
||||||
// get all objects belonging to user:
|
// get all objects belonging to user:
|
||||||
if (PiggyBank::class === $class) {
|
if (PiggyBank::class === $class) {
|
||||||
@@ -124,8 +127,11 @@ class BelongsUser implements Rule
|
|||||||
}
|
}
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($objects as $object) {
|
foreach ($objects as $object) {
|
||||||
if (trim((string)$object->$field) === trim($value)) {
|
$objectValue = trim((string)$object->$field);
|
||||||
|
Log::debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value));
|
||||||
|
if ($objectValue === $value) {
|
||||||
$count++;
|
$count++;
|
||||||
|
Log::debug(sprintf('Hit! Count is now %d', $count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,6 +188,7 @@ class BelongsUser implements Rule
|
|||||||
private function validateBillName(string $value): bool
|
private function validateBillName(string $value): bool
|
||||||
{
|
{
|
||||||
$count = $this->countField(Bill::class, 'name', $value);
|
$count = $this->countField(Bill::class, 'name', $value);
|
||||||
|
Log::debug(sprintf('Result of countField for bill name "%s" is %d', $value, $count));
|
||||||
|
|
||||||
return 1 === $count;
|
return 1 === $count;
|
||||||
}
|
}
|
||||||
|
@@ -98,9 +98,6 @@ class ProfileControllerTest extends TestCase
|
|||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
|
||||||
|
|
||||||
// set recovery codes.
|
|
||||||
Preferences::shouldReceive('set')->withArgs(['mfa_recovery', Mockery::any()])->atLeast()->once();
|
|
||||||
|
|
||||||
Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');
|
Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');
|
||||||
Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');
|
Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');
|
||||||
|
|
||||||
@@ -448,6 +445,16 @@ class ProfileControllerTest extends TestCase
|
|||||||
|
|
||||||
$userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), $secret])->atLeast()->once();
|
$userRepos->shouldReceive('setMFACode')->withArgs([Mockery::any(), $secret])->atLeast()->once();
|
||||||
|
|
||||||
|
// set recovery history
|
||||||
|
Preferences::shouldReceive('set')->withArgs(['mfa_history', Mockery::any()])->atLeast()->once();
|
||||||
|
|
||||||
|
// set recovery codes.
|
||||||
|
Preferences::shouldReceive('set')->withArgs(['mfa_recovery', null])->atLeast()->once();
|
||||||
|
|
||||||
|
$pref = new Preference;
|
||||||
|
$pref->data= [];
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['mfa_history', []])->atLeast()->once()->andReturn($pref);
|
||||||
|
|
||||||
Preferences::shouldReceive('mark')->once();
|
Preferences::shouldReceive('mark')->once();
|
||||||
Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
|
Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);
|
||||||
|
|
||||||
|
@@ -50,6 +50,7 @@ class CreateControllerTest extends TestCase
|
|||||||
public function testCreate(): void
|
public function testCreate(): void
|
||||||
{
|
{
|
||||||
$this->mockDefaultSession();
|
$this->mockDefaultSession();
|
||||||
|
$this->mockIntroPreference('shown_demo_transactions_create_withdrawal');
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
$cash = $this->getRandomAsset();
|
$cash = $this->getRandomAsset();
|
||||||
@@ -63,7 +64,7 @@ class CreateControllerTest extends TestCase
|
|||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('transactions.create'));
|
$response = $this->get(route('transactions.create', ['withdrawal']));
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -133,7 +133,7 @@ class LinkControllerTest extends TestCase
|
|||||||
|
|
||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
$response->assertSessionHas('success');
|
$response->assertSessionHas('success');
|
||||||
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
$response->assertRedirect(route('transactions.show', [$withdrawal->transaction_group_id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -90,6 +90,8 @@ class BelongsUserTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$this->assertTrue($engine->passes($attribute, $value));
|
$this->assertTrue($engine->passes($attribute, $value));
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
Log::error($e->getTraceAsString());
|
||||||
$this->assertTrue(false, $e->getMessage());
|
$this->assertTrue(false, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user