| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * TransactionControllerTest.php | 
					
						
							|  |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							|  |  |  |  * This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See the LICENSE file for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Tests\Feature\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | use FireflyIII\Helpers\Collector\JournalCollectorInterface; | 
					
						
							|  |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Journal\JournalTaskerInterface; | 
					
						
							|  |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
					
						
							|  |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TransactionControllerTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::index | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:38 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::__construct | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testIndex() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $collector  = $this->mock(JournalCollectorInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $collector->shouldReceive('setTypes')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setLimit')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setPage')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setRange')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('disableInternalFilter')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $collector->shouldReceive('getJournals')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('transactions.index', ['transfer'])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::index | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testIndexAll() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $collector  = $this->mock(JournalCollectorInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $repository->shouldReceive('first')->twice()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $collector->shouldReceive('setTypes')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setLimit')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setPage')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setRange')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('disableInternalFilter')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $collector->shouldReceive('getJournals')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $response = $this->get(route('transactions.index', ['transfer','all'])); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::index | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function testIndexByDate() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $collector  = $this->mock(JournalCollectorInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $repository->shouldReceive('first')->twice()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $collector->shouldReceive('setTypes')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setLimit')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setPage')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('setRange')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('disableInternalFilter')->andReturnSelf(); | 
					
						
							|  |  |  |         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $collector->shouldReceive('getJournals')->andReturn(new Collection); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-03-11 07:41:26 +01:00
										 |  |  |         $response = $this->get(route('transactions.index', ['transfer', '2016-01-01'])); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         // has bread crumb
 | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::reorder | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testReorder() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $data = [ | 
					
						
							|  |  |  |             'items' => [], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->post(route('transactions.reorder'), $data); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 21:01:33 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::show | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |     public function testShow() | 
					
						
							| 
									
										
										
										
											2017-02-24 21:01:33 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $tasker     = $this->mock(JournalTaskerInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $tasker->shouldReceive('getPiggyBankEvents')->andReturn(new Collection); | 
					
						
							|  |  |  |         $tasker->shouldReceive('getTransactionsOverview')->andReturn([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 21:01:33 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |         $response = $this->get(route('transactions.show', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							| 
									
										
										
										
											2017-02-24 21:01:33 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\Controller::redirectToAccount | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\TransactionController::show | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |     public function testShowOpeningBalance() | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $repository = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |         $journal  = $this->user()->transactionJournals()->where('transaction_type_id', 4)->first(); | 
					
						
							|  |  |  |         $response = $this->get(route('transactions.show', [$journal->id])); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-16 22:33:32 +01:00
										 |  |  | } |