mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 12:15:55 +00:00
Refactored a lot of tests.
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@@ -30,6 +31,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -52,21 +54,44 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\PreferencesController
|
||||
* @covers \FireflyIII\Http\Controllers\PreferencesController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$this->mockIntroPreference('shown_demo_preferences_index');
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
|
||||
|
||||
// mock get preferences:
|
||||
|
||||
$frontPage = new Preference;
|
||||
$frontPage->data = [];
|
||||
Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', []])->andReturn($frontPage)->atLeast()->once();
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = 50;
|
||||
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = 0;
|
||||
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', 0])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = '01-01';
|
||||
Preferences::shouldReceive('get')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$pref = new Preference;
|
||||
$pref->data = [];
|
||||
Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('preferences.index'));
|
||||
$response->assertStatus(200);
|
||||
@@ -78,6 +103,7 @@ class PreferencesControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostIndex(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
@@ -95,6 +121,16 @@ class PreferencesControllerTest extends TestCase
|
||||
'tj' => [],
|
||||
];
|
||||
|
||||
Preferences::shouldReceive('set')->withArgs(['frontPageAccounts', [1]])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['viewRange', '1M'])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['customFiscalYear', false])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['fiscalYearStart', '01-01'])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['listPageSize', 100])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['listPageSize', 50])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['language', 'en_US'])->atLeast()->once();
|
||||
Preferences::shouldReceive('set')->withArgs(['transaction_journal_optional_fields', Mockery::any()])->atLeast()->once();
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('preferences.update'), $data);
|
||||
$response->assertStatus(302);
|
||||
|
||||
Reference in New Issue
Block a user