mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	Wrote new tests.
This commit is contained in:
		| @@ -49,7 +49,7 @@ class ReportGeneratorFactory | ||||
|         $class = sprintf('FireflyIII\Generator\Report\%s\%sReportGenerator', $type, $period); | ||||
|         if (class_exists($class)) { | ||||
|             /** @var ReportGeneratorInterface $obj */ | ||||
|             $obj = new $class; | ||||
|             $obj = app($class); | ||||
|             $obj->setStartDate($start); | ||||
|             $obj->setEndDate($end); | ||||
|  | ||||
|   | ||||
| @@ -204,7 +204,6 @@ class TagController extends Controller | ||||
|                 function (Tag $tag) { | ||||
|                     $date = !is_null($tag->date) ? $tag->date->format('Ymd') : '000000'; | ||||
|  | ||||
|  | ||||
|                     return strtolower($date . $tag->tag); | ||||
|                 } | ||||
|             ); | ||||
|   | ||||
| @@ -154,7 +154,6 @@ class TransactionController extends Controller | ||||
|  | ||||
|         /** @var JournalCollectorInterface $collector */ | ||||
|         $collector = app(JournalCollectorInterface::class); | ||||
|         $collector->setUser(auth()->user()); | ||||
|         $collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts(); | ||||
|         $collector->setRange($start, $end)->withBudgetInformation()->withCategoryInformation(); | ||||
|         $collector->withOpposingAccount(); | ||||
|   | ||||
| @@ -11,8 +11,16 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class NewUserControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class NewUserControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -22,6 +30,13 @@ class NewUserControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('count')->andReturn(0); | ||||
|  | ||||
|  | ||||
|         $this->be($this->emptyUser()); | ||||
|         $response = $this->get(route('new-user.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -33,9 +48,39 @@ class NewUserControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testSubmit() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('store')->times(3); | ||||
|  | ||||
|  | ||||
|         $data = [ | ||||
|             'bank_name'         => 'New bank', | ||||
|             'bank_balance' => 100, | ||||
|             'savings_balance'   => '1000', | ||||
|             'bank_balance'      => '100', | ||||
|             'credit_card_limit' => '1000', | ||||
|         ]; | ||||
|         $this->be($this->emptyUser()); | ||||
|         $response = $this->post(route('new-user.submit'), $data); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\NewUserController::submit | ||||
|      */ | ||||
|     public function testSubmitSingle() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('store')->once(); | ||||
|  | ||||
|         $data = [ | ||||
|             'bank_name'    => 'New bank', | ||||
|             'bank_balance' => '100', | ||||
|         ]; | ||||
|         $this->be($this->emptyUser()); | ||||
|         $response = $this->post(route('new-user.submit'), $data); | ||||
|   | ||||
| @@ -11,10 +11,21 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\PiggyBank; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class PiggyBankControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class PiggyBankControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -23,6 +34,10 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testAdd() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.add', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -33,6 +48,10 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testAddMobile() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.add-money-mobile', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -44,6 +63,14 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $account      = factory(Account::class)->make(); | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType') | ||||
|                      ->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.create')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -55,6 +82,10 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.delete', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -66,9 +97,14 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $repository->shouldReceive('destroy')->andReturn(true); | ||||
|  | ||||
|  | ||||
|         $this->session(['piggy-banks.delete.url' => 'http://localhost']); | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('piggy-banks.destroy', [2])); | ||||
| @@ -82,6 +118,14 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $account      = factory(Account::class)->make(); | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType') | ||||
|                      ->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.edit', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -94,6 +138,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -105,8 +155,15 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testOrder() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('reset'); | ||||
|         $repository->shouldReceive('setOrder')->times(2); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('piggy-banks.order', [1, 2])); | ||||
|         $response = $this->post(route('piggy-banks.order'), ['order' => [1, 2]]); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
| @@ -115,6 +172,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostAdd() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('createEvent')->once(); | ||||
|  | ||||
|         $data = ['amount' => '1.123']; | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('piggy-banks.add', [1]), $data); | ||||
| @@ -130,6 +193,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostAddExact() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('createEvent')->once(); | ||||
|  | ||||
|         // find a piggy with current amount = 0. | ||||
|         $piggy = PiggyBank::leftJoin('piggy_bank_repetitions', 'piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id') | ||||
|                           ->where('currentamount', 0) | ||||
| @@ -149,6 +218,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostRemove() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('createEvent')->once(); | ||||
|  | ||||
|         $data = ['amount' => '1.123']; | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('piggy-banks.remove', [1]), $data); | ||||
| @@ -162,6 +237,11 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testRemove() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.remove', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -172,6 +252,10 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testRemoveMobile() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.remove-money-mobile', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -183,6 +267,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testShow() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('getEvents')->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('piggy-banks.show', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -194,6 +284,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testStore() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('store')->andReturn(new PiggyBank); | ||||
|  | ||||
|         $this->session(['piggy-banks.create.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'name'                            => 'Piggy ' . rand(999, 10000), | ||||
| @@ -214,6 +310,12 @@ class PiggyBankControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUpdate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(PiggyBankRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('update')->andReturn(new PiggyBank); | ||||
|  | ||||
|         $this->session(['piggy-banks.edit.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'name'                            => 'Updated Piggy ' . rand(999, 10000), | ||||
|   | ||||
| @@ -11,8 +11,19 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use PragmaRX\Google2FA\Contracts\Google2FA; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class PreferencesControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class PreferencesControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -21,6 +32,12 @@ class PreferencesControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCode() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $google       = $this->mock(Google2FA::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $google->shouldReceive('generateSecretKey')->andReturn('secret'); | ||||
|         $google->shouldReceive('getQRCodeInline')->andReturn('long-data-url'); | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('preferences.code')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -32,6 +49,10 @@ class PreferencesControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDeleteCode() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('preferences.delete-code')); | ||||
|         $response->assertStatus(302); | ||||
| @@ -46,6 +67,12 @@ class PreferencesControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('preferences.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -57,6 +84,10 @@ class PreferencesControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $data = [ | ||||
|             'fiscalYearStart'       => '2016-01-01', | ||||
|             'frontPageAccounts'     => [], | ||||
|   | ||||
| @@ -11,9 +11,16 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class ProfileControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class ProfileControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -22,6 +29,10 @@ class ProfileControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testChangePassword() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('profile.change-password')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -33,6 +44,10 @@ class ProfileControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDeleteAccount() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('profile.delete-account')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -45,6 +60,10 @@ class ProfileControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('profile.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -56,6 +75,9 @@ class ProfileControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostChangePassword() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository = $this->mock(UserRepositoryInterface::class); | ||||
|         $repository->shouldReceive('changePassword'); | ||||
|  | ||||
| @@ -75,6 +97,9 @@ class ProfileControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostDeleteAccount() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository = $this->mock(UserRepositoryInterface::class); | ||||
|         $repository->shouldReceive('destroy'); | ||||
|         $data = [ | ||||
|   | ||||
| @@ -11,8 +11,25 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Generator\Report\Audit\YearReportGenerator as AYRG; | ||||
| use FireflyIII\Generator\Report\Budget\YearReportGenerator as BYRG; | ||||
| use FireflyIII\Generator\Report\Category\YearReportGenerator as CYRG; | ||||
| use FireflyIII\Generator\Report\Standard\YearReportGenerator as SYRG; | ||||
| use FireflyIII\Generator\Report\Tag\YearReportGenerator as TYRG; | ||||
| use FireflyIII\Helpers\Report\ReportHelperInterface; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class ReportControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class ReportControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -21,10 +38,19 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testAuditReport() | ||||
|     { | ||||
|         $generator    = $this->mock(AYRG::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $generator->shouldReceive('setStartDate')->once(); | ||||
|         $generator->shouldReceive('setEndDate')->once(); | ||||
|         $generator->shouldReceive('setAccounts')->once(); | ||||
|         $generator->shouldReceive('generate')->andReturn('here-be-report'); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.report.audit', [1, '20160101', '20160131'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -32,10 +58,18 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testBudgetReport() | ||||
|     { | ||||
|         $generator    = $this->mock(BYRG::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $generator->shouldReceive('setStartDate')->once(); | ||||
|         $generator->shouldReceive('setEndDate')->once(); | ||||
|         $generator->shouldReceive('setAccounts')->once(); | ||||
|         $generator->shouldReceive('setBudgets')->once(); | ||||
|         $generator->shouldReceive('generate')->andReturn('here-be-report'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.report.budget', [1, 1, '20160101', '20160131'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -43,10 +77,18 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCategoryReport() | ||||
|     { | ||||
|         $generator    = $this->mock(CYRG::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $generator->shouldReceive('setStartDate')->once(); | ||||
|         $generator->shouldReceive('setEndDate')->once(); | ||||
|         $generator->shouldReceive('setAccounts')->once(); | ||||
|         $generator->shouldReceive('setCategories')->once(); | ||||
|         $generator->shouldReceive('generate')->andReturn('here-be-report'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.report.category', [1, 1, '20160101', '20160131'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -54,10 +96,17 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDefaultReport() | ||||
|     { | ||||
|         $generator    = $this->mock(SYRG::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $generator->shouldReceive('setStartDate')->once(); | ||||
|         $generator->shouldReceive('setEndDate')->once(); | ||||
|         $generator->shouldReceive('setAccounts')->once(); | ||||
|         $generator->shouldReceive('generate')->andReturn('here-be-report'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.report.default', [1, '20160101', '20160131'])); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -66,6 +115,13 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         $helper       = $this->mock(ReportHelperInterface::class); | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $helper->shouldReceive('listOfMonths')->andReturn([]); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -77,6 +133,9 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testOptions() | ||||
|     { | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.options', ['default'])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -87,9 +146,31 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testPostIndex() | ||||
|     { | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('reports.index.post')); | ||||
|         $response->assertStatus(302); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\ReportController::categoryReport | ||||
|      */ | ||||
|     public function testTagReport() | ||||
|     { | ||||
|         $generator    = $this->mock(TYRG::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $generator->shouldReceive('setStartDate')->once(); | ||||
|         $generator->shouldReceive('setEndDate')->once(); | ||||
|         $generator->shouldReceive('setAccounts')->once(); | ||||
|         $generator->shouldReceive('setTags')->once(); | ||||
|         $generator->shouldReceive('generate')->andReturn('here-be-report'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('reports.report.tag', [1, 'TagJanuary', '20160101', '20160131'])); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -12,17 +12,33 @@ declare(strict_types = 1); | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use FireflyIII\Models\Rule; | ||||
| use FireflyIII\Models\RuleGroup; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\Rule\RuleRepositoryInterface; | ||||
| use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class RuleControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class RuleControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\RuleController::create | ||||
|      * @covers \FireflyIII\Http\Controllers\RuleController::getPreviousTriggers | ||||
|      * @covers \FireflyIII\Http\Controllers\RuleController::getPreviousActions | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.create', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -34,6 +50,10 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.delete', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -45,7 +65,10 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(RuleRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('destroy'); | ||||
|  | ||||
|         $this->session(['rules.delete.url' => 'http://localhost']); | ||||
| @@ -61,6 +84,12 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDown() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(RuleRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('moveDown'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.down', [1])); | ||||
|         $response->assertStatus(302); | ||||
| @@ -72,6 +101,12 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(RuleRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('getPrimaryTrigger')->andReturn(new Rule); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.edit', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -84,6 +119,20 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository     = $this->mock(RuleRepositoryInterface::class); | ||||
|         $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos   = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $ruleGroupRepos->shouldReceive('count')->andReturn(0); | ||||
|         $ruleGroupRepos->shouldReceive('store'); | ||||
|         $repository->shouldReceive('getFirstRuleGroup')->andReturn(new RuleGroup); | ||||
|         $ruleGroupRepos->shouldReceive('getRuleGroupsWithRules')->andReturn(new Collection); | ||||
|  | ||||
|         $repository->shouldReceive('count')->andReturn(0); | ||||
|         $repository->shouldReceive('store'); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -95,6 +144,10 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testReorderRuleActions() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $data = [ | ||||
|             'triggers' => [1, 2, 3], | ||||
|         ]; | ||||
| @@ -112,6 +165,10 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testReorderRuleTriggers() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $data = [ | ||||
|             'triggers' => [1, 2, 3], | ||||
|         ]; | ||||
| @@ -129,6 +186,12 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testStore() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos   = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $ruleGroupRepos->shouldReceive('find')->andReturn(new RuleGroup)->once(); | ||||
|  | ||||
|         $this->session(['rules.create.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'rule_group_id'      => 1, | ||||
| @@ -166,6 +229,10 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testTestTriggers() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.test-triggers', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -176,6 +243,12 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUp() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(RuleRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('moveUp'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rules.up', [1])); | ||||
|         $response->assertStatus(302); | ||||
| @@ -187,6 +260,12 @@ class RuleControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUpdate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos   = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $ruleGroupRepos->shouldReceive('find')->andReturn(new RuleGroup)->once(); | ||||
|  | ||||
|         $data = [ | ||||
|             'rule_group_id'      => 1, | ||||
|             'title'              => 'Your first default rule', | ||||
|   | ||||
| @@ -13,9 +13,18 @@ namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Models\RuleGroup; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class RuleGroupControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class RuleGroupControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -24,6 +33,10 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.create')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -35,6 +48,12 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('get')->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.delete', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -46,6 +65,9 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $repository->shouldReceive('destroy'); | ||||
|  | ||||
| @@ -62,6 +84,12 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDown() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('moveDown'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.down', [1])); | ||||
|         $response->assertStatus(302); | ||||
| @@ -73,6 +101,10 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.edit', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -84,6 +116,12 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testExecute() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection); | ||||
|  | ||||
|         $this->session(['first' => new Carbon('2010-01-01')]); | ||||
|         $data = [ | ||||
|             'accounts'   => [1], | ||||
| @@ -103,6 +141,12 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testSelectTransactions() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.select-transactions', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -114,13 +158,17 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testStore() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->session(['rule-groups.create.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'title'       => 'A', | ||||
|             'description' => '', | ||||
|         ]; | ||||
|  | ||||
|         $repository = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $repository->shouldReceive('store')->andReturn(new RuleGroup); | ||||
|         $repository->shouldReceive('find')->andReturn(new RuleGroup); | ||||
|  | ||||
| @@ -135,6 +183,12 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUp() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('moveUp'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('rule-groups.up', [1])); | ||||
|         $response->assertStatus(302); | ||||
| @@ -146,13 +200,17 @@ class RuleGroupControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUpdate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository   = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $data = [ | ||||
|             'title'       => 'C', | ||||
|             'description' => 'XX', | ||||
|         ]; | ||||
|         $this->session(['rule-groups.edit.url' => 'http://localhost']); | ||||
|  | ||||
|         $repository = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $repository->shouldReceive('update'); | ||||
|         $repository->shouldReceive('find')->andReturn(new RuleGroup); | ||||
|  | ||||
|   | ||||
| @@ -15,6 +15,11 @@ use FireflyIII\Support\Search\SearchInterface; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class SearchControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class SearchControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
|   | ||||
| @@ -11,10 +11,22 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Helpers\Collector\JournalCollectorInterface; | ||||
| use FireflyIII\Models\Tag; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Journal\JournalRepositoryInterface; | ||||
| use FireflyIII\Repositories\Tag\TagRepositoryInterface; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| use Illuminate\Support\Collection; | ||||
| use Tests\TestCase; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Class TagControllerTest | ||||
|  * | ||||
|  * @package Tests\Feature\Controllers | ||||
|  */ | ||||
| class TagControllerTest extends TestCase | ||||
| { | ||||
|  | ||||
| @@ -23,6 +35,10 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('tags.create')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -34,6 +50,10 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('tags.delete', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -45,7 +65,10 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(TagRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('destroy'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
| @@ -59,6 +82,10 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('tags.edit', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -71,6 +98,15 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $tag          = factory(Tag::class)->make(); | ||||
|         $repository   = $this->mock(TagRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('count')->andReturn(0); | ||||
|         $repository->shouldReceive('getByType')->andReturn(new Collection([$tag])); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('tags.index')); | ||||
|         $response->assertStatus(200); | ||||
| @@ -79,9 +115,33 @@ class TagControllerTest extends TestCase | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\TagController::show | ||||
|      * @covers \FireflyIII\Http\Controllers\TagController::getPeriodOverview | ||||
|      */ | ||||
|     public function testShow() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(TagRepositoryInterface::class); | ||||
|         $collector    = $this->mock(JournalCollectorInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('spentInPeriod')->andReturn('-1'); | ||||
|         $repository->shouldReceive('firstUseDate')->andReturn(new Carbon); | ||||
|         $repository->shouldReceive('lastUseDate')->andReturn(new Carbon); | ||||
|         $repository->shouldReceive('earnedInPeriod')->andReturn('1'); | ||||
|         $repository->shouldReceive('find')->andReturn(new Tag); | ||||
|  | ||||
|         $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setTag')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withOpposingAccount')->andReturnSelf(); | ||||
|         $collector->shouldReceive('disableInternalFilter')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withBudgetInformation')->andReturnSelf(); | ||||
|         $collector->shouldReceive('withCategoryInformation')->andReturnSelf(); | ||||
|         $collector->shouldReceive('setRange')->andReturnSelf(); | ||||
|         $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10)); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('tags.show', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -93,6 +153,13 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testStore() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(TagRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|         $repository->shouldReceive('find')->andReturn(new Tag); | ||||
|         $repository->shouldReceive('store')->andReturn(new Tag); | ||||
|  | ||||
|         $this->session(['tags.create.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'tag'     => 'Hello new tag' . rand(999, 10000), | ||||
| @@ -109,12 +176,18 @@ class TagControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testUpdate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository   = $this->mock(TagRepositoryInterface::class); | ||||
|         $journalRepos = $this->mock(JournalRepositoryInterface::class); | ||||
|         $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|  | ||||
|         $this->session(['tags.edit.url' => 'http://localhost']); | ||||
|         $data = [ | ||||
|             'tag'     => 'Hello updated tag' . rand(999, 10000), | ||||
|             'tagMode' => 'nothing', | ||||
|         ]; | ||||
|         $repository = $this->mock(TagRepositoryInterface::class); | ||||
|  | ||||
|         $repository->shouldReceive('update'); | ||||
|         $repository->shouldReceive('find')->andReturn(new Tag); | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,37 @@ use Tests\TestCase; | ||||
|  */ | ||||
| class SplitControllerTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal | ||||
|      */ | ||||
|     public function testEditSingle() | ||||
|     { | ||||
|  | ||||
|         $currencyRepository = $this->mock(CurrencyRepositoryInterface::class); | ||||
|         $accountRepository  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $budgetRepository   = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $transactions       = factory(Transaction::class, 1)->make(); | ||||
|         $tasker             = $this->mock(JournalTaskerInterface::class); | ||||
|  | ||||
|         $currencyRepository->shouldReceive('get')->once()->andReturn(new Collection); | ||||
|         $accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]]) | ||||
|                           ->andReturn(new Collection)->once(); | ||||
|         $budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection); | ||||
|         $tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray()); | ||||
|  | ||||
|  | ||||
|         $deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first(); | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.split.edit', [$deposit->id])); | ||||
|         $response->assertStatus(200); | ||||
|         // has bread crumb | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct | ||||
|   | ||||
| @@ -11,6 +11,12 @@ declare(strict_types = 1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers; | ||||
|  | ||||
| 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; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| class TransactionControllerTest extends TestCase | ||||
| @@ -22,6 +28,21 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         // 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)); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.index', ['transfer'])); | ||||
| @@ -35,6 +56,22 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndexAll() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository = $this->mock(JournalRepositoryInterface::class); | ||||
|         $collector  = $this->mock(JournalCollectorInterface::class); | ||||
|         $repository->shouldReceive('first')->once()->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)); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.index.all', ['transfer'])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -47,6 +84,22 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testIndexByDate() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository = $this->mock(JournalRepositoryInterface::class); | ||||
|         $collector  = $this->mock(JournalCollectorInterface::class); | ||||
|         $repository->shouldReceive('first')->once()->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)); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.index.date', ['transfer', '2016-01-01'])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -59,6 +112,10 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testReorder() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $data = [ | ||||
|             'items' => [], | ||||
|         ]; | ||||
| @@ -72,6 +129,14 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testShow() | ||||
|     { | ||||
|         // 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([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.show', [1])); | ||||
|         $response->assertStatus(200); | ||||
| @@ -84,6 +149,10 @@ class TransactionControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testShowOpeningBalance() | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository = $this->mock(JournalRepositoryInterface::class); | ||||
|         $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $journal  = $this->user()->transactionJournals()->where('transaction_type_id', 4)->first(); | ||||
|         $response = $this->get(route('transactions.show', [$journal->id])); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user