diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index c881b6ce83..49f52942af 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -270,8 +270,8 @@ class AccountController extends Controller // prep for current period if (strlen($moment) === 0) { - $start = session('start', Navigation::startOfPeriod(new Carbon, $range)); - $end = session('end', Navigation::endOfPeriod(new Carbon, $range)); + $start = clone session('start', Navigation::startOfPeriod(new Carbon, $range)); + $end = clone session('end', Navigation::endOfPeriod(new Carbon, $range)); $periods = $this->periodEntries($account); } diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 2235b32e67..b238ad4bf8 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -33,21 +33,36 @@ $factory->define( } ); +$factory->define( + FireflyIII\Models\Account::class, function (Faker\Generator $faker) { + return [ + 'id' => $faker->numberBetween(1, 10), + 'name' => $faker->words(3, true), + ]; +} +); + $factory->define( FireflyIII\Models\Transaction::class, function (Faker\Generator $faker) { return [ - 'transaction_amount' => strval($faker->randomFloat(2, -100, 100)), - 'destination_amount' => strval($faker->randomFloat(2, -100, 100)), - 'opposing_account_id' => $faker->numberBetween(1, 10), - 'source_account_id' => $faker->numberBetween(1, 10), - 'opposing_account_name' => $faker->words(3, true), - 'description' => $faker->words(3, true), - 'source_account_name' => $faker->words(3, true), - 'destination_account_id' => $faker->numberBetween(1, 10), - 'destination_account_name' => $faker->words(3, true), - 'amount' => strval($faker->randomFloat(2, -100, 100)), - 'budget_id' => 0, - 'category' => $faker->words(3, true), + 'transaction_amount' => strval($faker->randomFloat(2, -100, 100)), + 'destination_amount' => strval($faker->randomFloat(2, -100, 100)), + 'opposing_account_id' => $faker->numberBetween(1, 10), + 'source_account_id' => $faker->numberBetween(1, 10), + 'opposing_account_name' => $faker->words(3, true), + 'description' => $faker->words(3, true), + 'source_account_name' => $faker->words(3, true), + 'destination_account_id' => $faker->numberBetween(1, 10), + 'destination_account_name' => $faker->words(3, true), + 'amount' => strval($faker->randomFloat(2, -100, 100)), + 'budget_id' => 0, + 'category' => $faker->words(3, true), + 'transaction_journal_id' => $faker->numberBetween(1, 10), + 'journal_id' => $faker->numberBetween(1, 10), + 'transaction_currency_code' => 'EUR', + 'transaction_type_type' => 'Withdrawal', + 'account_encrypted' => 0, + 'account_name' => 'Some name', ]; } ); \ No newline at end of file diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.php index f8a79adfed..e15ca29237 100644 --- a/tests/Feature/Controllers/AccountControllerTest.php +++ b/tests/Feature/Controllers/AccountControllerTest.php @@ -14,10 +14,14 @@ namespace Tests\Feature\Controllers; use Carbon\Carbon; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\Account; +use FireflyIII\Models\AccountType; +use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountTaskerInterface; +use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; +use Steam; use Tests\TestCase; class AccountControllerTest extends TestCase @@ -27,6 +31,11 @@ class AccountControllerTest extends TestCase */ public function testCreate() { + // mock stuff + $collector = $this->mock(JournalCollectorInterface::class); + $repository = $this->mock(CurrencyRepositoryInterface::class); + $repository->shouldReceive('get')->andReturn(new Collection); + $this->be($this->user()); $response = $this->get(route('accounts.create', ['asset'])); $response->assertStatus(200); @@ -39,6 +48,12 @@ class AccountControllerTest extends TestCase */ public function testDelete() { + // mock stuff + $collector = $this->mock(JournalCollectorInterface::class); + $repository = $this->mock(AccountRepositoryInterface::class); + $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection); + + $this->be($this->user()); $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); $response = $this->get(route('accounts.delete', [$account->id])); @@ -52,13 +67,15 @@ class AccountControllerTest extends TestCase */ public function testDestroy() { - $this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']); - - $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); + // mock stuff + $collector = $this->mock(JournalCollectorInterface::class); $repository = $this->mock(AccountRepositoryInterface::class); $repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account); $repository->shouldReceive('destroy')->andReturn(true); + $this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']); + $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); + $this->be($this->user()); $response = $this->post(route('accounts.destroy', [$account->id])); $response->assertStatus(302); @@ -70,6 +87,11 @@ class AccountControllerTest extends TestCase */ public function testEdit() { + // mock stuff + $collector = $this->mock(JournalCollectorInterface::class); + $repository = $this->mock(CurrencyRepositoryInterface::class); + $repository->shouldReceive('get')->andReturn(new Collection); + $this->be($this->user()); $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); $response = $this->get(route('accounts.edit', [$account->id])); @@ -88,6 +110,13 @@ class AccountControllerTest extends TestCase */ public function testIndex(string $range) { + // mock stuff + $account = factory(Account::class)->make(); + $repository = $this->mock(AccountRepositoryInterface::class); + $repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])); + Steam::shouldReceive('balancesById')->andReturn([]); + Steam::shouldReceive('getLastActivities')->andReturn([]); + $this->be($this->user()); $this->changeDateRange($this->user(), $range); $response = $this->get(route('accounts.index', ['asset'])); @@ -96,37 +125,6 @@ class AccountControllerTest extends TestCase $response->assertSee('