Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix tests that broke during Laravel 5.6 upgrade
James Cole04b2eaf53539
diff --git a/tests/Feature/Controllers/ExportControllerTest.php b/tests/Feature/Controllers/ExportControllerTest.phpindex 480a58b73f..0fae59774e 100644--- a/tests/Feature/Controllers/ExportControllerTest.php+++ b/tests/Feature/Controllers/ExportControllerTest.php@@ -102,8 +102,9 @@ class ExportControllerTest extends TestCase$repository = $this->mock(ExportJobRepositoryInterface::class);$accountRepos = $this->mock(AccountRepositoryInterface::class);$journalRepos = $this->mock(JournalRepositoryInterface::class);+ $job = ExportJob::first();$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);- $repository->shouldReceive('create')->andReturn(new ExportJob);+ $repository->shouldReceive('create')->andReturn($job);$repository->shouldReceive('cleanup');$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);diff --git a/tests/Feature/Controllers/Json/BoxControllerTest.php b/tests/Feature/Controllers/Json/BoxControllerTest.phpindex 19449b1d62..40ce31cea0 100644--- a/tests/Feature/Controllers/Json/BoxControllerTest.php+++ b/tests/Feature/Controllers/Json/BoxControllerTest.php@@ -100,7 +100,7 @@ class BoxControllerTest extends TestCase{$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));+ $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));$this->be($this->user());$response = $this->get(route('json.box.net-worth'));@@ -114,7 +114,7 @@ class BoxControllerTest extends TestCase{$accountRepos = $this->mock(AccountRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));+ $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));$start = new Carbon;diff --git a/tests/Feature/Controllers/PreferencesControllerTest.php b/tests/Feature/Controllers/PreferencesControllerTest.phpindex 749b162a4a..7aef05dbd8 100644--- a/tests/Feature/Controllers/PreferencesControllerTest.php+++ b/tests/Feature/Controllers/PreferencesControllerTest.php@@ -41,41 +41,6 @@ use Tests\TestCase;*/class PreferencesControllerTest extends TestCase{- /**- * @covers \FireflyIII\Http\Controllers\PreferencesController::code- * @covers \FireflyIII\Http\Controllers\PreferencesController::getDomain- */- public function testCode()- {- // mock stuff- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);- Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');- Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');-- $this->be($this->user());- $response = $this->get(route('preferences.code'));- $response->assertStatus(200);- $response->assertSee('<ol class="breadcrumb">');- }-- /**- * @covers \FireflyIII\Http\Controllers\PreferencesController::deleteCode- */- public function testDeleteCode()- {- // mock stuff- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);-- $this->be($this->user());- $response = $this->get(route('preferences.delete-code'));- $response->assertStatus(302);- $response->assertSessionHas('success');- $response->assertSessionHas('info');- $response->assertRedirect(route('preferences.index'));- }-/*** @covers \FireflyIII\Http\Controllers\PreferencesController::index* @covers \FireflyIII\Http\Controllers\PreferencesController::__construct@@ -94,33 +59,6 @@ class PreferencesControllerTest extends TestCase$response->assertSee('<ol class="breadcrumb">');}- /**- *- */- public function testPostCode()- {- $secret = '0123456789abcde';- $key = '123456';-- $this->withoutMiddleware();- $this->session(['two-factor-secret' => $secret]);-- Preferences::shouldReceive('set')->withArgs(['twoFactorAuthEnabled', 1])->once();- Preferences::shouldReceive('set')->withArgs(['twoFactorAuthSecret', $secret])->once();- Preferences::shouldReceive('mark')->once();-- Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);-- $data = [- 'code' => $key,- ];-- $this->be($this->user());- $response = $this->post(route('preferences.code.store'), $data);- $response->assertStatus(302);- $response->assertSessionHas('success');- }-/*** @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex*/@@ -139,7 +77,6 @@ class PreferencesControllerTest extends TestCase'customFiscalYear' => 0,'showDepositsFrontpage' => 0,'listPageSize' => 100,- 'twoFactorAuthEnabled' => 0,'language' => 'en_US','tj' => [],];@@ -150,80 +87,4 @@ class PreferencesControllerTest extends TestCase$response->assertSessionHas('success');$response->assertRedirect(route('preferences.index'));}-- /**- * User wants 2FA and has secret already.- *- * @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex- */- public function testPostIndexWith2FA()- {- $this->withoutMiddleware();- // mock stuff- $userRepos = $this->mock(UserRepositoryInterface::class);- $userRepos->shouldReceive('hasRole')->andReturn(false);-- // mock preferences (in a useful way?)- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn('12345');- Preferences::shouldReceive('set');- Preferences::shouldReceive('mark');-- $data = [- 'fiscalYearStart' => '2016-01-01',- 'frontPageAccounts' => [1],- 'viewRange' => '1M',- 'customFiscalYear' => 0,- 'showDepositsFrontpage' => 0,- 'listPageSize' => 100,- 'twoFactorAuthEnabled' => 1,- 'language' => 'en_US',- 'tj' => [],- ];-- $this->be($this->user());- $response = $this->post(route('preferences.update'), $data);- $response->assertStatus(302);- $response->assertSessionHas('success');-- // go to code to get a secret.- $response->assertRedirect(route('preferences.index'));- }-- /**- * User wants 2FA and has no secret.- *- * @covers \FireflyIII\Http\Controllers\PreferencesController::postIndex- */- public function testPostIndexWithEmpty2FA()- {- $this->withoutMiddleware();- // mock stuff- $userRepos = $this->mock(UserRepositoryInterface::class);- $userRepos->shouldReceive('hasRole')->andReturn(false);-- // mock preferences (in a useful way?)- Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->andReturn(null);- Preferences::shouldReceive('set');- Preferences::shouldReceive('mark');-- $data = [- 'fiscalYearStart' => '2016-01-01',- 'frontPageAccounts' => [1],- 'viewRange' => '1M',- 'customFiscalYear' => 0,- 'showDepositsFrontpage' => 0,- 'listPageSize' => 100,- 'twoFactorAuthEnabled' => 1,- 'language' => 'en_US',- 'tj' => [],- ];-- $this->be($this->user());- $response = $this->post(route('preferences.update'), $data);- $response->assertStatus(302);- $response->assertSessionHas('success');-- // go to code to get a secret.- $response->assertRedirect(route('preferences.code'));- }}diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.phpindex ac1967f7f0..4bd6b25435 100644--- a/tests/Feature/Controllers/ProfileControllerTest.php+++ b/tests/Feature/Controllers/ProfileControllerTest.php@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\User\UserRepositoryInterface;use FireflyIII\User;+use Google2FA;use Illuminate\Support\Collection;use Preferences;use Tests\TestCase;@@ -40,6 +41,71 @@ use Tests\TestCase;*/class ProfileControllerTest extends TestCase{+ /**+ * @covers \FireflyIII\Http\Controllers\ProfileController::code+ * @covers \FireflyIII\Http\Controllers\ProfileController::getDomain+ */+ public function testCode()+ {+ // mock stuff+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);+ Google2FA::shouldReceive('generateSecretKey')->andReturn('secret');+ Google2FA::shouldReceive('getQRCodeInline')->andReturn('long-data-url');++ $this->be($this->user());+ $response = $this->get(route('profile.code'));+ $response->assertStatus(200);+ $response->assertSee('<ol class="breadcrumb">');+ }++++ /**+ * @covers \FireflyIII\Http\Controllers\ProfileController::deleteCode+ */+ public function testDeleteCode()+ {+ // mock stuff+ $journalRepos = $this->mock(JournalRepositoryInterface::class);+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);++ $this->be($this->user());+ $response = $this->get(route('profile.delete-code'));+ $response->assertStatus(302);+ $response->assertSessionHas('success');+ $response->assertSessionHas('info');+ $response->assertRedirect(route('profile.index'));+ }++ /**+ * @covers \FireflyIII\Http\Controllers\ProfileController::postCode+ */+ public function testPostCode()+ {+ $secret = '0123456789abcde';+ $key = '123456';++ $this->withoutMiddleware();+ $this->session(['two-factor-secret' => $secret]);++ Preferences::shouldReceive('set')->withArgs(['twoFactorAuthEnabled', 1])->once();+ Preferences::shouldReceive('set')->withArgs(['twoFactorAuthSecret', $secret])->once();+ Preferences::shouldReceive('mark')->once();++ Google2FA::shouldReceive('verifyKey')->withArgs([$secret, $key])->andReturn(true);++ $data = [+ 'code' => $key,+ ];++ $this->be($this->user());+ $response = $this->post(route('profile.code.store'), $data);+ $response->assertStatus(302);+ $response->assertSessionHas('success');+ }++/*** @covers \FireflyIII\Http\Controllers\ProfileController::changeEmail()diff --git a/tests/Feature/Controllers/Report/ExpenseControllerTest.php b/tests/Feature/Controllers/Report/ExpenseControllerTest.phpindex 0e30a56b41..02b3b6bf76 100644--- a/tests/Feature/Controllers/Report/ExpenseControllerTest.php+++ b/tests/Feature/Controllers/Report/ExpenseControllerTest.php@@ -208,6 +208,7 @@ class ExpenseControllerTest extends TestCase$transA->transaction_currency_symbol = 'A';$transA->transaction_currency_dp = 2;$transA->transaction_amount = '100';+ $transA->opposing_account_id = $expense->id;$transB = new Transaction;$transB->transaction_currency_id = 2;$transB->transaction_category_name = null;@@ -217,6 +218,7 @@ class ExpenseControllerTest extends TestCase$transB->transaction_currency_symbol = 'A';$transB->transaction_currency_dp = 2;$transB->transaction_amount = '100';+ $transB->opposing_account_id = $expense->id;$collection = new Collection([$transA, $transB]);// mock collector for topExpense (complex)diff --git a/tests/Unit/Middleware/AuthenticateTest.php b/tests/Unit/Middleware/AuthenticateTest.phpindex b1022269dc..33051d6112 100644--- a/tests/Unit/Middleware/AuthenticateTest.php+++ b/tests/Unit/Middleware/AuthenticateTest.php@@ -51,7 +51,7 @@ class AuthenticateTest extends TestCaseLog::debug('Now at testMiddlewareAjax');$server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];$response = $this->get('/_test/authenticate', $server);- $this->assertEquals(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());+ $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());}/**