| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * AccountControllerTest.php | 
					
						
							|  |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2017-12-17 14:42:21 +01:00
										 |  |  |  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | namespace Tests\Feature\Controllers; | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use FireflyIII\Helpers\Collector\JournalCollectorInterface; | 
					
						
							|  |  |  | use FireflyIII\Models\Account; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | use FireflyIII\Models\AccountType; | 
					
						
							| 
									
										
										
										
											2017-12-31 10:40:27 +01:00
										 |  |  | use FireflyIII\Models\Note; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | use FireflyIII\Models\Transaction; | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Account\AccountTaskerInterface; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
					
						
							|  |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2017-11-26 09:54:09 +01:00
										 |  |  | use Preferences; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | use Steam; | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class AccountControllerTest | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-08-12 10:27:45 +02:00
										 |  |  |  * @SuppressWarnings(PHPMD.TooManyPublicMethods) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | class AccountControllerTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::create | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testCreate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(CurrencyRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('get')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.create', ['asset'])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::delete | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::rememberPreviousUri | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testDelete() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-02-22 20:35:31 +01:00
										 |  |  |         $account  = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.delete', [$account->id])); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::destroy | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::__construct | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testDestroy() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account); | 
					
						
							|  |  |  |         $repository->shouldReceive('destroy')->andReturn(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['accounts.delete.uri' => 'http://localhost/accounts/show/1']); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-02-22 20:35:31 +01:00
										 |  |  |         $response = $this->post(route('accounts.destroy', [$account->id])); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::edit | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testEdit() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-31 10:40:27 +01:00
										 |  |  |         $note = new Note(); | 
					
						
							|  |  |  |         $note->text = 'This is a test'; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(CurrencyRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-12-31 10:40:27 +01:00
										 |  |  |         $accountRepos = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('get')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  |         $repository->shouldReceive('find')->once()->andReturn(new TransactionCurrency()); | 
					
						
							| 
									
										
										
										
											2017-12-31 10:40:27 +01:00
										 |  |  |         $accountRepos->shouldReceive('getNote')->andReturn($note)->once(); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-02-22 20:35:31 +01:00
										 |  |  |         $account  = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first(); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.edit', [$account->id])); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							| 
									
										
										
										
											2017-12-31 10:40:27 +01:00
										 |  |  |         $response->assertSee($note->text); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::index | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:38 +01:00
										 |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::__construct | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::isInArray | 
					
						
							|  |  |  |      * @dataProvider dateRangeProvider | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $range | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testIndex(string $range) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $account      = factory(Account::class)->make(); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-06-05 22:11:54 +02:00
										 |  |  |         Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         Steam::shouldReceive('getLastActivities')->andReturn([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $this->changeDateRange($this->user(), $range); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.index', ['asset'])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::show | 
					
						
							| 
									
										
										
										
											2017-03-18 08:09:14 +01:00
										 |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::getPeriodOverview | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      * @dataProvider dateRangeProvider | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $range | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testShow(string $range) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $date = new Carbon; | 
					
						
							|  |  |  |         $this->session(['start' => $date, 'end' => clone $date]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         // mock stuff:
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $tasker       = $this->mock(AccountTaskerInterface::class); | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1'); | 
					
						
							|  |  |  |         $tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $repository = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-10 18:54:50 +01:00
										 |  |  |         $repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once(); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $transaction = factory(Transaction::class)->make(); | 
					
						
							|  |  |  |         $collector   = $this->mock(JournalCollectorInterface::class); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $collector->shouldReceive('setAccounts')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setRange')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setLimit')->andReturnSelf(); | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  |         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $collector->shouldReceive('setPage')->andReturnSelf(); | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  |         $collector->shouldReceive('setTypes')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction])); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10)); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $this->changeDateRange($this->user(), $range); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.show', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers                   \FireflyIII\Http\Controllers\AccountController::show | 
					
						
							|  |  |  |      * @covers                   \FireflyIII\Http\Controllers\AccountController::redirectToOriginalAccount | 
					
						
							|  |  |  |      * @expectedExceptionMessage Expected a transaction | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testShowBrokenInitial() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-12 21:24:34 +01:00
										 |  |  |         // mock
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |         $date = new Carbon; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $this->session(['start' => $date, 'end' => clone $date]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $account  = $this->user()->accounts()->where('account_type_id', 6)->orderBy('id', 'ASC')->whereNull('deleted_at')->first(); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.show', [$account->id])); | 
					
						
							|  |  |  |         $response->assertStatus(500); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::show | 
					
						
							|  |  |  |      * @dataProvider dateRangeProvider | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $range | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testShowByDateEmpty(string $range) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $collector    = $this->mock(JournalCollectorInterface::class); | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $collector->shouldReceive('setAccounts')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setRange')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setLimit')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setPage')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $repository = $this->mock(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon); | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $collector->shouldReceive('setTypes')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getJournals')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $this->changeDateRange($this->user(), $range); | 
					
						
							| 
									
										
										
										
											2017-03-10 18:54:50 +01:00
										 |  |  |         $response = $this->get(route('accounts.show', [1, '2016-01-01'])); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::show | 
					
						
							|  |  |  |      * @covers       \FireflyIII\Http\Controllers\AccountController::redirectToOriginalAccount | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testShowInitial() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-12 21:24:34 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |         $date = new Carbon; | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $this->session(['start' => $date, 'end' => clone $date]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $account  = $this->user()->accounts()->where('account_type_id', 6)->orderBy('id', 'DESC')->whereNull('deleted_at')->first(); | 
					
						
							|  |  |  |         $response = $this->get(route('accounts.show', [$account->id])); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::store | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testStore() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-12 21:24:34 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('find')->andReturn(new Account)->once(); | 
					
						
							|  |  |  |         $repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make()); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-26 09:54:09 +01:00
										 |  |  |         // change the preference:
 | 
					
						
							|  |  |  |         Preferences::setForUser($this->user(), 'frontPageAccounts', [1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['accounts.create.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $data = [ | 
					
						
							|  |  |  |             'name' => 'new account ' . rand(1000, 9999), | 
					
						
							|  |  |  |             'what' => 'asset', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $response = $this->post(route('accounts.store', ['asset']), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::store | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testStoreAnother() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('find')->andReturn(new Account)->once(); | 
					
						
							|  |  |  |         $repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make()); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['accounts.create.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $data = [ | 
					
						
							|  |  |  |             'name'           => 'new account ' . rand(1000, 9999), | 
					
						
							|  |  |  |             'what'           => 'asset', | 
					
						
							|  |  |  |             'create_another' => 1, | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $response = $this->post(route('accounts.store', ['asset']), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::update | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testUpdate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-12 21:24:34 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  |         $repository->shouldReceive('find')->andReturn(new Account)->once(); | 
					
						
							|  |  |  |         $repository->shouldReceive('update')->once(); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:18:34 +01:00
										 |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-04 19:14:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['accounts.edit.uri' => 'http://localhost/javascript/account']); | 
					
						
							| 
									
										
										
										
											2017-02-12 11:25:17 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $data = [ | 
					
						
							|  |  |  |             'name'   => 'updated account ' . rand(1000, 9999), | 
					
						
							|  |  |  |             'active' => 1, | 
					
						
							|  |  |  |             'what'   => 'asset', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $response = $this->post(route('accounts.update', [1]), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\AccountController::update | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::getPreviousUri | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testUpdateAgain() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('find')->andReturn(new Account)->once(); | 
					
						
							|  |  |  |         $repository->shouldReceive('update')->once(); | 
					
						
							|  |  |  |         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['accounts.edit.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-03-18 11:02:02 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $data = [ | 
					
						
							|  |  |  |             'name'           => 'updated account ' . rand(1000, 9999), | 
					
						
							|  |  |  |             'active'         => 1, | 
					
						
							|  |  |  |             'what'           => 'asset', | 
					
						
							|  |  |  |             'return_to_edit' => '1', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $response = $this->post(route('accounts.update', [1]), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-16 22:33:32 +01:00
										 |  |  | } |