mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 04:21:20 +00:00
Improve test coverage and efficiency for accounts and budgets.
This commit is contained in:
@@ -22,11 +22,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Admin;
|
||||
|
||||
use Amount;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -44,14 +48,19 @@ class ConfigurationControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// for session
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
$this->be($this->user());
|
||||
$falseConfig = new Configuration;
|
||||
@@ -72,10 +81,19 @@ class ConfigurationControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\ConfigurationController
|
||||
* @covers \FireflyIII\Http\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testPostIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// for session
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
@@ -86,6 +104,7 @@ class ConfigurationControllerTest extends TestCase
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['single_user_mode', false])->once();
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['is_demo_site', false])->once();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.configuration.index.post'));
|
||||
|
||||
@@ -22,8 +22,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Admin;
|
||||
|
||||
use Amount;
|
||||
use Event;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@@ -49,6 +52,14 @@ class HomeControllerTest extends TestCase
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
// default for session
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
@@ -65,6 +76,13 @@ class HomeControllerTest extends TestCase
|
||||
public function testTestMessage(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$euro = $this->getEuro();
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
Amount::shouldReceive('getDefaultCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultPreferences();
|
||||
$this->mockDefaultConfiguration();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
@@ -29,6 +29,7 @@ use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
* Class LinkControllerTest
|
||||
@@ -50,6 +51,11 @@ class LinkControllerTest extends TestCase
|
||||
public function testCreate(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
@@ -66,17 +72,23 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
$newType = LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType]));
|
||||
$another= LinkType::where('editable', 0)->first();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType, $another]));
|
||||
$repository->shouldReceive('countJournals')->andReturn(2);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
$newType->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +100,9 @@ class LinkControllerTest extends TestCase
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->be($this->user());
|
||||
@@ -107,6 +122,10 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
||||
|
||||
@@ -126,10 +145,14 @@ class LinkControllerTest extends TestCase
|
||||
public function testEditEditable(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
|
||||
|
||||
@@ -145,10 +168,15 @@ class LinkControllerTest extends TestCase
|
||||
public function testEditNonEditable(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
||||
@@ -162,9 +190,13 @@ class LinkControllerTest extends TestCase
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
//Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$linkTypes = LinkType::inRandomOrder()->take(3)->get();
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
@@ -181,8 +213,11 @@ class LinkControllerTest extends TestCase
|
||||
public function testShow(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$repository->shouldReceive('getJournalLinks')->andReturn(new Collection);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
|
||||
$linkType = LinkType::first();
|
||||
@@ -203,10 +238,13 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(LinkType::first());
|
||||
$repository->shouldReceive('findNull')->andReturn(LinkType::first());
|
||||
@@ -230,10 +268,13 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'create_another' => '1',
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(new LinkType);
|
||||
@@ -260,10 +301,14 @@ class LinkControllerTest extends TestCase
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
@@ -284,12 +329,14 @@ class LinkControllerTest extends TestCase
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
@@ -314,10 +361,14 @@ class LinkControllerTest extends TestCase
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
||||
|
||||
// mock default session stuff
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . random_int(1, 10000),
|
||||
'inward' => 'test inward' . random_int(1, 10000),
|
||||
'outward' => 'test outward' . random_int(1, 10000),
|
||||
'name' => sprintf('test %d', $this->randomInt()),
|
||||
'inward' => sprintf('test inward %d', $this->randomInt()),
|
||||
'outward' => sprintf('test outward %d', $this->randomInt()),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
|
||||
@@ -52,25 +52,22 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
$config = new Configuration;
|
||||
$config->data = -1;
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
// mock update calls.
|
||||
$config = new Configuration;
|
||||
$config->data = -1;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
|
||||
// call service
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.update-check'));
|
||||
$response->assertStatus(200);
|
||||
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
@@ -79,17 +76,19 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testPost(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
// mock update calls
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['permission_update_check', 1])->once()->andReturn(new Configuration);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
// call service
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.update-check.post'), ['check_for_updates' => 1]);
|
||||
$response->assertSessionHas('success');
|
||||
@@ -103,16 +102,16 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateCheck(): void
|
||||
{
|
||||
// mock stuff
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// set some data
|
||||
$version = config('firefly.version');
|
||||
$date = new Carbon;
|
||||
$date->subDays(5);
|
||||
@@ -138,14 +137,13 @@ class UpdateControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateCheckCurrent(): void
|
||||
{
|
||||
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$date = new Carbon;
|
||||
@@ -175,13 +173,10 @@ class UpdateControllerTest extends TestCase
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$version = config('firefly.version') . '-alpha';
|
||||
$releases = [];
|
||||
$updater = $this->mock(UpdateRequest::class);
|
||||
$updater->shouldReceive('call')->andThrow(FireflyException::class, 'Something broke.');
|
||||
@@ -203,10 +198,8 @@ class UpdateControllerTest extends TestCase
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$falseConfig = new Configuration;
|
||||
$falseConfig->data = false;
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
|
||||
FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
|
||||
|
||||
$version = config('firefly.version') . '-alpha';
|
||||
|
||||
@@ -26,6 +26,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,9 @@ class UserControllerTest extends TestCase
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -67,6 +71,8 @@ class UserControllerTest extends TestCase
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.users.destroy', ['2']));
|
||||
$response->assertStatus(302);
|
||||
@@ -81,6 +87,9 @@ class UserControllerTest extends TestCase
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(2)->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -98,6 +107,15 @@ class UserControllerTest extends TestCase
|
||||
$user = $this->user();
|
||||
$repository->shouldReceive('all')->andReturn(new Collection([$user]));
|
||||
|
||||
Preferences::shouldReceive('getArrayForUser')->atLeast()->once()->andReturn(
|
||||
[
|
||||
'twoFactorAuthEnabled' => false,
|
||||
'twoFactorAuthSecret' => null,
|
||||
]
|
||||
);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($user);
|
||||
$response = $this->get(route('admin.users'));
|
||||
$response->assertStatus(200);
|
||||
@@ -120,6 +138,8 @@ class UserControllerTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.users.show', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -129,6 +149,7 @@ class UserControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\UserController
|
||||
* @covers \FireflyIII\Http\Requests\UserFormRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@@ -138,6 +159,10 @@ class UserControllerTest extends TestCase
|
||||
$repository->shouldReceive('updateEmail')->once();
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
$this->mockDefaultSession();
|
||||
Preferences::shouldReceive('mark');
|
||||
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'email' => 'test@example.com',
|
||||
|
||||
Reference in New Issue
Block a user