| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * RuleGroupControllerTest.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 12:00:11 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-07-08 06:28:44 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Tests\Feature\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 13:15:23 +01:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  | use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions; | 
					
						
							| 
									
										
										
										
											2017-02-12 13:15:23 +01:00
										 |  |  | use FireflyIII\Models\RuleGroup; | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-02-12 13:15:23 +01:00
										 |  |  | use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  | use FireflyIII\Repositories\User\UserRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2018-03-24 06:08:50 +01:00
										 |  |  | use Log; | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  | use Mockery; | 
					
						
							| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class RuleGroupControllerTest | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-08-12 10:27:45 +02:00
										 |  |  |  * @SuppressWarnings(PHPMD.TooManyPublicMethods) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | 
					
						
							|  |  |  |  * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-02-12 12:00:11 +01:00
										 |  |  | class RuleGroupControllerTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-24 06:08:50 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-09-02 20:27:26 +02:00
										 |  |  |     public function setUp(): void | 
					
						
							| 
									
										
										
										
											2018-03-24 06:08:50 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         parent::setUp(); | 
					
						
							| 
									
										
										
										
											2018-09-03 18:52:46 +02:00
										 |  |  |         Log::info(sprintf('Now in %s.', \get_class($this))); | 
					
						
							| 
									
										
										
										
											2018-03-24 06:08:50 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testCreate(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.create')); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testDelete(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         $repository->shouldReceive('get')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.delete', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testDestroy(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $repository->shouldReceive('destroy'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['rule-groups.delete.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->post(route('rule-groups.destroy', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:32:13 +01:00
										 |  |  |         $response->assertRedirect(route('index')); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testDown(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         $repository->shouldReceive('moveDown'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.down', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:32:13 +01:00
										 |  |  |         $response->assertRedirect(route('rules.index')); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testEdit(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 17:54:37 +02:00
										 |  |  |         /** @var RuleGroup $ruleGroup */ | 
					
						
							|  |  |  |         $ruleGroup              = $this->user()->ruleGroups()->first(); | 
					
						
							|  |  |  |         $ruleGroup->description = 'Some description ' . random_int(1, 10000); | 
					
						
							|  |  |  |         $ruleGroup->save(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.edit', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							| 
									
										
										
										
											2018-08-07 17:54:37 +02:00
										 |  |  |         $response->assertSee($ruleGroup->description); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testExecute(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  |         $accountRepos = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  |         $this->expectsJobs(ExecuteRuleGroupOnExistingTransactions::class); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->session(['first' => new Carbon('2010-01-01')]); | 
					
						
							|  |  |  |         $data = [ | 
					
						
							|  |  |  |             'accounts'   => [1], | 
					
						
							|  |  |  |             'start_date' => '2010-01-02', | 
					
						
							|  |  |  |             'end_date'   => '2010-01-02', | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->post(route('rule-groups.execute', [1]), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:32:13 +01:00
										 |  |  |         $response->assertRedirect(route('rules.index')); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							|  |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testSelectTransactions(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  |         $accountRepos = $this->mock(AccountRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.select-transactions', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(200); | 
					
						
							|  |  |  |         $response->assertSee('<ol class="breadcrumb">'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers       \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2018-03-03 17:16:47 +01:00
										 |  |  |      * @covers       \FireflyIII\Http\Requests\RuleGroupFormRequest | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testStore(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['rule-groups.create.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-03-16 20:46:18 +01:00
										 |  |  |         $repository->shouldReceive('store')->andReturn(new RuleGroup); | 
					
						
							|  |  |  |         $repository->shouldReceive('find')->andReturn(new RuleGroup); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $data = [ | 
					
						
							|  |  |  |             'title'       => 'A', | 
					
						
							| 
									
										
										
										
											2017-09-12 19:47:29 +02:00
										 |  |  |             'description' => 'No description', | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->post(route('rule-groups.store', [1]), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testUp(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         $repository->shouldReceive('moveUp'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->get(route('rule-groups.up', [1])); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:32:13 +01:00
										 |  |  |         $response->assertRedirect(route('rules.index')); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-09 20:17:15 +02:00
										 |  |  |      * @covers       \FireflyIII\Http\Controllers\RuleGroupController | 
					
						
							| 
									
										
										
										
											2018-03-03 17:16:47 +01:00
										 |  |  |      * @covers       \FireflyIII\Http\Requests\RuleGroupFormRequest | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-05-11 19:58:10 +02:00
										 |  |  |     public function testUpdate(): void | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  |         // mock stuff
 | 
					
						
							|  |  |  |         $journalRepos = $this->mock(JournalRepositoryInterface::class); | 
					
						
							|  |  |  |         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-09-04 09:52:19 +02:00
										 |  |  |         $userRepos = $this->mock(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2018-04-28 10:27:33 +02:00
										 |  |  |         $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); | 
					
						
							| 
									
										
										
										
											2017-03-05 18:15:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         $data = [ | 
					
						
							| 
									
										
										
										
											2018-03-03 17:16:47 +01:00
										 |  |  |             'id'          => 1, | 
					
						
							| 
									
										
										
										
											2017-03-05 11:19:06 +01:00
										 |  |  |             'title'       => 'C', | 
					
						
							|  |  |  |             'description' => 'XX', | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2017-03-18 20:53:44 +01:00
										 |  |  |         $this->session(['rule-groups.edit.uri' => 'http://localhost']); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $repository->shouldReceive('update'); | 
					
						
							| 
									
										
										
										
											2018-03-03 17:16:47 +01:00
										 |  |  |         $repository->shouldReceive('find')->andReturn(RuleGroup::first()); | 
					
						
							| 
									
										
										
										
											2017-02-12 12:21:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->be($this->user()); | 
					
						
							|  |  |  |         $response = $this->post(route('rule-groups.update', [1]), $data); | 
					
						
							|  |  |  |         $response->assertStatus(302); | 
					
						
							|  |  |  |         $response->assertSessionHas('success'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-16 22:33:32 +01:00
										 |  |  | } |