mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	Expand test coverage.
This commit is contained in:
		| @@ -78,7 +78,7 @@ class ShowController extends Controller | ||||
|      */ | ||||
|     public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) | ||||
|     { | ||||
|         Log::debug('Now in show()'); | ||||
|         //Log::debug('Now in show()'); | ||||
|         /** @var Carbon $start */ | ||||
|         $start = $start ?? session('start', Carbon::now()->startOfMonth()); | ||||
|         /** @var Carbon $end */ | ||||
| @@ -104,7 +104,7 @@ class ShowController extends Controller | ||||
|         $groups = $collector->getPaginatedGroups(); | ||||
|         $groups->setPath($path); | ||||
|  | ||||
|         Log::debug('End of show()'); | ||||
|         //Log::debug('End of show()'); | ||||
|  | ||||
|         return view('categories.show', compact('category', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end')); | ||||
|     } | ||||
|   | ||||
| @@ -77,8 +77,6 @@ class IndexController extends Controller | ||||
|      */ | ||||
|     public function create(string $importProvider) | ||||
|     { | ||||
|  | ||||
|  | ||||
|         $hasPreReq      = (bool)config(sprintf('import.has_prereq.%s', $importProvider)); | ||||
|         $hasConfig      = (bool)config(sprintf('import.has_job_config.%s', $importProvider)); | ||||
|         $allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $importProvider)); | ||||
| @@ -90,12 +88,13 @@ class IndexController extends Controller | ||||
|         Log::debug(sprintf('Has prerequisites? %s', var_export($hasPreReq, true))); | ||||
|         Log::debug(sprintf('Has config? %s', var_export($hasConfig, true))); | ||||
|  | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         if ($isDemoUser && !$allowedForDemo) { | ||||
|             Log::debug('User is demo and this provider doesnt work for demo users.'); | ||||
|  | ||||
|             return redirect(route('import.index')); | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         $importJob = $this->repository->create($importProvider); | ||||
|  | ||||
|   | ||||
| @@ -1,341 +0,0 @@ | ||||
| <?php | ||||
| /** | ||||
|  * JournalFormRequest.php | ||||
|  * Copyright (c) 2017 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\TransactionType; | ||||
| use Illuminate\Validation\Validator; | ||||
| use Log; | ||||
|  | ||||
| /** | ||||
|  * Class JournalFormRequest. | ||||
|  */ | ||||
| class JournalFormRequest extends Request | ||||
| { | ||||
|     /** | ||||
|      * Verify the request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize(): bool | ||||
|     { | ||||
|         // Only allow logged in users | ||||
|         return auth()->check(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns and validates the data required to store a new journal. Can handle both single transaction journals and split journals. | ||||
|      * | ||||
|      * @return array | ||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     public function getJournalData(): array | ||||
|     { | ||||
|         $currencyId = $this->integer('amount_currency_id_amount'); | ||||
|         $data       = [ | ||||
|             'type'               => $this->get('what'), // type. can be 'deposit', 'withdrawal' or 'transfer' | ||||
|             'date'               => $this->date('date'), | ||||
|             'tags'               => explode(',', $this->string('tags')), | ||||
|             'user'               => auth()->user()->id, | ||||
|  | ||||
|             // all custom fields: | ||||
|             'interest_date'      => $this->date('interest_date'), | ||||
|             'book_date'          => $this->date('book_date'), | ||||
|             'process_date'       => $this->date('process_date'), | ||||
|             'due_date'           => $this->date('due_date'), | ||||
|             'payment_date'       => $this->date('payment_date'), | ||||
|             'invoice_date'       => $this->date('invoice_date'), | ||||
|             'internal_reference' => $this->string('internal_reference'), | ||||
|             'notes'              => $this->string('notes'), | ||||
|  | ||||
|             // journal data: | ||||
|             'description'        => $this->string('description'), | ||||
|             'piggy_bank_id'      => $this->integer('piggy_bank_id'), | ||||
|             'piggy_bank_name'    => null, | ||||
|             'bill_id'            => null, | ||||
|             'bill_name'          => null, | ||||
|             'original-source'    => sprintf('gui-v%s', config('firefly.version')), | ||||
|  | ||||
|             // transaction data: | ||||
|             'transactions'       => [ | ||||
|                 [ | ||||
|                     'currency_id'           => null, | ||||
|                     'currency_code'         => null, | ||||
|                     'description'           => null, | ||||
|                     'amount'                => $this->string('amount'), | ||||
|                     'budget_id'             => $this->integer('budget_id'), | ||||
|                     'budget_name'           => null, | ||||
|                     'category_id'           => null, | ||||
|                     'category_name'         => $this->string('category'), | ||||
|                     'source_id'             => $this->integer('source_id'), | ||||
|                     'source_name'           => $this->string('source_name'), | ||||
|                     'destination_id'        => $this->integer('destination_id'), | ||||
|                     'destination_name'      => $this->string('destination_name'), | ||||
|                     'foreign_currency_id'   => null, | ||||
|                     'foreign_currency_code' => null, | ||||
|                     'foreign_amount'        => null, | ||||
|                     'reconciled'            => false, | ||||
|                     'identifier'            => 0, | ||||
|                 ], | ||||
|             ], | ||||
|         ]; | ||||
|         switch (strtolower($data['type'])) { | ||||
|             case 'withdrawal': | ||||
|                 $sourceCurrency                            = $this->integer('source_account_currency'); | ||||
|                 $data['transactions'][0]['currency_id']    = $sourceCurrency; | ||||
|                 $data['transactions'][0]['destination_id'] = null; // clear destination ID (transfer) | ||||
|                 if ($sourceCurrency !== $currencyId) { | ||||
|                     // user has selected a foreign currency. | ||||
|                     $data['transactions'][0]['foreign_currency_id'] = $currencyId; | ||||
|                     $data['transactions'][0]['foreign_amount']      = $this->string('amount'); | ||||
|                     $data['transactions'][0]['amount']              = $this->string('native_amount'); | ||||
|                 } | ||||
|  | ||||
|                 break; | ||||
|             case 'deposit': | ||||
|                 $destinationCurrency                    = $this->integer('destination_account_currency'); | ||||
|                 $data['transactions'][0]['currency_id'] = $destinationCurrency; | ||||
|                 $data['transactions'][0]['source_id']   = null; // clear destination ID (transfer) | ||||
|                 if ($destinationCurrency !== $currencyId) { | ||||
|                     // user has selected a foreign currency. | ||||
|                     $data['transactions'][0]['foreign_currency_id'] = $currencyId; | ||||
|                     $data['transactions'][0]['foreign_amount']      = $this->string('amount'); | ||||
|                     $data['transactions'][0]['amount']              = $this->string('native_amount'); | ||||
|                 } | ||||
|                 break; | ||||
|             case 'transfer': | ||||
|                 // by default just assume source currency | ||||
|                 $sourceCurrency                         = $this->integer('source_account_currency'); | ||||
|                 $destinationCurrency                    = $this->integer('destination_account_currency'); | ||||
|                 $data['transactions'][0]['currency_id'] = $sourceCurrency; | ||||
|                 if ($sourceCurrency !== $destinationCurrency) { | ||||
|                     // user has selected a foreign currency. | ||||
|                     $data['transactions'][0]['foreign_currency_id'] = $destinationCurrency; | ||||
|                     $data['transactions'][0]['foreign_amount']      = $this->string('destination_amount'); | ||||
|                     $data['transactions'][0]['amount']              = $this->string('source_amount'); | ||||
|                 } | ||||
|                 break; | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Rules for this request. | ||||
|      * | ||||
|      * @return array | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function rules(): array | ||||
|     { | ||||
|         $what  = $this->get('what'); | ||||
|         $rules = [ | ||||
|             'what'                      => 'required|in:withdrawal,deposit,transfer', | ||||
|             'date'                      => 'required|date', | ||||
|             'amount_currency_id_amount' => 'exists:transaction_currencies,id|required', | ||||
|             // then, custom fields: | ||||
|             'interest_date'             => 'date|nullable', | ||||
|             'book_date'                 => 'date|nullable', | ||||
|             'process_date'              => 'date|nullable', | ||||
|             'due_date'                  => 'date|nullable', | ||||
|             'payment_date'              => 'date|nullable', | ||||
|             'invoice_date'              => 'date|nullable', | ||||
|             'internal_reference'        => 'min:1|max:255|nullable', | ||||
|             'notes'                     => 'min:1|max:50000|nullable', | ||||
|             // and then transaction rules: | ||||
|             'description'               => 'required|between:1,255', | ||||
|             'amount'                    => 'numeric|required|more:0|less:1000000000', | ||||
|             'budget_id'                 => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable', | ||||
|             'category'                  => 'between:1,255|nullable', | ||||
|             'source_id'                 => 'numeric|belongsToUser:accounts,id|nullable', | ||||
|             'source_name'               => 'between:1,255|nullable', | ||||
|             'destination_id'            => 'numeric|belongsToUser:accounts,id|nullable', | ||||
|             'destination_name'          => 'between:1,255|nullable', | ||||
|             'piggy_bank_id'             => 'numeric|nullable', | ||||
|  | ||||
|             // foreign currency amounts | ||||
|             'native_amount'             => 'numeric|more:0|nullable', | ||||
|             'source_amount'             => 'numeric|more:0|nullable', | ||||
|             'destination_amount'        => 'numeric|more:0|nullable', | ||||
|         ]; | ||||
|  | ||||
|         // some rules get an upgrade depending on the type of data: | ||||
|         $rules = $this->enhanceRules($what, $rules); | ||||
|  | ||||
|         return $rules; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Configure the validator instance. | ||||
|      * | ||||
|      * @param  Validator $validator | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function withValidator(Validator $validator): void | ||||
|     { | ||||
|         $validator->after( | ||||
|             function (Validator $validator) { | ||||
|                 $this->validNativeAmount($validator); | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Inspired by https://www.youtube.com/watch?v=WwnI0RS6J5A. | ||||
|      * | ||||
|      * @param string $what | ||||
|      * @param array  $rules | ||||
|      * | ||||
|      * @return array | ||||
|      * | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     private function enhanceRules(string $what, array $rules): array | ||||
|     { | ||||
|         switch ($what) { | ||||
|             case strtolower(TransactionType::WITHDRAWAL): | ||||
|                 $rules['source_id']        = 'required|exists:accounts,id|belongsToUser:accounts'; | ||||
|                 $rules['destination_name'] = 'between:1,255|nullable'; | ||||
|                 break; | ||||
|             case strtolower(TransactionType::DEPOSIT): | ||||
|                 $rules['source_name']    = 'between:1,255|nullable'; | ||||
|                 $rules['destination_id'] = 'required|exists:accounts,id|belongsToUser:accounts'; | ||||
|                 break; | ||||
|             case strtolower(TransactionType::TRANSFER): | ||||
|                 // this may not work: | ||||
|                 $rules['source_id']      = 'required|exists:accounts,id|belongsToUser:accounts|different:destination_id'; | ||||
|                 $rules['destination_id'] = 'required|exists:accounts,id|belongsToUser:accounts|different:source_id'; | ||||
|  | ||||
|                 break; | ||||
|             default: | ||||
|                 throw new FireflyException(sprintf('Cannot handle transaction type of type "%s"', $what)); // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         return $rules; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if amounts are valid. | ||||
|      * | ||||
|      * @param Validator $validator | ||||
|      */ | ||||
|     private function validNativeAmount(Validator $validator): void | ||||
|     { | ||||
|         $data = $validator->getData(); | ||||
|         $type = $data['what'] ?? 'invalid'; | ||||
|         Log::debug(sprintf('Type is %s', $type)); | ||||
|         if ('withdrawal' === $type) { | ||||
|             $this->validateWithdrawal($validator); | ||||
|         } | ||||
|  | ||||
|         // same thing for deposits: | ||||
|         if ('deposit' === $type) { | ||||
|             $this->validateDeposit($validator); | ||||
|         } | ||||
|  | ||||
|         // and for transfers | ||||
|         if ('transfer' === $type) { | ||||
|             $this->validateTransfer($validator); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if deposit amount is valid. | ||||
|      * | ||||
|      * @param Validator $validator | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     private function validateDeposit(Validator $validator): void | ||||
|     { | ||||
|         $data             = $validator->getData(); | ||||
|         $selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0); | ||||
|         $accountCurrency  = (int)($data['destination_account_currency'] ?? 0); | ||||
|         $nativeAmount     = (string)($data['native_amount'] ?? ''); | ||||
|  | ||||
|         Log::debug('Now in validateDeposit.'); | ||||
|         Log::debug(sprintf('SelectedCurrency is "%s", accountCurrency is "%s", native amount is "%s".', $selectedCurrency, $accountCurrency, $nativeAmount)); | ||||
|  | ||||
|         if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount && 0 !== $selectedCurrency && 0 !== $accountCurrency) { | ||||
|             Log::debug('Adding an error about missing native amount.'); | ||||
|             $validator->errors()->add('native_amount', (string)trans('validation.numeric_native')); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if transfer amount is valid. | ||||
|      * | ||||
|      * @param Validator $validator | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     private function validateTransfer(Validator $validator): void | ||||
|     { | ||||
|         $data                = $validator->getData(); | ||||
|         $sourceCurrency      = (int)($data['source_account_currency'] ?? 0); | ||||
|         $destinationCurrency = (int)($data['destination_account_currency'] ?? 0); | ||||
|         $sourceAmount        = (string)($data['source_amount'] ?? ''); | ||||
|         $destinationAmount   = (string)($data['destination_amount'] ?? ''); | ||||
|  | ||||
|         Log::debug(sprintf('Source currency is %d, destination currency is %d', $sourceCurrency, $destinationCurrency)); | ||||
|  | ||||
|         if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount && 0 !== $sourceCurrency && 0 !== $destinationCurrency) { | ||||
|             $validator->errors()->add('source_amount', (string)trans('validation.numeric_source')); | ||||
|         } | ||||
|  | ||||
|         if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount && 0 !== $sourceCurrency && 0 !== $destinationCurrency) { | ||||
|             $validator->errors()->add('destination_amount', (string)trans('validation.numeric_destination')); | ||||
|             $validator->errors()->add('destination_amount', (string)trans('validation.numeric', ['attribute' => 'destination_amount'])); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if withdrawal amount is valid. | ||||
|      * | ||||
|      * @param Validator $validator | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     private function validateWithdrawal(Validator $validator): void | ||||
|     { | ||||
|         $data             = $validator->getData(); | ||||
|         $selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0); | ||||
|         $accountCurrency  = (int)($data['source_account_currency'] ?? 0); | ||||
|         Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency)); | ||||
|         $nativeAmount = (string)($data['native_amount'] ?? ''); | ||||
|         if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount | ||||
|             && 0 !== $selectedCurrency | ||||
|             && 0 !== $accountCurrency | ||||
|         ) { | ||||
|             Log::debug('ADD validation error on native_amount'); | ||||
|             $validator->errors()->add('native_amount', (string)trans('validation.numeric_native')); | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,71 +0,0 @@ | ||||
| <?php | ||||
| /** | ||||
|  * ReconciliationUpdateRequest.php | ||||
|  * Copyright (c) 2017 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| /** | ||||
|  * Class ReconciliationUpdateRequest. | ||||
|  */ | ||||
| class ReconciliationUpdateRequest extends Request | ||||
| { | ||||
|     /** | ||||
|      * Verify the request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize(): bool | ||||
|     { | ||||
|         // Only allow logged in users | ||||
|         return auth()->check(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns and validates the data required to update a reconciliation. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getJournalData(): array | ||||
|     { | ||||
|         $data = [ | ||||
|             'tags'     => explode(',', $this->string('tags')), | ||||
|             'amount'   => $this->string('amount'), | ||||
|             'category' => $this->string('category'), | ||||
|         ]; | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Rules for this request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules(): array | ||||
|     { | ||||
|         $rules = [ | ||||
|             'amount'   => 'numeric|required', | ||||
|             'category' => 'between:1,255|nullable', | ||||
|         ]; | ||||
|  | ||||
|         return $rules; | ||||
|     } | ||||
| } | ||||
| @@ -1,180 +0,0 @@ | ||||
| <?php | ||||
| /** | ||||
|  * SplitJournalFormRequest.php | ||||
|  * Copyright (c) 2017 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace FireflyIII\Http\Requests; | ||||
|  | ||||
| use Illuminate\Validation\Validator; | ||||
|  | ||||
| /** | ||||
|  * Class SplitJournalFormRequest. | ||||
|  */ | ||||
| class SplitJournalFormRequest extends Request | ||||
| { | ||||
|     /** | ||||
|      * Verify the request. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function authorize(): bool | ||||
|     { | ||||
|         // Only allow logged in users | ||||
|         return auth()->check(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get all info for the controller. | ||||
|      * | ||||
|      * @return array | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     public function getAll(): array | ||||
|     { | ||||
|         $data = [ | ||||
|             'description'     => $this->string('journal_description'), | ||||
|             'type'            => $this->string('what'), | ||||
|             'date'            => $this->date('date'), | ||||
|             'tags'            => explode(',', $this->string('tags')), | ||||
|             'bill_id'         => null, | ||||
|             'bill_name'       => null, | ||||
|             'piggy_bank_id'   => null, | ||||
|             'piggy_bank_name' => null, | ||||
|             'notes'           => $this->string('notes'), | ||||
|             'transactions'    => [], | ||||
|         ]; | ||||
|         // switch type to get correct source / destination info: | ||||
|         $sourceId        = null; | ||||
|         $sourceName      = null; | ||||
|         $destinationId   = null; | ||||
|         $destinationName = null; | ||||
|  | ||||
|         foreach ($this->get('transactions') as $index => $transaction) { | ||||
|             switch ($data['type']) { | ||||
|                 case 'withdrawal': | ||||
|                     $sourceId        = $this->integer('journal_source_id'); | ||||
|                     $destinationName = $transaction['destination_name'] ?? ''; | ||||
|                     break; | ||||
|                 case 'deposit': | ||||
|                     $sourceName    = $transaction['source_name'] ?? ''; | ||||
|                     $destinationId = $this->integer('journal_destination_id'); | ||||
|                     break; | ||||
|                 case 'transfer': | ||||
|                     $sourceId      = $this->integer('journal_source_id'); | ||||
|                     $destinationId = $this->integer('journal_destination_id'); | ||||
|                     break; | ||||
|             } | ||||
|             $foreignAmount          = $transaction['foreign_amount'] ?? null; | ||||
|             $foreignCurrencyId      = (int)($transaction['foreign_currency_id'] ?? 0.0); | ||||
|             $set                    = [ | ||||
|                 'source_id'             => $sourceId, | ||||
|                 'source_name'           => $sourceName, | ||||
|                 'destination_id'        => $destinationId, | ||||
|                 'destination_name'      => $destinationName, | ||||
|                 'foreign_amount'        => $foreignAmount, | ||||
|                 'foreign_currency_id'   => $foreignCurrencyId, | ||||
|                 'foreign_currency_code' => null, | ||||
|                 'reconciled'            => false, | ||||
|                 'identifier'            => $index, | ||||
|                 'currency_id'           => (int)$transaction['currency_id'], | ||||
|                 'currency_code'         => null, | ||||
|                 'description'           => $transaction['transaction_description'] ?? '', | ||||
|                 'amount'                => $transaction['amount'] ?? '', | ||||
|                 'budget_id'             => (int)($transaction['budget_id'] ?? 0.0), | ||||
|                 'budget_name'           => null, | ||||
|                 'category_id'           => null, | ||||
|                 'category_name'         => $transaction['category_name'] ?? '', | ||||
|             ]; | ||||
|             $data['transactions'][] = $set; | ||||
|         } | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Rules for this request. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return [ | ||||
|             'what'                                   => 'required|in:withdrawal,deposit,transfer', | ||||
|             'journal_description'                    => 'required|between:1,255', | ||||
|             'id'                                     => 'numeric|belongsToUser:transaction_journals,id', | ||||
|             'journal_source_id'                      => 'numeric|belongsToUser:accounts,id', | ||||
|             'journal_source_name.*'                  => 'between:1,255', | ||||
|             'journal_currency_id'                    => 'required|exists:transaction_currencies,id', | ||||
|             'date'                                   => 'required|date', | ||||
|             'interest_date'                          => 'date|nullable', | ||||
|             'book_date'                              => 'date|nullable', | ||||
|             'process_date'                           => 'date|nullable', | ||||
|             'transactions.*.transaction_description' => 'required|between:1,255', | ||||
|             'transactions.*.destination_id'          => 'numeric|belongsToUser:accounts,id', | ||||
|             'transactions.*.destination_name'        => 'between:1,255|nullable', | ||||
|             'transactions.*.amount'                  => 'required|numeric', | ||||
|             'transactions.*.budget_id'               => 'belongsToUser:budgets,id', | ||||
|             'transactions.*.category_name'           => 'between:1,255|nullable', | ||||
|             'transactions.*.piggy_bank_id'           => 'numeric|nullable', | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Configure the validator instance. | ||||
|      * | ||||
|      * @param  Validator $validator | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function withValidator(Validator $validator): void | ||||
|     { | ||||
|         $validator->after( | ||||
|             function (Validator $validator) { | ||||
|                 $this->sameAccounts($validator); | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Verify that source and destination are not the same. | ||||
|      * | ||||
|      * @param Validator $validator | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     protected function sameAccounts(Validator $validator): void | ||||
|     { | ||||
|         $data         = $this->getAll(); | ||||
|         $transactions = $data['transactions'] ?? []; | ||||
|         /** @var array $array */ | ||||
|         foreach ($transactions as $array) { | ||||
|             if (null !== $array['destination_id'] && null !== $array['source_id'] && $array['destination_id'] === $array['source_id']) { | ||||
|                 // @codeCoverageIgnoreStart | ||||
|                 $validator->errors()->add('journal_source_id', (string)trans('validation.source_equals_destination')); | ||||
|                 $validator->errors()->add('journal_destination_id', (string)trans('validation.source_equals_destination')); | ||||
|                 // @codeCoverageIgnoreEnd | ||||
|             } | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -39,6 +39,16 @@ class BunqPrerequisites implements PrerequisitesInterface | ||||
|     /** @var User The current user */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * BunqPrerequisites constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         if ('testing' === config('app.env')) { | ||||
|             Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns view name that allows user to fill in prerequisites. | ||||
|      * | ||||
|   | ||||
| @@ -24,6 +24,7 @@ namespace FireflyIII\Import\Prerequisites; | ||||
|  | ||||
| use FireflyIII\User; | ||||
| use Illuminate\Support\MessageBag; | ||||
| use Log; | ||||
|  | ||||
| /** | ||||
|  * This class contains all the routines necessary for the fake import provider. | ||||
| @@ -35,6 +36,16 @@ class FakePrerequisites implements PrerequisitesInterface | ||||
|     /** @var User The current user */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * FakePrerequisites constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         if ('testing' === config('app.env')) { | ||||
|             Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns view name that allows user to fill in prerequisites. Currently asks for the API key. | ||||
|      * | ||||
|   | ||||
| @@ -24,6 +24,7 @@ namespace FireflyIII\Import\Prerequisites; | ||||
|  | ||||
| use FireflyIII\User; | ||||
| use Illuminate\Support\MessageBag; | ||||
| use Log; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -33,6 +34,16 @@ use Illuminate\Support\MessageBag; | ||||
|  */ | ||||
| class FilePrerequisites implements PrerequisitesInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * FilePrerequisites constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         if ('testing' === config('app.env')) { | ||||
|             Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); | ||||
|         } | ||||
|     } | ||||
|     /** | ||||
|      * Returns view name that allows user to fill in prerequisites. | ||||
|      * | ||||
|   | ||||
| @@ -35,6 +35,16 @@ class SpectrePrerequisites implements PrerequisitesInterface | ||||
|     /** @var User The current user */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * SpectrePrerequisites constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         if ('testing' === config('app.env')) { | ||||
|             Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns view name that allows user to fill in prerequisites. | ||||
|      * | ||||
|   | ||||
| @@ -35,6 +35,16 @@ class YnabPrerequisites implements PrerequisitesInterface | ||||
|     /** @var User The current user */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * YnabPrerequisites constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         if ('testing' === config('app.env')) { | ||||
|             Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns view name that allows user to fill in prerequisites. | ||||
|      * | ||||
|   | ||||
| @@ -67,8 +67,6 @@ class FinTSRoutine implements RoutineInterface | ||||
|                     $this->repository->setTransactions($this->importJob, $transactions); | ||||
|                     $this->repository->setStatus($this->importJob, 'provider_finished'); | ||||
|                     $this->repository->setStage($this->importJob, 'final'); | ||||
|  | ||||
|                     return; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -165,7 +165,7 @@ class AbnAmroDescription implements SpecificInterface | ||||
|                         case 'IBAN': | ||||
|                             $this->row[9] = $value; | ||||
|                             break; | ||||
|                         default: | ||||
|                         default: // @codeCoverageIgnore | ||||
|                             // Ignore the rest | ||||
|                     } | ||||
|                 } | ||||
| @@ -224,7 +224,7 @@ class AbnAmroDescription implements SpecificInterface | ||||
|                         case 'TRTP': | ||||
|                             $type = $value; | ||||
|                             break; | ||||
|                         default: | ||||
|                         default: // @codeCoverageIgnore | ||||
|                             // Ignore the rest | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
| @@ -111,6 +111,7 @@ class ImportArrayStorage | ||||
|  | ||||
|         $count = 0; | ||||
|         foreach ($array as $index => $group) { | ||||
|  | ||||
|             foreach ($group['transactions'] as $transaction) { | ||||
|                 if (strtolower(TransactionType::TRANSFER) === strtolower($transaction['type'])) { | ||||
|                     $count++; | ||||
| @@ -213,7 +214,7 @@ class ImportArrayStorage | ||||
|  | ||||
|         $collection = new Collection; | ||||
|         foreach ($array as $index => $group) { | ||||
|             Log::debug(sprintf('Now store #%d', ($index + 1))); | ||||
|             Log::debug(sprintf('Now store #%d', $index + 1)); | ||||
|             $result = $this->storeGroup($index, $group); | ||||
|             if (null !== $result) { | ||||
|                 $collection->push($result); | ||||
| @@ -250,6 +251,7 @@ class ImportArrayStorage | ||||
|         // store the group | ||||
|         try { | ||||
|             $newGroup = $this->groupRepos->store($group); | ||||
|             // @codeCoverageIgnoreStart | ||||
|         } catch (FireflyException $e) { | ||||
|             Log::error($e->getMessage()); | ||||
|             Log::error($e->getTraceAsString()); | ||||
| @@ -257,6 +259,7 @@ class ImportArrayStorage | ||||
|  | ||||
|             return null; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|         Log::debug(sprintf('Stored as group #%d', $newGroup->id)); | ||||
|  | ||||
|         // add to collection of transfers, if necessary: | ||||
| @@ -280,6 +283,7 @@ class ImportArrayStorage | ||||
|      */ | ||||
|     private function duplicateDetected(int $index, array $group): bool | ||||
|     { | ||||
|         Log::debug(sprintf('Now in duplicateDetected(%d)', $index)); | ||||
|         $transactions = $group['transactions'] ?? []; | ||||
|         foreach ($transactions as $transaction) { | ||||
|             $hash       = $this->getHash($transaction); | ||||
| @@ -387,7 +391,7 @@ class ImportArrayStorage | ||||
|      */ | ||||
|     private function transferExists(array $transaction): bool | ||||
|     { | ||||
|         Log::debug('Check if transaction is a double transfer.'); | ||||
|         Log::debug('transferExists() Check if transaction is a double transfer.'); | ||||
|  | ||||
|         // how many hits do we need? | ||||
|         Log::debug(sprintf('System has %d existing transfers', count($this->transfers))); | ||||
| @@ -395,9 +399,11 @@ class ImportArrayStorage | ||||
|  | ||||
|         // check if is a transfer | ||||
|         if (strtolower(TransactionType::TRANSFER) !== strtolower($transaction['type'])) { | ||||
|             // @codeCoverageIgnoreStart | ||||
|             Log::debug(sprintf('Is a %s, not a transfer so no.', $transaction['type'])); | ||||
|  | ||||
|             return false; | ||||
|             // @codeCoverageIgnoreEnd | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -411,7 +417,8 @@ class ImportArrayStorage | ||||
|         } | ||||
|  | ||||
|         // get the description: | ||||
|         $description = '' === (string)$transaction['description'] ? $transaction['description'] : $transaction['description']; | ||||
|         //$description = '' === (string)$transaction['description'] ? $transaction['description'] : $transaction['description']; | ||||
|         $description = (string)$transaction['description']; | ||||
|  | ||||
|         // get the source and destination ID's: | ||||
|         $transactionSourceIDs = [(int)$transaction['source_id'], (int)$transaction['destination_id']]; | ||||
| @@ -467,7 +474,7 @@ class ImportArrayStorage | ||||
|                 ++$hits; | ||||
|                 Log::debug(sprintf('Source IDs are the same! (%d)', $hits)); | ||||
|             } | ||||
|             if ($transactionSourceIDs !== $transactionSourceIDs) { | ||||
|             if ($transactionSourceIDs !== $transferSourceIDs) { | ||||
|                 Log::debug('Source IDs are not the same.'); | ||||
|             } | ||||
|             unset($transferSourceIDs); | ||||
| @@ -566,12 +573,14 @@ class ImportArrayStorage | ||||
|         $tagId      = $tag->id; | ||||
|         foreach ($journalIds as $journalId) { | ||||
|             Log::debug(sprintf('Linking journal #%d to tag #%d...', $journalId, $tagId)); | ||||
|             // @codeCoverageIgnoreStart | ||||
|             try { | ||||
|                 DB::table('tag_transaction_journal')->insert(['transaction_journal_id' => $journalId, 'tag_id' => $tagId]); | ||||
|             } catch (QueryException $e) { | ||||
|                 Log::error(sprintf('Could not link journal #%d to tag #%d because: %s', $journalId, $tagId, $e->getMessage())); | ||||
|                 Log::error($e->getTraceAsString()); | ||||
|             } | ||||
|             // @codeCoverageIgnoreEnd | ||||
|         } | ||||
|         Log::info(sprintf('Linked %d journals to tag #%d ("%s")', $collection->count(), $tag->id, $tag->tag)); | ||||
|  | ||||
| @@ -582,6 +591,8 @@ class ImportArrayStorage | ||||
|     /** | ||||
|      * Applies the users rules to the created journals. | ||||
|      * | ||||
|      * TODO this piece of code must be replaced with the rule engine for consistent processing. | ||||
|      * TODO double for-each is terrible. | ||||
|      * @param Collection $collection | ||||
|      * | ||||
|      */ | ||||
| @@ -589,19 +600,21 @@ class ImportArrayStorage | ||||
|     { | ||||
|         $rules = $this->getRules(); | ||||
|         if ($rules->count() > 0) { | ||||
|             foreach ($collection as $journal) { | ||||
|             /** @var TransactionGroup $group */ | ||||
|             foreach ($collection as $group) { | ||||
|                 $rules->each( | ||||
|                     function (Rule $rule) use ($journal) { | ||||
|                         Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id)); | ||||
|                         /** @var Processor $processor */ | ||||
|                         $processor = app(Processor::class); | ||||
|                         $processor->make($rule); | ||||
|                         $processor->handleTransactionJournal($journal); | ||||
|                         $journal->refresh(); | ||||
|                         if ($rule->stop_processing) { | ||||
|                             return false; | ||||
|                     static function (Rule $rule) use ($group) { | ||||
|                         Log::debug(sprintf('Going to apply rule #%d to group %d.', $rule->id, $group->id)); | ||||
|                         foreach ($group->transactionJournals as $journal) { | ||||
|                             /** @var Processor $processor */ | ||||
|                             $processor = app(Processor::class); | ||||
|                             $processor->make($rule); | ||||
|                             $processor->handleTransactionJournal($journal); | ||||
|                             $journal->refresh(); | ||||
|                             if ($rule->stop_processing) { | ||||
|                                 return false; // @codeCoverageIgnore | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         return true; | ||||
|                     } | ||||
|                 ); | ||||
|   | ||||
| @@ -142,6 +142,7 @@ class TransactionJournal extends Model | ||||
|  | ||||
|     /** | ||||
|      * Checks if tables are joined. | ||||
|      * @codeCoverageIgnore | ||||
|      * | ||||
|      * @param Builder $query | ||||
|      * @param string  $table | ||||
| @@ -225,6 +226,7 @@ class TransactionJournal extends Model | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @codeCoverageIgnore | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isDeposit(): bool | ||||
|   | ||||
| @@ -72,10 +72,6 @@ class ImportProvider implements BinderInterface | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
| //            if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) { | ||||
| //                continue; | ||||
| //            } | ||||
|  | ||||
|             $providers[$providerName] = [ | ||||
|                 'has_prereq'       => (bool)config('import.has_prereq.' . $providerName), | ||||
|                 'allowed_for_demo' => (bool)config(sprintf('import.allowed_for_demo.%s', $providerName)), | ||||
| @@ -91,7 +87,7 @@ class ImportProvider implements BinderInterface | ||||
|             } | ||||
|             $providers[$providerName]['prereq_complete'] = $result; | ||||
|         } | ||||
|         Log::debug(sprintf('Enabled providers: %s', json_encode(array_keys($providers)))); | ||||
|         //Log::debug(sprintf('Enabled providers: %s', json_encode(array_keys($providers)))); | ||||
|  | ||||
|         return $providers; | ||||
|     } | ||||
|   | ||||
| @@ -204,32 +204,6 @@ trait GetConfigurationData | ||||
|  | ||||
|         return $steps; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if forbidden functions are set. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     protected function hasForbiddenFunctions(): bool // validate system config | ||||
|     { | ||||
|         $list      = ['proc_close']; | ||||
|         $forbidden = explode(',', ini_get('disable_functions')); | ||||
|         $trimmed   = array_map( | ||||
|             function (string $value) { | ||||
|                 return trim($value); | ||||
|             }, $forbidden | ||||
|         ); | ||||
|         foreach ($list as $entry) { | ||||
|             if (in_array($entry, $trimmed, true)) { | ||||
|                 Log::error('Method "%s" is FORBIDDEN, so the console command cannot be executed.'); | ||||
|  | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|   | ||||
| @@ -71,130 +71,6 @@ trait ModelInformation | ||||
|         return [$result]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the destination account. Is complex. | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param TransactionType $destinationType | ||||
|      * @param array $data | ||||
|      * | ||||
|      * @return Account | ||||
|      * | ||||
|      * @throws FireflyException | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     protected function getDestinationAccount(TransactionJournal $journal, TransactionType $destinationType, array $data | ||||
|     ): Account // helper for conversion. Get info from obj. | ||||
|     { | ||||
|         /** @var AccountRepositoryInterface $accountRepository */ | ||||
|         $accountRepository = app(AccountRepositoryInterface::class); | ||||
|         /** @var JournalRepositoryInterface $journalRepos */ | ||||
|         $journalRepos       = app(JournalRepositoryInterface::class); | ||||
|         $sourceAccount      = $journalRepos->getJournalSourceAccounts($journal)->first(); | ||||
|         $destinationAccount = $journalRepos->getJournalDestinationAccounts($journal)->first(); | ||||
|         $sourceType         = $journal->transactionType; | ||||
|         $joined             = $sourceType->type . '-' . $destinationType->type; | ||||
|         switch ($joined) { | ||||
|             default: | ||||
|                 throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore | ||||
|             case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: | ||||
|                 // one | ||||
|                 $destination = $sourceAccount; | ||||
|                 break; | ||||
|             case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: | ||||
|                 // two | ||||
|                 $destination = $accountRepository->findNull((int)$data['destination_account_asset']); | ||||
|                 break; | ||||
|             case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: | ||||
|             case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: | ||||
|                 // three and five | ||||
|                 if ('' === $data['destination_account_expense'] || null === $data['destination_account_expense']) { | ||||
|                     // destination is a cash account. | ||||
|                     return $accountRepository->getCashAccount(); | ||||
|                 } | ||||
|                 $data        = [ | ||||
|                     'name'            => $data['destination_account_expense'], | ||||
|                     'account_type'    => 'expense', | ||||
|                     'account_type_id' => null, | ||||
|                     'virtual_balance' => 0, | ||||
|                     'active'          => true, | ||||
|                     'iban'            => null, | ||||
|                 ]; | ||||
|                 $destination = $accountRepository->store($data); | ||||
|                 break; | ||||
|             case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: | ||||
|             case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: | ||||
|                 // four and six | ||||
|                 $destination = $destinationAccount; | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         return $destination; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the source account. | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * @param TransactionType $destinationType | ||||
|      * @param array $data | ||||
|      * | ||||
|      * @return Account | ||||
|      * | ||||
|      * @throws FireflyException | ||||
|      * | ||||
|      * @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||||
|      * @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||||
|      */ | ||||
|     protected function getSourceAccount(TransactionJournal $journal, TransactionType $destinationType, array $data | ||||
|     ): Account // helper for conversion. Get info from obj. | ||||
|     { | ||||
|         /** @var AccountRepositoryInterface $accountRepository */ | ||||
|         $accountRepository = app(AccountRepositoryInterface::class); | ||||
|         /** @var JournalRepositoryInterface $journalRepos */ | ||||
|         $journalRepos       = app(JournalRepositoryInterface::class); | ||||
|         $sourceAccount      = $journalRepos->getJournalSourceAccounts($journal)->first(); | ||||
|         $destinationAccount = $journalRepos->getJournalDestinationAccounts($journal)->first(); | ||||
|         $sourceType         = $journal->transactionType; | ||||
|         $joined             = $sourceType->type . '-' . $destinationType->type; | ||||
|         switch ($joined) { | ||||
|             default: | ||||
|                 throw new FireflyException('Cannot handle ' . $joined); // @codeCoverageIgnore | ||||
|             case TransactionType::WITHDRAWAL . '-' . TransactionType::DEPOSIT: | ||||
|             case TransactionType::TRANSFER . '-' . TransactionType::DEPOSIT: | ||||
|  | ||||
|                 if ('' === $data['source_account_revenue'] || null === $data['source_account_revenue']) { | ||||
|                     // destination is a cash account. | ||||
|                     return $accountRepository->getCashAccount(); | ||||
|                 } | ||||
|  | ||||
|                 $data   = [ | ||||
|                     'name'            => $data['source_account_revenue'], | ||||
|                     'account_type'    => 'revenue', | ||||
|                     'virtual_balance' => 0, | ||||
|                     'active'          => true, | ||||
|                     'account_type_id' => null, | ||||
|                     'iban'            => null, | ||||
|                 ]; | ||||
|                 $source = $accountRepository->store($data); | ||||
|                 break; | ||||
|             case TransactionType::WITHDRAWAL . '-' . TransactionType::TRANSFER: | ||||
|             case TransactionType::TRANSFER . '-' . TransactionType::WITHDRAWAL: | ||||
|                 $source = $sourceAccount; | ||||
|                 break; | ||||
|             case TransactionType::DEPOSIT . '-' . TransactionType::WITHDRAWAL: | ||||
|                 $source = $destinationAccount; | ||||
|                 break; | ||||
|             case TransactionType::DEPOSIT . '-' . TransactionType::TRANSFER: | ||||
|                 $source = $accountRepository->findNull((int)$data['source_account_asset']); | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         return $source; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Create fake triggers to match the bill's properties | ||||
|      * | ||||
| @@ -275,16 +151,4 @@ trait ModelInformation | ||||
|  | ||||
|         return $liabilityTypes; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is transaction opening balance? | ||||
|      * | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     protected function isOpeningBalance(TransactionJournal $journal): bool | ||||
|     { | ||||
|         return TransactionType::OPENING_BALANCE === $journal->transactionType->type; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -489,45 +489,6 @@ trait PeriodOverview | ||||
|         return $entries; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Collect the sum per currency. | ||||
|      * | ||||
|      * @param Collection $collection | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     protected function sumPerCurrency(Collection $collection): array // helper for transactions (math, calculations) | ||||
|     { | ||||
|         $return = []; | ||||
|         /** @var Transaction $transaction */ | ||||
|         foreach ($collection as $transaction) { | ||||
|             $currencyId = (int)$transaction->transaction_currency_id; | ||||
|  | ||||
|             // save currency information: | ||||
|             if (!isset($return[$currencyId])) { | ||||
|                 $currencySymbol      = $transaction->transaction_currency_symbol; | ||||
|                 $decimalPlaces       = $transaction->transaction_currency_dp; | ||||
|                 $currencyCode        = $transaction->transaction_currency_code; | ||||
|                 $return[$currencyId] = [ | ||||
|                     'currency' => [ | ||||
|                         'id'     => $currencyId, | ||||
|                         'code'   => $currencyCode, | ||||
|                         'symbol' => $currencySymbol, | ||||
|                         'dp'     => $decimalPlaces, | ||||
|                     ], | ||||
|                     'sum'      => '0', | ||||
|                     'count'    => 0, | ||||
|                 ]; | ||||
|             } | ||||
|             // save amount: | ||||
|             $return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], $transaction->transaction_amount); | ||||
|             ++$return[$currencyId]['count']; | ||||
|         } | ||||
|         asort($return); | ||||
|  | ||||
|         return $return; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return only transactions where $account is the source. | ||||
|      * @param Account $account | ||||
| @@ -552,6 +513,7 @@ trait PeriodOverview | ||||
|      * @param Account $account | ||||
|      * @param array $journals | ||||
|      * @return array | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     private function filterTransferredIn(Account $account, array $journals): array | ||||
|     { | ||||
| @@ -591,6 +553,7 @@ trait PeriodOverview | ||||
|      * @param array $journals | ||||
|      * | ||||
|      * @return array | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     private function groupByCurrency(array $journals): array | ||||
|     { | ||||
| @@ -635,53 +598,4 @@ trait PeriodOverview | ||||
|  | ||||
|         return $return; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param array $journals | ||||
|      * @return array | ||||
|      */ | ||||
|     private function getJournalsSum(array $journals): array | ||||
|     { | ||||
|         $return = [ | ||||
|             'count' => 0, | ||||
|             'sums'  => [], | ||||
|         ]; | ||||
|         if (0 === count($journals)) { | ||||
|             return $return; | ||||
|         } | ||||
|  | ||||
|         foreach ($journals as $row) { | ||||
|             $return['count']++; | ||||
|             $currencyId = (int)$row['currency_id']; | ||||
|             if (!isset($return['sums'][$currencyId])) { | ||||
|                 $return['sums'][$currencyId] = [ | ||||
|                     'sum'                     => '0', | ||||
|                     'currency_id'             => $currencyId, | ||||
|                     'currency_code'           => $row['currency_code'], | ||||
|                     'currency_symbol'         => $row['currency_symbol'], | ||||
|                     'currency_name'           => $row['currency_name'], | ||||
|                     'currency_decimal_places' => (int)$row['currency_decimal_places'], | ||||
|                 ]; | ||||
|             } | ||||
|             // add amounts: | ||||
|             $return['sums'][$currencyId]['sum'] = bcadd($return['sums'][$currencyId]['sum'], (string)$row['amount']); | ||||
|  | ||||
|             // same but for foreign amounts: | ||||
|             if (null !== $row['foreign_currency_id'] && 0 !== $row['foreign_currency_id']) { | ||||
|                 $foreignCurrencyId                         = (int)$row['foreign_currency_id']; | ||||
|                 $return['sums'][$foreignCurrencyId]        = [ | ||||
|                     'sum'                     => '0', | ||||
|                     'currency_id'             => $foreignCurrencyId, | ||||
|                     'currency_code'           => $row['foreign_currency_code'], | ||||
|                     'currency_symbol'         => $row['foreign_currency_symbol'], | ||||
|                     'currency_name'           => $row['foreign_currency_name'], | ||||
|                     'currency_decimal_places' => (int)$row['foreign_currency_decimal_places'], | ||||
|                 ]; | ||||
|                 $return['sums'][$foreignCurrencyId]['sum'] = bcadd($return['sums'][$foreignCurrencyId]['sum'], (string)$row['foreign_amount']); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $return; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -30,7 +30,6 @@ use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Models\Rule; | ||||
| use FireflyIII\Models\RuleAction; | ||||
| use FireflyIII\Models\RuleTrigger; | ||||
| use FireflyIII\Models\Tag; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||
| @@ -64,6 +63,7 @@ trait RenderPartialViews | ||||
|                 $set->push($exp); | ||||
|             } | ||||
|         } | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $result = view('reports.options.account', compact('set'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
| @@ -71,6 +71,8 @@ trait RenderPartialViews | ||||
|             $result = 'Could not render view.'; | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
| @@ -94,7 +96,6 @@ trait RenderPartialViews | ||||
|  | ||||
|         /** @var PopupReportInterface $popupHelper */ | ||||
|         $popupHelper = app(PopupReportInterface::class); | ||||
|  | ||||
|         $budget  = $budgetRepository->findNull((int)$attributes['budgetId']); | ||||
|         $account = $accountRepository->findNull((int)$attributes['accountId']); | ||||
|  | ||||
| @@ -114,12 +115,14 @@ trait RenderPartialViews | ||||
|                 // row with tag info. | ||||
|                 return 'Firefly cannot handle this type of info-button (BalanceLine::TagRole)'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
|             Log::error(sprintf('Could not render: %s', $e->getMessage())); | ||||
|             $view = 'Firefly III could not render the view. Please see the log files.'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $view; | ||||
|     } | ||||
| @@ -134,6 +137,7 @@ trait RenderPartialViews | ||||
|         /** @var BudgetRepositoryInterface $repository */ | ||||
|         $repository = app(BudgetRepositoryInterface::class); | ||||
|         $budgets    = $repository->getBudgets(); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $result = view('reports.options.budget', compact('budgets'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
| @@ -141,6 +145,8 @@ trait RenderPartialViews | ||||
|             $result = 'Could not render view.'; | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
| @@ -164,12 +170,14 @@ trait RenderPartialViews | ||||
|             $budget = new Budget; | ||||
|         } | ||||
|         $journals = $popupHelper->byBudget($budget, $attributes); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
|             Log::error(sprintf('Could not render: %s', $e->getMessage())); | ||||
|             $view = 'Firefly III could not render the view. Please see the log files.'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $view; | ||||
|     } | ||||
| @@ -195,12 +203,14 @@ trait RenderPartialViews | ||||
|         } | ||||
|  | ||||
|         $journals = $popupHelper->byCategory($category, $attributes); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $view = view('popup.report.category-entry', compact('journals', 'category'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
|             Log::error(sprintf('Could not render: %s', $e->getMessage())); | ||||
|             $view = 'Firefly III could not render the view. Please see the log files.'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $view; | ||||
|     } | ||||
| @@ -215,6 +225,7 @@ trait RenderPartialViews | ||||
|         /** @var CategoryRepositoryInterface $repository */ | ||||
|         $repository = app(CategoryRepositoryInterface::class); | ||||
|         $categories = $repository->getCategories(); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $result = view('reports.options.category', compact('categories'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
| @@ -222,6 +233,8 @@ trait RenderPartialViews | ||||
|             $result = 'Could not render view.'; | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
| @@ -247,12 +260,14 @@ trait RenderPartialViews | ||||
|         } | ||||
|  | ||||
|         $journals = $popupHelper->byExpenses($account, $attributes); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $view = view('popup.report.expense-entry', compact('journals', 'account'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
|             Log::error(sprintf('Could not render: %s', $e->getMessage())); | ||||
|             $view = 'Firefly III could not render the view. Please see the log files.'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $view; | ||||
|     } | ||||
| @@ -357,12 +372,14 @@ trait RenderPartialViews | ||||
|         } | ||||
|  | ||||
|         $journals = $popupHelper->byIncome($account, $attributes); | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $view = view('popup.report.income-entry', compact('journals', 'account'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
|             Log::error(sprintf('Could not render: %s', $e->getMessage())); | ||||
|             $view = 'Firefly III could not render the view. Please see the log files.'; | ||||
|         } | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $view; | ||||
|     } | ||||
| @@ -374,6 +391,7 @@ trait RenderPartialViews | ||||
|      */ | ||||
|     protected function noReportOptions(): string // render a view | ||||
|     { | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $result = view('reports.options.no-options')->render(); | ||||
|         } catch (Throwable $e) { | ||||
| @@ -381,6 +399,8 @@ trait RenderPartialViews | ||||
|             $result = 'Could not render view.'; | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
| @@ -394,6 +414,8 @@ trait RenderPartialViews | ||||
|         /** @var TagRepositoryInterface $repository */ | ||||
|         $repository = app(TagRepositoryInterface::class); | ||||
|         $tags       = $repository->get(); | ||||
|  | ||||
|         // @codeCoverageIgnoreStart | ||||
|         try { | ||||
|             $result = view('reports.options.tag', compact('tags'))->render(); | ||||
|         } catch (Throwable $e) { | ||||
| @@ -401,6 +423,8 @@ trait RenderPartialViews | ||||
|             $result = 'Could not render view.'; | ||||
|         } | ||||
|  | ||||
|         // @codeCoverageIgnoreEnd | ||||
|  | ||||
|         return $result; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -117,7 +117,7 @@ trait RequestInformation | ||||
|             return $content; | ||||
|         } | ||||
|  | ||||
|         return '<p>' . trans('firefly.route_has_no_help') . '</p>'; | ||||
|         return '<p>' . trans('firefly.route_has_no_help') . '</p>'; // @codeCoverageIgnore | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -181,7 +181,7 @@ trait RequestInformation | ||||
|             //Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %s', $key, var_export($shownDemo, true))); | ||||
|         } | ||||
|         if (!is_bool($shownDemo)) { | ||||
|             $shownDemo = true; | ||||
|             $shownDemo = true; // @codeCoverageIgnore | ||||
|         } | ||||
|  | ||||
|         return $shownDemo; | ||||
| @@ -291,6 +291,7 @@ trait RequestInformation | ||||
|      * @param array $data | ||||
|      * | ||||
|      * @return ValidatorContract | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     protected function validator(array $data): ValidatorContract | ||||
|     { | ||||
|   | ||||
| @@ -89,7 +89,7 @@ trait RuleManagement | ||||
|      * @param Request $request | ||||
|      * | ||||
|      * @return array | ||||
|      * | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     protected function getPreviousActions(Request $request): array | ||||
|     { | ||||
| @@ -123,6 +123,7 @@ trait RuleManagement | ||||
|      * @param Request $request | ||||
|      * | ||||
|      * @return array | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     protected function getPreviousTriggers(Request $request): array | ||||
|     { | ||||
|   | ||||
| @@ -95,6 +95,7 @@ trait UserNavigation | ||||
|      * @param TransactionJournal $journal | ||||
|      * | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     protected function redirectToAccount(TransactionJournal $journal) | ||||
|     { | ||||
| @@ -118,6 +119,7 @@ trait UserNavigation | ||||
|      * @param Account $account | ||||
|      * | ||||
|      * @return RedirectResponse|\Illuminate\Routing\Redirector | ||||
|      * @codeCoverageIgnore | ||||
|      */ | ||||
|     protected function redirectToOriginalAccount(Account $account) | ||||
|     { | ||||
|   | ||||
| @@ -43,6 +43,8 @@ | ||||
|             <directory suffix="Test.php">./tests/Unit/Generator</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Handlers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Helpers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Middleware</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Import</directory> | ||||
|         </testsuite> | ||||
|         <testsuite name="Feature"> | ||||
|             <directory suffix="Test.php">./tests/Feature</directory> | ||||
|   | ||||
| @@ -43,6 +43,8 @@ | ||||
|             <directory suffix="Test.php">./tests/Unit/Generator</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Handlers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Helpers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Middleware</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Import</directory> | ||||
|         </testsuite> | ||||
|         <testsuite name="Feature"> | ||||
|             <directory suffix="Test.php">./tests/Feature</directory> | ||||
|   | ||||
| @@ -43,6 +43,8 @@ | ||||
|             <directory suffix="Test.php">./tests/Unit/Generator</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Handlers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Helpers</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Middleware</directory> | ||||
|             <directory suffix="Test.php">./tests/Unit/Import</directory> | ||||
|         </testsuite> | ||||
|         <testsuite name="Feature"> | ||||
|             <directory suffix="Test.php">./tests/Feature</directory> | ||||
|   | ||||
| @@ -13,7 +13,7 @@ | ||||
|     <p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;"> | ||||
|         You can find it in your Firefly III installation:<br /> | ||||
|         {% for journal in journals %} | ||||
|             <a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> ({{ journal|journalTotalAmount }}) | ||||
|             <a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO) | ||||
|         {% endfor %} | ||||
|     </p> | ||||
| {% endif %} | ||||
| @@ -25,7 +25,7 @@ | ||||
|     <ul> | ||||
|         {% for journal in journals %} | ||||
|             <li> | ||||
|                 <a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> ({{ journal|journalTotalAmount }}) | ||||
|                 <a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO) | ||||
|             </li> | ||||
|         {% endfor %} | ||||
|     </ul> | ||||
|   | ||||
| @@ -10,7 +10,7 @@ Firefly III has created {{ journals.count }} transactions for you. | ||||
| You can find in in your Firefly III installation: | ||||
|  | ||||
| {% for journal in journals %} | ||||
| {{ journal.description }}: {{ route('transactions.show', journal.id) }} ({{ journal|journalTotalAmountPlain }}) | ||||
| {{ journal.description }}: {{ route('transactions.show', journal.id) }} (AMOUNT TODO) | ||||
| {% endfor %} | ||||
| {% endif %} | ||||
|  | ||||
| @@ -18,7 +18,7 @@ You can find in in your Firefly III installation: | ||||
| You can find them in your Firefly III installation: | ||||
|  | ||||
| {% for journal in journals %} | ||||
| - {{ journal.description }}: {{ route('transactions.show', journal.id) }} ({{ journal|journalTotalAmountPlain }}) | ||||
| - {{ journal.description }}: {{ route('transactions.show', journal.id) }} (AMOUNT TODO) | ||||
| {% endfor %} | ||||
| {% endif %} | ||||
|  | ||||
|   | ||||
| @@ -23,7 +23,6 @@ declare(strict_types=1); | ||||
| use Carbon\Carbon; | ||||
| use DaveJamesMiller\Breadcrumbs\BreadcrumbsGenerator; | ||||
| use DaveJamesMiller\Breadcrumbs\Exceptions\DuplicateBreadcrumbException; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\Account; | ||||
| use FireflyIII\Models\Attachment; | ||||
| use FireflyIII\Models\Bill; | ||||
| @@ -287,7 +286,10 @@ try { | ||||
|         function (BreadcrumbsGenerator $breadcrumbs, Attachment $attachment) { | ||||
|             $object = $attachment->attachable; | ||||
|             if ($object instanceof TransactionJournal) { | ||||
|                 $breadcrumbs->parent('transactions.show', $object->transactionGroup); | ||||
|                 $group = $object->transactionGroup; | ||||
|                 if (null !== $group) { | ||||
|                     $breadcrumbs->parent('transactions.show', [$object->transactionGroup]); | ||||
|                 } | ||||
|                 $breadcrumbs->push(limitStringLength($attachment->filename), route('attachments.edit', [$attachment])); | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -172,6 +172,8 @@ class ShowControllerTest extends TestCase | ||||
|         $collector    = $this->mock(GroupCollectorInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|          | ||||
|          | ||||
|  | ||||
|         // mock calls | ||||
|         $pref       = new Preference; | ||||
|   | ||||
| @@ -24,7 +24,6 @@ namespace Tests\Feature\Controllers\Import; | ||||
|  | ||||
| use FireflyIII\Import\Prerequisites\BunqPrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\FakePrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\FilePrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\SpectrePrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\YnabPrerequisites; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| @@ -57,10 +56,11 @@ class IndexControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCreateBadJob(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // mock stuff: | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
| @@ -70,14 +70,13 @@ class IndexControllerTest extends TestCase | ||||
|         $importJob->provider = 'fake'; | ||||
|         $importJob->key      = 'fake_job_1'; | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // mock calls: | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->once(); | ||||
|         $fakePrerequisites->shouldReceive('setUser')->once(); | ||||
|         //$fakePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->once(); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         //$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
| @@ -94,13 +93,11 @@ class IndexControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testCreateDemoUser(): void | ||||
|     { | ||||
|         Log::debug(sprintf('Now in test %s', __METHOD__)); | ||||
|         // mock stuff: | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake job: | ||||
|         $importJob           = new ImportJob; | ||||
| @@ -110,21 +107,14 @@ class IndexControllerTest extends TestCase | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // mock calls: | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $fakePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $fakePrerequisites->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->atLeast()->once()->andReturn(true); | ||||
|  | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3); | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('import.create', ['spectre'])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.index')); | ||||
|         $response->assertStatus(404); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -136,10 +126,6 @@ class IndexControllerTest extends TestCase | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake job: | ||||
|         $importJob           = new ImportJob; | ||||
| @@ -151,16 +137,6 @@ class IndexControllerTest extends TestCase | ||||
|  | ||||
|         // mock calls | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3); | ||||
|  | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(false); | ||||
|  | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(false); | ||||
|  | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(false); | ||||
|  | ||||
|         $repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(false); | ||||
| @@ -183,10 +159,6 @@ class IndexControllerTest extends TestCase | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake job: | ||||
|         $importJob           = new ImportJob; | ||||
| @@ -201,14 +173,6 @@ class IndexControllerTest extends TestCase | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true); | ||||
|         $fakePrerequisites->shouldReceive('setUser')->times(3); | ||||
|  | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->times(2); | ||||
|  | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->times(2); | ||||
|  | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->times(2); | ||||
|  | ||||
|  | ||||
|         $repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob); | ||||
| @@ -231,10 +195,8 @@ class IndexControllerTest extends TestCase | ||||
|         // mock stuff: | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake job: | ||||
| @@ -246,12 +208,12 @@ class IndexControllerTest extends TestCase | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // mock calls | ||||
|         $fakePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         //$fakePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->times(2); | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->times(2); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         //$fakePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
| @@ -276,10 +238,8 @@ class IndexControllerTest extends TestCase | ||||
|         // mock stuff: | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
| @@ -303,13 +263,13 @@ class IndexControllerTest extends TestCase | ||||
|         $repository->shouldReceive('getConfiguration')->andReturn($fakeConfig)->once(); | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('setUser')->times(1); | ||||
|         //$fakePrerequisites->shouldReceive('setUser')->times(1); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->times(1); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->times(1); | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->times(1); | ||||
|         //$filePrerequisites->shouldReceive('setUser')->times(1); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true); | ||||
|         //$fakePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->times(1)->andReturn(true); | ||||
| @@ -330,12 +290,10 @@ class IndexControllerTest extends TestCase | ||||
|  | ||||
|         // fake stuff: | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
| @@ -343,12 +301,12 @@ class IndexControllerTest extends TestCase | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false); | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('setUser')->once(); | ||||
|         //$fakePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->once(); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->once(); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         //$fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
| @@ -367,26 +325,14 @@ class IndexControllerTest extends TestCase | ||||
|  | ||||
|         // fake stuff: | ||||
|         $fakePrerequisites    = $this->mock(FakePrerequisites::class); | ||||
|         $bunqPrerequisites    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrerequisites = $this->mock(SpectrePrerequisites::class); | ||||
|         $filePrerequisites    = $this->mock(FilePrerequisites::class); | ||||
|         $userRepository       = $this->mock(UserRepositoryInterface::class); | ||||
|         $ynabPrerequisites    = $this->mock(YnabPrerequisites::class); | ||||
|         $repository           = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // call methods: | ||||
|         $fakePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $bunqPrerequisites->shouldReceive('setUser')->once(); | ||||
|         $spectrePrerequisites->shouldReceive('setUser')->once(); | ||||
|         $ynabPrerequisites->shouldReceive('setUser')->once(); | ||||
|  | ||||
|         $fakePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $bunqPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $spectrePrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|         $ynabPrerequisites->shouldReceive('isComplete')->once()->andReturn(true); | ||||
|  | ||||
|  | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true); | ||||
|         $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false); | ||||
|   | ||||
| @@ -115,7 +115,7 @@ class JobStatusControllerTest extends TestCase | ||||
|     { | ||||
|         $importRepos       = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $userRepos         = $this->mock(UserRepositoryInterface::class); | ||||
|         $tag               = $this->user()->tags()->first(); | ||||
|         $tag               = $this->getRandomTag(); | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
|         $job->key          = 'Cfake_job_' . $this->randomInt(); | ||||
| @@ -127,7 +127,6 @@ class JobStatusControllerTest extends TestCase | ||||
|         $job->save(); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         $importRepos->shouldReceive('countTransactions')->once()->andReturn(0); | ||||
|  | ||||
|         // call thing. | ||||
|   | ||||
| @@ -22,7 +22,10 @@ declare(strict_types=1); | ||||
|  | ||||
| namespace Tests\Feature\Controllers\Import; | ||||
|  | ||||
| use FireflyIII\Import\Prerequisites\BunqPrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\FakePrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\SpectrePrerequisites; | ||||
| use FireflyIII\Import\Prerequisites\YnabPrerequisites; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||
| @@ -57,9 +60,13 @@ class PrerequisitesControllerTest extends TestCase | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq    = $this->mock(FakePrerequisites::class); | ||||
|         $prereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         // mock some prerequisites: | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
|         $job->key          = 'A_pre_job_' . $this->randomInt(); | ||||
| @@ -69,23 +76,25 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $job->file_type    = ''; | ||||
|         $job->save(); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         $prereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $prereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|  | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|  | ||||
|         $prereq->shouldReceive('setUser')->times(2); | ||||
|         $prereq->shouldReceive('isComplete')->times(2)->andReturn(false); | ||||
|         $prereq->shouldReceive('getView')->once()->andReturn('import.fake.prerequisites'); | ||||
|         $prereq->shouldReceive('getViewParameters')->once()->andReturn(['api_key' => '']); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['fake', $job->key])); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key])); | ||||
|         $response->assertStatus(200); | ||||
|  | ||||
|     } | ||||
| @@ -99,6 +108,10 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
| @@ -109,16 +122,20 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $job->file_type    = ''; | ||||
|         $job->save(); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'fake_api_key', null])->andReturnNull(); | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['fake', $job->key])); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.index')); | ||||
|     } | ||||
| @@ -130,29 +147,39 @@ class PrerequisitesControllerTest extends TestCase | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $userRepos  = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq     = $this->mock(FakePrerequisites::class); | ||||
|         $repository = $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->andReturn(true)->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->andReturn(false)->atLeast()->once(); | ||||
|  | ||||
|         //Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(),'x','x'])->atLeast()->once(); | ||||
|  | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
|         $job->key          = 'C_pre_job_' . $this->randomInt(); | ||||
|         $job->status       = 'new'; | ||||
|         $job->provider     = 'fake'; | ||||
|         $job->provider     = 'bunq'; | ||||
|         $job->transactions = []; | ||||
|         $job->file_type    = ''; | ||||
|         $job->save(); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|         $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']); | ||||
|         $prereq->shouldReceive('setUser')->times(2); | ||||
|         $prereq->shouldReceive('isComplete')->times(2)->andReturn(true); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['fake', $job->key])); | ||||
|         $response = $this->get(route('import.prerequisites.index', ['bunq', $job->key])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.job.configuration.index', [$job->key])); | ||||
|  | ||||
| @@ -167,13 +194,23 @@ class PrerequisitesControllerTest extends TestCase | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $userRepos  = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq     = $this->mock(FakePrerequisites::class); | ||||
|         $repository = $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'fake_api_key',null])->andReturnNull(); | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag); | ||||
|  | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
| @@ -186,13 +223,13 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $job->save(); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|         $prereq->shouldReceive('setUser')->times(2); | ||||
|         $prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag); | ||||
|         //$prereq->shouldReceive('setUser')->times(2); | ||||
|         //$prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag); | ||||
|  | ||||
|         $repository->shouldReceive('setStatus')->once()->withArgs([Mockery::any(), 'has_prereq']); | ||||
|         $prereq->shouldReceive('isComplete')->times(1)->andReturn(false); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['fake', $job->key])); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.job.configuration.index', [$job->key])); | ||||
|     } | ||||
| @@ -205,29 +242,41 @@ class PrerequisitesControllerTest extends TestCase | ||||
|     public function testPostBadState(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq    = $this->mock(FakePrerequisites::class); | ||||
|         $userRepos         = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq            = $this->mock(FakePrerequisites::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|  | ||||
|         //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|  | ||||
|         $job          = new ImportJob; | ||||
|         $job->user_id = $this->user()->id; | ||||
|         $job->key          = 'D_pre_job_' . $this->randomInt(); | ||||
|         $job->status       = 'badstate'; | ||||
|         $job->provider     = 'fake'; | ||||
|         $job->provider     = 'bunq'; | ||||
|         $job->transactions = []; | ||||
|         $job->file_type    = ''; | ||||
|         $job->save(); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|         $prereq->shouldReceive('setUser')->times(1); | ||||
|         $prereq->shouldReceive('isComplete')->times(1)->andReturn(false); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['fake', $job->key])); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.index')); | ||||
|         $response->assertSessionHas('error', 'To access this page, your import job cannot have status "badstate".'); | ||||
| @@ -242,23 +291,28 @@ class PrerequisitesControllerTest extends TestCase | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $prereq    = $this->mock(FakePrerequisites::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn(new MessageBag); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $prereq->shouldReceive('setUser')->once(); | ||||
|         $prereq->shouldReceive('storePrerequisites')->once()->andReturn(new MessageBag); | ||||
|  | ||||
|         $prereq->shouldReceive('setUser')->times(1); | ||||
|         $prereq->shouldReceive('isComplete')->times(1)->andReturn(false); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['fake'])); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['bunq'])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.index')); | ||||
|     } | ||||
| @@ -275,16 +329,11 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $prereq    = $this->mock(FakePrerequisites::class); | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'bunq_api_key', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'spectre_app_id', null])->andReturnNull(); | ||||
|         Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'ynab_client_id', null])->andReturnNull(); | ||||
|         //Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'fake_api_key',null])->andReturnNull(); | ||||
|  | ||||
|         $job               = new ImportJob; | ||||
|         $job->user_id      = $this->user()->id; | ||||
|         $job->key          = 'D_pre_job_' . $this->randomInt(); | ||||
|         $job->status       = 'new'; | ||||
|         $job->provider     = 'fake'; | ||||
|         $job->provider     = 'bunq'; | ||||
|         $job->transactions = []; | ||||
|         $job->file_type    = ''; | ||||
|         $job->save(); | ||||
| @@ -293,16 +342,30 @@ class PrerequisitesControllerTest extends TestCase | ||||
|         $messages->add('some', 'message'); | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $prereq->shouldReceive('setUser')->times(1); | ||||
|         $prereq->shouldReceive('isComplete')->times(1)->andReturn(false); | ||||
|  | ||||
|         $prereq->shouldReceive('setUser')->once(); | ||||
|         $prereq->shouldReceive('storePrerequisites')->once()->andReturn($messages); | ||||
|         // mock some prerequisites: | ||||
|         $bunqPrereq    = $this->mock(BunqPrerequisites::class); | ||||
|         $spectrePrereq = $this->mock(SpectrePrerequisites::class); | ||||
|         $ynabPrereq    = $this->mock(YnabPrerequisites::class); | ||||
|  | ||||
|         // fake calls to prereq classes | ||||
|         $bunqPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $spectrePrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $ynabPrereq->shouldReceive('setUser')->atLeast()->once(); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $spectrePrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|         $ynabPrereq->shouldReceive('isComplete')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $bunqPrereq->shouldReceive('storePrerequisites')->atLeast()->once()->andReturn($messages); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['fake', $job->key])); | ||||
|         $response = $this->post(route('import.prerequisites.post', ['bunq', $job->key])); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertRedirect(route('import.prerequisites.index', ['fake', $job->key])); | ||||
|         $response->assertRedirect(route('import.prerequisites.index', ['bunq', $job->key])); | ||||
|         $response->assertSessionHas('error', 'message'); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -252,6 +252,43 @@ class BoxControllerTest extends TestCase | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Json\BoxController | ||||
|      */ | ||||
|     public function testNetWorthPast(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $result = [ | ||||
|             [ | ||||
|                 'currency' => TransactionCurrency::find(1), | ||||
|                 'balance'  => '3', | ||||
|             ], | ||||
|         ]; | ||||
|  | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100'); | ||||
|         $netWorthHelper = $this->mock(NetWorthInterface::class); | ||||
|         $netWorthHelper->shouldReceive('setUser')->once(); | ||||
|         $netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result); | ||||
|  | ||||
|         $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()])); | ||||
|         $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); | ||||
|         $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); | ||||
|         $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset'); | ||||
|         $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1'); | ||||
|  | ||||
|         $start = new Carbon; | ||||
|         $start->subMonths(6)->startOfMonth(); | ||||
|         $end = clone $start; | ||||
|         $end->endOfMonth(); | ||||
|         $this->session(['start' => $start, 'end' => $end]); | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('json.box.net-worth')); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Json\BoxController | ||||
|      */ | ||||
|   | ||||
| @@ -25,7 +25,6 @@ namespace Tests\Feature\Controllers\Popup; | ||||
| use Amount; | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Helpers\Report\PopupReportInterface; | ||||
| use FireflyIII\Models\Budget; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | ||||
| use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | ||||
| @@ -76,6 +75,8 @@ class ReportControllerTest extends TestCase | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('Firefly III cannot handle'); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -103,6 +104,7 @@ class ReportControllerTest extends TestCase | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('Firefly III cannot handle'); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -110,18 +112,17 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testBalanceAmountDefaultNoBudget(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $this->mock(CategoryRepositoryInterface::class); | ||||
|         $accountRepos = $this->mock(AccountRepositoryInterface::class); | ||||
|         $budgetRepos  = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $popupHelper  = $this->mock(PopupReportInterface::class); | ||||
|         $account      = $this->getRandomAsset(); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         $popupHelper->shouldReceive('balanceForNoBudget')->andReturn([]); | ||||
|         $budgetRepos->shouldReceive('findNull')->andReturn(new Budget)->once()->withArgs([0]); | ||||
|         $budgetRepos->shouldReceive('findNull')->andReturn(null)->once()->withArgs([0]); | ||||
|         $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); | ||||
|         $popupHelper->shouldReceive('balanceForBudget')->once()->andReturn([]); | ||||
|         //$popupHelper->shouldReceive('balanceForBudget')->once()->andReturn([]); | ||||
|  | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100'); | ||||
|  | ||||
| @@ -142,6 +143,7 @@ class ReportControllerTest extends TestCase | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee($account->name); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -157,6 +159,7 @@ class ReportControllerTest extends TestCase | ||||
|         $budget       = $this->getRandomBudget(); | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); | ||||
|         $accountRepos->shouldReceive('findNull')->andReturn($account)->once()->withArgs([1]); | ||||
| @@ -178,6 +181,7 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -213,6 +217,7 @@ class ReportControllerTest extends TestCase | ||||
|         $uri      = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -220,8 +225,8 @@ class ReportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testBudgetSpentAmount(): void | ||||
|     { | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $categoryRepos = $this->mock(CategoryRepositoryInterface::class); | ||||
|         $this->mock(AccountRepositoryInterface::class); | ||||
|         $this->mock(CategoryRepositoryInterface::class); | ||||
|         $budgetRepos   = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $popupHelper   = $this->mock(PopupReportInterface::class); | ||||
|         $budget        = $this->getRandomBudget(); | ||||
| @@ -230,6 +235,42 @@ class ReportControllerTest extends TestCase | ||||
|         $budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]); | ||||
|         $popupHelper->shouldReceive('byBudget')->andReturn([]); | ||||
|  | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
|             'attributes' => [ | ||||
|                 'location'   => 'budget-spent-amount', | ||||
|                 'startDate'  => Carbon::now()->startOfMonth()->format('Ymd'), | ||||
|                 'endDate'    => Carbon::now()->endOfMonth()->format('Ymd'), | ||||
|                 'accounts'   => 1, | ||||
|                 'accountId'  => 1, | ||||
|                 'categoryId' => 1, | ||||
|                 'budgetId'   => 1, | ||||
|             ], | ||||
|         ]; | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Popup\ReportController | ||||
|      */ | ||||
|     public function testBudgetSpentAmountNoBudget(): void | ||||
|     { | ||||
|         $this->mock(AccountRepositoryInterface::class); | ||||
|         $this->mock(CategoryRepositoryInterface::class); | ||||
|         $budgetRepos = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $popupHelper = $this->mock(PopupReportInterface::class); | ||||
|  | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         $budgetRepos->shouldReceive('findNull')->andReturnNull()->once()->withArgs([1]); | ||||
|         $popupHelper->shouldReceive('byBudget')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
|             'attributes' => [ | ||||
| @@ -245,6 +286,7 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -261,6 +303,40 @@ class ReportControllerTest extends TestCase | ||||
|         $this->mockDefaultSession(); | ||||
|         $categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]); | ||||
|         $popupHelper->shouldReceive('byCategory')->andReturn([]); | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
|             'attributes' => [ | ||||
|                 'location'   => 'category-entry', | ||||
|                 'startDate'  => Carbon::now()->startOfMonth()->format('Ymd'), | ||||
|                 'endDate'    => Carbon::now()->endOfMonth()->format('Ymd'), | ||||
|                 'accounts'   => 1, | ||||
|                 'accountId'  => 1, | ||||
|                 'categoryId' => 1, | ||||
|                 'budgetId'   => 1, | ||||
|             ], | ||||
|         ]; | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Popup\ReportController | ||||
|      */ | ||||
|     public function testCategoryEntryUnknown(): void | ||||
|     { | ||||
|         $this->mock(BudgetRepositoryInterface::class); | ||||
|         $this->mock(AccountRepositoryInterface::class); | ||||
|         $categoryRepos = $this->mock(CategoryRepositoryInterface::class); | ||||
|         $popupHelper   = $this->mock(PopupReportInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         $categoryRepos->shouldReceive('findNull')->andReturn(null)->once()->withArgs([1]); | ||||
|         $popupHelper->shouldReceive('byCategory')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
| @@ -277,6 +353,8 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|         $response->assertSee('This is an unknown category. Apologies.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -291,6 +369,8 @@ class ReportControllerTest extends TestCase | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $account       = $this->getRandomAsset(); | ||||
|  | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once(); | ||||
|         $popupHelper->shouldReceive('byExpenses')->andReturn([]); | ||||
| @@ -310,6 +390,42 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Popup\ReportController | ||||
|      */ | ||||
|     public function testExpenseEntryUnknown(): void | ||||
|     { | ||||
|         $budgetRepos   = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $categoryRepos = $this->mock(CategoryRepositoryInterface::class); | ||||
|         $popupHelper   = $this->mock(PopupReportInterface::class); | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once(); | ||||
|         $popupHelper->shouldReceive('byExpenses')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
|             'attributes' => [ | ||||
|                 'location'   => 'expense-entry', | ||||
|                 'startDate'  => Carbon::now()->startOfMonth()->format('Ymd'), | ||||
|                 'endDate'    => Carbon::now()->endOfMonth()->format('Ymd'), | ||||
|                 'accounts'   => 1, | ||||
|                 'accountId'  => 1, | ||||
|                 'categoryId' => 1, | ||||
|                 'budgetId'   => 1, | ||||
|             ], | ||||
|         ]; | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|         $response->assertSee('This is an unknown account. Apologies.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -327,6 +443,7 @@ class ReportControllerTest extends TestCase | ||||
|         $this->mockDefaultSession(); | ||||
|         $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once(); | ||||
|         $popupHelper->shouldReceive('byIncome')->andReturn([]); | ||||
|         Amount::shouldReceive('formatAnything')->andReturn('-100')->atLeast()->once(); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
| @@ -343,6 +460,41 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Popup\ReportController | ||||
|      */ | ||||
|     public function testIncomeEntryUnknown(): void | ||||
|     { | ||||
|         $budgetRepos   = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|         $categoryRepos = $this->mock(CategoryRepositoryInterface::class); | ||||
|         $popupHelper   = $this->mock(PopupReportInterface::class); | ||||
|         $accountRepos  = $this->mock(AccountRepositoryInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         $accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once(); | ||||
|         $popupHelper->shouldReceive('byIncome')->andReturn([]); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $arguments = [ | ||||
|             'attributes' => [ | ||||
|                 'location'   => 'income-entry', | ||||
|                 'startDate'  => Carbon::now()->startOfMonth()->format('Ymd'), | ||||
|                 'endDate'    => Carbon::now()->endOfMonth()->format('Ymd'), | ||||
|                 'accounts'   => 1, | ||||
|                 'accountId'  => 1, | ||||
|                 'categoryId' => 1, | ||||
|                 'budgetId'   => 1, | ||||
|             ], | ||||
|         ]; | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -369,5 +521,6 @@ class ReportControllerTest extends TestCase | ||||
|         $uri       = route('popup.general') . '?' . http_build_query($arguments); | ||||
|         $response  = $this->get($uri); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertDontSee('Firefly III could not render the view. Please see the log files.'); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -166,6 +166,127 @@ class CreateControllerTest extends TestCase | ||||
|         $response->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Stores a withdrawal, but destination is invalid | ||||
|      * | ||||
|      * @covers \FireflyIII\Http\Controllers\Recurring\CreateController | ||||
|      * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest | ||||
|      */ | ||||
|     public function testStoreWithdrawalInvalidDest(): void | ||||
|     { | ||||
|         // mock repositories, even if not used. | ||||
|         $this->mock(BudgetRepositoryInterface::class); | ||||
|  | ||||
|         $this->mock(RecurringRepositoryInterface::class); | ||||
|         $validator      = $this->mock(AccountValidator::class); | ||||
|         $source         = $this->getRandomAsset(); | ||||
|         $destination    = $this->getRandomExpense(); | ||||
|         $tomorrow       = Carbon::now()->addDays(2); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         // validator: | ||||
|         $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once(); | ||||
|         $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true); | ||||
|         $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|  | ||||
|         $data = [ | ||||
|             'title'                     => sprintf('hello %d', $this->randomInt()), | ||||
|             'first_date'                => $tomorrow->format('Y-m-d'), | ||||
|             'repetition_type'           => 'daily', | ||||
|             'skip'                      => 0, | ||||
|             'recurring_description'     => sprintf('Some descr %d', $this->randomInt()), | ||||
|             'active'                    => '1', | ||||
|             'apply_rules'               => '1', | ||||
|             'foreign_amount'            => '1', | ||||
|             'foreign_currency_id'       => '2', | ||||
|  | ||||
|             // mandatory for transaction: | ||||
|             'transaction_description'   => 'Some descr', | ||||
|             'transaction_type'          => 'withdrawal', | ||||
|             'transaction_currency_id'   => '1', | ||||
|             'amount'                    => '30', | ||||
|  | ||||
|             // mandatory account info: | ||||
|             'source_id'                 => $source->id, | ||||
|             'withdrawal_destination_id' => $destination->id, | ||||
|  | ||||
|             // optional fields: | ||||
|             'budget_id'                 => '1', | ||||
|             'category'                  => 'CategoryA', | ||||
|             'tags'                      => 'A,B,C', | ||||
|             'create_another'            => '1', | ||||
|             'repetition_end'            => 'times', | ||||
|             'repetitions'               => 3, | ||||
|         ]; | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('recurring.store'), $data); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertSessionHas('errors'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Try to store withdrawal, but the source account is invalid. | ||||
|      * | ||||
|      * @covers \FireflyIII\Http\Controllers\Recurring\CreateController | ||||
|      * @covers \FireflyIII\Http\Requests\RecurrenceFormRequest | ||||
|      */ | ||||
|     public function testStoreWithdrawalInvalidSource(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         // mock repositories, even if not used. | ||||
|         $this->mock(BudgetRepositoryInterface::class); | ||||
|         $this->mock(RecurringRepositoryInterface::class); | ||||
|         $validator      = $this->mock(AccountValidator::class); | ||||
|         $source         = $this->getRandomAsset(); | ||||
|         $destination    = $this->getRandomExpense(); | ||||
|         $tomorrow       = Carbon::now()->addDays(2); | ||||
|  | ||||
|  | ||||
|         // validator: | ||||
|         $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once(); | ||||
|         // source account is invalid. | ||||
|         $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false); | ||||
|  | ||||
|         $data = [ | ||||
|             'title'                     => sprintf('hello %d', $this->randomInt()), | ||||
|             'first_date'                => $tomorrow->format('Y-m-d'), | ||||
|             'repetition_type'           => 'daily', | ||||
|             'skip'                      => 0, | ||||
|             'recurring_description'     => sprintf('Some descr %d', $this->randomInt()), | ||||
|             'active'                    => '1', | ||||
|             'apply_rules'               => '1', | ||||
|             'foreign_amount'            => '1', | ||||
|             'foreign_currency_id'       => '2', | ||||
|  | ||||
|             // mandatory for transaction: | ||||
|             'transaction_description'   => 'Some descr', | ||||
|             'transaction_type'          => 'withdrawal', | ||||
|             'transaction_currency_id'   => '1', | ||||
|             'amount'                    => '30', | ||||
|  | ||||
|             // mandatory account info: | ||||
|             'source_id'                 => $source->id, | ||||
|             'withdrawal_destination_id' => $destination->id, | ||||
|  | ||||
|             // optional fields: | ||||
|             'budget_id'                 => '1', | ||||
|             'category'                  => 'CategoryA', | ||||
|             'tags'                      => 'A,B,C', | ||||
|             'create_another'            => '1', | ||||
|             'repetition_end'            => 'times', | ||||
|             'repetitions'               => 3, | ||||
|         ]; | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->post(route('recurring.store'), $data); | ||||
|         $response->assertStatus(302); | ||||
|         $response->assertSessionHas('errors'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Stores a withdrawal. But throw error. | ||||
|      * | ||||
|   | ||||
| @@ -103,6 +103,62 @@ class IndexControllerTest extends TestCase | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * The last time the recurring job fired it was a long time ago. | ||||
|      * | ||||
|      * @covers \FireflyIII\Http\Controllers\Recurring\IndexController | ||||
|      */ | ||||
|     public function testIndexLongAgo(): void | ||||
|     { | ||||
|  | ||||
|         $repository      = $this->mock(RecurringRepositoryInterface::class); | ||||
|         $budgetRepos     = $this->mock(BudgetRepositoryInterface::class); | ||||
|         $userRepos       = $this->mock(UserRepositoryInterface::class); | ||||
|         $categoryFactory = $this->mock(CategoryFactory::class); | ||||
|         $transformer     = $this->mock(RecurrenceTransformer::class); | ||||
|  | ||||
|         // mock calls | ||||
|         $pref       = new Preference; | ||||
|         $pref->data = 50; | ||||
|         Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|  | ||||
|         $transformer->shouldReceive('setParameters')->atLeast()->once(); | ||||
|         $transformer->shouldReceive('transform')->atLeast()->once()->andReturn( | ||||
|             [ | ||||
|                 'id'           => 5, | ||||
|                 'first_date'   => '2018-01-01', | ||||
|                 'repeat_until' => null, | ||||
|                 'latest_date'  => null, | ||||
|             ] | ||||
|         ); | ||||
|  | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); | ||||
|  | ||||
|         $config       = new Configuration; | ||||
|         $config->data = 1; | ||||
|  | ||||
|         $falseConfig       = new Configuration; | ||||
|         $falseConfig->data = false; | ||||
|  | ||||
|         $collection = $this->user()->recurrences()->take(2)->get(); | ||||
|  | ||||
|         // mock cron job config: | ||||
|         FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config); | ||||
|  | ||||
|         $repository->shouldReceive('get')->andReturn($collection)->once(); | ||||
|  | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('recurring.index')); | ||||
|         $response->assertStatus(200); | ||||
|         $response->assertSee('<ol class="breadcrumb">'); | ||||
|         $response->assertSessionHas('warning'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Recurring\IndexController | ||||
|      */ | ||||
|   | ||||
| @@ -139,8 +139,8 @@ class CreateControllerTest extends TestCase | ||||
|     { | ||||
|         // mock stuff | ||||
|         $repository     = $this->mock(RuleRepositoryInterface::class); | ||||
|         $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $userRepos      = $this->mock(UserRepositoryInterface::class); | ||||
|         $this->mock(RuleGroupRepositoryInterface::class); | ||||
|         $this->mock(UserRepositoryInterface::class); | ||||
|  | ||||
|         $this->mockDefaultSession(); | ||||
|         Preferences::shouldReceive('mark')->atLeast()->once(); | ||||
| @@ -155,7 +155,7 @@ class CreateControllerTest extends TestCase | ||||
|             'title'         => 'A', | ||||
|             'trigger'       => 'store-journal', | ||||
|             'description'   => 'D', | ||||
|             'rule_triggers' => [ | ||||
|             'triggers' => [ | ||||
|                 [ | ||||
|                     'type'            => 'description_is', | ||||
|                     'value'           => 'A', | ||||
| @@ -163,7 +163,7 @@ class CreateControllerTest extends TestCase | ||||
|  | ||||
|                 ], | ||||
|             ], | ||||
|             'rule_actions'  => [ | ||||
|             'actions'  => [ | ||||
|                 [ | ||||
|                     'type'            => 'set_category', | ||||
|                     'value'           => 'C', | ||||
|   | ||||
| @@ -78,6 +78,7 @@ class CreateControllerTest extends TestCase | ||||
|         $repository->shouldReceive('find')->andReturn(new RuleGroup); | ||||
|         $data = [ | ||||
|             'title'       => 'A', | ||||
|             'active'      => '1', | ||||
|             'description' => 'No description', | ||||
|         ]; | ||||
|  | ||||
|   | ||||
| @@ -58,7 +58,11 @@ class IndexControllerTest extends TestCase | ||||
|         $collector = $this->mock(GroupCollectorInterface::class); | ||||
|  | ||||
|         // generic set for the info blocks: | ||||
|         $groupArray = [$this->getRandomWithdrawalAsArray()]; | ||||
|         $groupArray = [ | ||||
|             $this->getRandomWithdrawalAsArray(), | ||||
|             $this->getRandomDepositAsArray(), | ||||
|             $this->getRandomTransferAsArray(), | ||||
|         ]; | ||||
|  | ||||
|         // role? | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true); | ||||
| @@ -88,6 +92,96 @@ class IndexControllerTest extends TestCase | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\IndexController | ||||
|      */ | ||||
|     public function testIndexDeposit(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $group     = $this->getRandomWithdrawalGroup(); | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $collector = $this->mock(GroupCollectorInterface::class); | ||||
|  | ||||
|         // generic set for the info blocks: | ||||
|         $groupArray = [ | ||||
|             $this->getRandomWithdrawalAsArray(), | ||||
|             $this->getRandomDepositAsArray(), | ||||
|             $this->getRandomTransferAsArray(), | ||||
|         ]; | ||||
|  | ||||
|         // role? | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true); | ||||
|  | ||||
|         // make paginator. | ||||
|         $paginator = new LengthAwarePaginator([$group], 1, 40, 1); | ||||
|         Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10'); | ||||
|  | ||||
|         $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator); | ||||
|         $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray); | ||||
|  | ||||
|  | ||||
|         $pref       = new Preference; | ||||
|         $pref->data = 50; | ||||
|         Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); | ||||
|         Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.index', ['deposit'])); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\IndexController | ||||
|      */ | ||||
|     public function testIndexTransfers(): void | ||||
|     { | ||||
|         $this->mockDefaultSession(); | ||||
|         $group     = $this->getRandomWithdrawalGroup(); | ||||
|         $userRepos = $this->mock(UserRepositoryInterface::class); | ||||
|         $collector = $this->mock(GroupCollectorInterface::class); | ||||
|  | ||||
|         // generic set for the info blocks: | ||||
|         $groupArray = [ | ||||
|             $this->getRandomWithdrawalAsArray(), | ||||
|             $this->getRandomDepositAsArray(), | ||||
|             $this->getRandomTransferAsArray(), | ||||
|         ]; | ||||
|  | ||||
|         // role? | ||||
|         $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true); | ||||
|  | ||||
|         // make paginator. | ||||
|         $paginator = new LengthAwarePaginator([$group], 1, 40, 1); | ||||
|         Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('10'); | ||||
|  | ||||
|         $collector->shouldReceive('setTypes')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf(); | ||||
|         $collector->shouldReceive('getPaginatedGroups')->atLeast()->once()->andReturn($paginator); | ||||
|         $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($groupArray); | ||||
|  | ||||
|  | ||||
|         $pref       = new Preference; | ||||
|         $pref->data = 50; | ||||
|         Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); | ||||
|         Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $response = $this->get(route('transactions.index', ['transfers'])); | ||||
|         $response->assertStatus(200); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Controllers\Transaction\IndexController | ||||
|   | ||||
| @@ -286,6 +286,47 @@ abstract class TestCase extends BaseTestCase | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getRandomTransferAsArray(): array | ||||
|     { | ||||
|         $transfer = $this->getRandomTransfer(); | ||||
|         $euro     = $this->getEuro(); | ||||
|         $category = $this->getRandomCategory(); | ||||
|         $source   = $this->getRandomAsset(); | ||||
|         $dest     = $this->getRandomAsset($source->id); | ||||
|         try { | ||||
|             $date = new Carbon; | ||||
|         } catch (Exception $e) { | ||||
|             $e->getMessage(); | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             'transaction_group_id'     => $transfer->transaction_group_id, | ||||
|             'transaction_journal_id'   => $transfer->id, | ||||
|             'transaction_type_type'    => 'Transfer', | ||||
|             'currency_id'              => $euro->id, | ||||
|             'foreign_currency_id'      => null, | ||||
|             'date'                     => $date, | ||||
|             'description'              => sprintf('I am descr #%d', $this->randomInt()), | ||||
|             'source_account_id'        => $source->id, | ||||
|             'source_account_name'      => $source->name, | ||||
|             'foreign_amount'           => null, | ||||
|             'destination_account_id'   => $dest->id, | ||||
|             'destination_account_name' => $dest->name, | ||||
|             'currency_name'            => $euro->name, | ||||
|             'currency_code'            => $euro->code, | ||||
|             'currency_symbol'          => $euro->symbol, | ||||
|  | ||||
|             'currency_decimal_places' => $euro->decimal_places, | ||||
|             'amount'                  => '-30', | ||||
|             'category_id'             => $category->id, | ||||
|             'category_name'           => $category->name, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return array | ||||
|      * @throws Exception | ||||
| @@ -416,9 +457,7 @@ abstract class TestCase extends BaseTestCase | ||||
|      */ | ||||
|     public function demoUser(): User | ||||
|     { | ||||
|         throw new FireflyException('demoUser()-method is obsolete.'); | ||||
|  | ||||
|         return User::find(4); | ||||
|         return User::where('email', 'demo@firefly')->first(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -558,6 +597,14 @@ abstract class TestCase extends BaseTestCase | ||||
|         return $this->getRandomGroup(TransactionType::WITHDRAWAL); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return TransactionGroup | ||||
|      */ | ||||
|     protected function getRandomTransferGroup(): TransactionGroup | ||||
|     { | ||||
|         return $this->getRandomGroup(TransactionType::TRANSFER); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return TransactionGroup | ||||
|      */ | ||||
|   | ||||
| @@ -88,7 +88,7 @@ class BunqJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'bunq_jc_B' . random_int(1, 10000); | ||||
|         $job->key           = 'bunq_jc_B' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'bunq'; | ||||
| @@ -122,7 +122,7 @@ class BunqJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'bunq_jc_C' . random_int(1, 10000); | ||||
|         $job->key           = 'bunq_jc_C' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'bunq'; | ||||
|   | ||||
| @@ -57,7 +57,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'A_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'A_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -84,7 +84,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'B_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'B_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'needs_config'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -110,7 +110,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'C_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'C_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -138,7 +138,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'D_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'D_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'config'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -169,7 +169,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'E_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'E_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -199,7 +199,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'f_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'f_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'config'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -230,7 +230,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'g_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'g_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -257,7 +257,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'h_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'h_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -292,7 +292,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'i_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'i_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -327,7 +327,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'j_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'j_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -362,7 +362,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'k_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'k_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -397,7 +397,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'l_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'l_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -432,7 +432,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'm_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'm_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -467,7 +467,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'n_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'n_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -502,7 +502,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'o_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'o_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -540,7 +540,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'p_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'p_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'not_new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -567,7 +567,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'p_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'p_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -594,7 +594,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'p_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'p_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -621,7 +621,7 @@ class FakeJobConfigurationTest extends TestCase | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'p_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'p_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
|   | ||||
| @@ -63,7 +63,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'File_A_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'File_A_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -88,7 +88,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'File_B_unit_' . random_int(1, 10000); | ||||
|         $job->key           = 'File_B_unit_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'ready_to_run'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -113,7 +113,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'I-Cfile_' . random_int(1, 10000); | ||||
|         $job->key           = 'I-Cfile_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'map'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -150,7 +150,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'G-Dfile_' . random_int(1, 10000); | ||||
|         $job->key           = 'G-Dfile_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'configure-upload'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -185,7 +185,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'H-Efile_' . random_int(1, 10000); | ||||
|         $job->key           = 'H-Efile_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'map'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -220,7 +220,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'F-fFile_' . random_int(1, 10000); | ||||
|         $job->key           = 'F-fFile_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -255,7 +255,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'H-fiGle_' . random_int(1, 10000); | ||||
|         $job->key           = 'H-fiGle_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'roles'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -290,7 +290,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'DfiHle_' . random_int(1, 10000); | ||||
|         $job->key           = 'DfiHle_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'configure-upload'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -320,7 +320,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'FfilIe_' . random_int(1, 10000); | ||||
|         $job->key           = 'FfilIe_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'map'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -350,7 +350,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'CfJile_' . random_int(1, 10000); | ||||
|         $job->key           = 'CfJile_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'file'; | ||||
| @@ -380,7 +380,7 @@ class FileJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once()->atLeast(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'EfiKle_' . random_int(1, 10000); | ||||
|         $job->key           = 'EfiKle_' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'roles'; | ||||
|         $job->provider      = 'file'; | ||||
|   | ||||
							
								
								
									
										167
									
								
								tests/Unit/Import/JobConfiguration/FinTSJobConfigurationTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								tests/Unit/Import/JobConfiguration/FinTSJobConfigurationTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| <?php | ||||
| /** | ||||
|  * FinTSJobConfigurationTest.php | ||||
|  * Copyright (c) 2019 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Tests\Unit\Import\JobConfiguration; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Import\JobConfiguration\FinTSJobConfiguration; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| use FireflyIII\Support\Import\JobConfiguration\FinTS\ChooseAccountHandler; | ||||
| use FireflyIII\Support\Import\JobConfiguration\FinTS\NewFinTSJobHandler; | ||||
| use Log; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class FinTSJobConfigurationTest | ||||
|  */ | ||||
| class FinTSJobConfigurationTest extends TestCase | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         Log::info(sprintf('Now in %s.', get_class($this))); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration | ||||
|      */ | ||||
|     public function testConfigurationComplete(): void | ||||
|     { | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(NewFinTSJobHandler::class); | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'fints_jc_A' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'fints'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         $config = new FinTSJobConfiguration; | ||||
|         $config->setImportJob($job); | ||||
|         $this->assertTrue($config->configurationComplete()); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration | ||||
|      */ | ||||
|     public function testConfigureJob(): void | ||||
|     { | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $handler = $this->mock(NewFinTSJobHandler::class); | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'fints_jc_B' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fints'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         $handler->shouldReceive('setImportJob')->atLeast()->once(); | ||||
|         $handler->shouldReceive('configureJob')->atLeast()->once()->withArgs([[123]]); | ||||
|  | ||||
|  | ||||
|         $config = new FinTSJobConfiguration; | ||||
|         $config->setImportJob($job); | ||||
|         try { | ||||
|             $config->configureJob([123]); | ||||
|         } catch (FireflyException $e) { | ||||
|             $this->assertFalse(true, $e->getMessage()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration | ||||
|      */ | ||||
|     public function testGetNextData(): void | ||||
|     { | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $handler = $this->mock(ChooseAccountHandler::class); | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'fints_jc_C' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'choose_account'; | ||||
|         $job->provider      = 'fints'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         $handler->shouldReceive('setImportJob')->atLeast()->once(); | ||||
|         $handler->shouldReceive('getNextData')->atLeast()->once()->withNoArgs()->andReturn([456]); | ||||
|  | ||||
|  | ||||
|         $res    = []; | ||||
|         $config = new FinTSJobConfiguration; | ||||
|         $config->setImportJob($job); | ||||
|         try { | ||||
|             $res = $config->getNextData(); | ||||
|         } catch (FireflyException $e) { | ||||
|             $this->assertFalse(true, $e->getMessage()); | ||||
|         } | ||||
|         $this->assertEquals([456], $res); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Import\JobConfiguration\FinTSJobConfiguration | ||||
|      */ | ||||
|     public function testGetNextView(): void | ||||
|     { | ||||
|         $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $this->mock(ChooseAccountHandler::class); | ||||
|  | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'fints_jc_D' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'choose_account'; | ||||
|         $job->provider      = 'fints'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         $res    = []; | ||||
|         $config = new FinTSJobConfiguration; | ||||
|         $config->setImportJob($job); | ||||
|         try { | ||||
|             $res = $config->getNextView(); | ||||
|         } catch (FireflyException $e) { | ||||
|             $this->assertFalse(true, $e->getMessage()); | ||||
|         } | ||||
|         $this->assertEquals('import.fints.choose_account', $res); | ||||
|     } | ||||
| } | ||||
| @@ -60,7 +60,7 @@ class SpectreJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'spectre_jc_A' . random_int(1, 10000); | ||||
|         $job->key           = 'spectre_jc_A' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -91,7 +91,7 @@ class SpectreJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'spectre_jc_B' . random_int(1, 10000); | ||||
|         $job->key           = 'spectre_jc_B' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'do-authenticate'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -125,7 +125,7 @@ class SpectreJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'spectre_jc_C' . random_int(1, 10000); | ||||
|         $job->key           = 'spectre_jc_C' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'choose-login'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -157,7 +157,7 @@ class SpectreJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'spectre_jc_D' . random_int(1, 10000); | ||||
|         $job->key           = 'spectre_jc_D' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'authenticated'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -188,7 +188,7 @@ class SpectreJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'spectre_jc_E' . random_int(1, 10000); | ||||
|         $job->key           = 'spectre_jc_E' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'choose-accounts'; | ||||
|         $job->provider      = 'spectre'; | ||||
|   | ||||
| @@ -89,7 +89,7 @@ class YnabJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_jc_B' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_jc_B' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'select_budgets'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -123,7 +123,7 @@ class YnabJobConfigurationTest extends TestCase | ||||
|         $jobRepos->shouldReceive('setUser')->once(); | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_jc_C' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_jc_C' . $this->randomInt(); | ||||
|         $job->status        = 'new'; | ||||
|         $job->stage         = 'select_accounts'; | ||||
|         $job->provider      = 'ynab'; | ||||
|   | ||||
| @@ -56,7 +56,7 @@ class BunqRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'brY_' . random_int(1, 10000); | ||||
|         $job->key           = 'brY_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'bunq'; | ||||
| @@ -96,7 +96,7 @@ class BunqRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'brY_' . random_int(1, 10000); | ||||
|         $job->key           = 'brY_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'bunq'; | ||||
| @@ -140,7 +140,7 @@ class BunqRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'brX_' . random_int(1, 10000); | ||||
|         $job->key           = 'brX_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'bunq'; | ||||
|   | ||||
| @@ -55,7 +55,7 @@ class FakeRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'a_route_' . random_int(1, 10000); | ||||
|         $job->key           = 'a_route_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'ahoy'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -91,7 +91,7 @@ class FakeRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'a_route_' . random_int(1, 10000); | ||||
|         $job->key           = 'a_route_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'final'; | ||||
|         $job->provider      = 'fake'; | ||||
| @@ -128,7 +128,7 @@ class FakeRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'a_route_' . random_int(1, 10000); | ||||
|         $job->key           = 'a_route_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'fake'; | ||||
|   | ||||
| @@ -25,9 +25,11 @@ namespace Tests\Unit\Import\Routine; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Import\Routine\BunqRoutine; | ||||
| use FireflyIII\Import\Routine\FileRoutine; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler; | ||||
| use FireflyIII\Support\Import\Routine\File\CSVProcessor; | ||||
| use Log; | ||||
| use Mockery; | ||||
| @@ -55,35 +57,35 @@ class FileRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'a_fr_' . random_int(1, 10000); | ||||
|         $job->key           = 'brY_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'ready_to_run'; | ||||
|         $job->provider      = 'file'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'bunq'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         // mock | ||||
|         $processor  = $this->mock(CSVProcessor::class); | ||||
|         // mock stuff: | ||||
|         $repository = $this->mock(ImportJobRepositoryInterface::class); | ||||
|         $handler    = $this->mock(StageImportDataHandler::class); | ||||
|  | ||||
|  | ||||
|         // calls | ||||
|         $repository->shouldReceive('setUser')->once(); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once(); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once(); | ||||
|         $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once(); | ||||
|         $repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once(); | ||||
|         $repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->once()->andReturn([]); | ||||
|         $processor->shouldReceive('setImportJob')->once(); | ||||
|         $processor->shouldReceive('run')->once()->andReturn(['a' => 'b']); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']); | ||||
|         $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']); | ||||
|         $repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once(); | ||||
|  | ||||
|  | ||||
|         $routine = new FileRoutine; | ||||
|         $handler->shouldReceive('setImportJob')->once(); | ||||
|         $handler->shouldReceive('run')->once(); | ||||
|         $handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']); | ||||
|         $handler->shouldReceive('isStillRunning')->andReturn(false); | ||||
|         $routine = new BunqRoutine; | ||||
|         $routine->setImportJob($job); | ||||
|         try { | ||||
|             $routine->run(); | ||||
|         } catch (FireflyException $e) { | ||||
|             $this->assertTrue(false, $e->getMessage()); | ||||
|             $this->assertFalse(true, $e->getMessage()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										87
									
								
								tests/Unit/Import/Routine/FinTSRoutineTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								tests/Unit/Import/Routine/FinTSRoutineTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| <?php | ||||
| /** | ||||
|  * FinTSRoutineTest.php | ||||
|  * Copyright (c) 2019 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Tests\Unit\Import\Routine; | ||||
|  | ||||
|  | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Import\Routine\FinTSRoutine; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler; | ||||
| use Log; | ||||
| use Mockery; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class FinTSRoutineTest | ||||
|  */ | ||||
| class FinTSRoutineTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         Log::info(sprintf('Now in %s.', get_class($this))); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Import\Routine\FinTSRoutine | ||||
|      */ | ||||
|     public function testRunDefault(): void | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'a_fin_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'fints'; | ||||
|         $job->file_type     = ''; | ||||
|         $job->configuration = []; | ||||
|         $job->save(); | ||||
|  | ||||
|         // mock | ||||
|         $handler    = $this->mock(StageImportDataHandler::class); | ||||
|         $repository = $this->mock(ImportJobRepositoryInterface::class); | ||||
|  | ||||
|         // calls | ||||
|         $repository->shouldReceive('setUser')->atLeast()->once(); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once(); | ||||
|         $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once(); | ||||
|         $repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once(); | ||||
|         $repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once(); | ||||
|  | ||||
|         $handler->shouldReceive('setImportJob')->atLeast()->once(); | ||||
|         $handler->shouldReceive('run')->once()->atLeast()->once(); | ||||
|         $handler->shouldReceive('getTransactions')->atLeast()->once()->andReturn(['a' => 'b']); | ||||
|  | ||||
|  | ||||
|         $routine = new FinTSRoutine; | ||||
|         $routine->setImportJob($job); | ||||
|         try { | ||||
|             $routine->run(); | ||||
|         } catch (FireflyException $e) { | ||||
|             $this->assertTrue(false, $e->getMessage()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -57,7 +57,7 @@ class SpectreRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'SR2b' . random_int(1, 10000); | ||||
|         $job->key           = 'SR2b' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'authenticated'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -95,7 +95,7 @@ class SpectreRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'SR1A' . random_int(1, 10000); | ||||
|         $job->key           = 'SR1A' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'do-authenticate'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -126,7 +126,7 @@ class SpectreRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'SR3c' . random_int(1, 10000); | ||||
|         $job->key           = 'SR3c' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -165,7 +165,7 @@ class SpectreRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'SR4A' . random_int(1, 10000); | ||||
|         $job->key           = 'SR4A' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'spectre'; | ||||
| @@ -205,7 +205,7 @@ class SpectreRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'SR5A' . random_int(1, 10000); | ||||
|         $job->key           = 'SR5A' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'new'; | ||||
|         $job->provider      = 'spectre'; | ||||
|   | ||||
| @@ -57,7 +57,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_7_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_7_' . $this->randomInt(); | ||||
|         $job->status        = 'not_ready_to_run'; | ||||
|         $job->stage         = 'bad_state'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -88,7 +88,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_6_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_6_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'bad_state'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -119,7 +119,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_1_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_1_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'get_access_token'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -158,7 +158,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_4_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_4_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'get_accounts'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -198,7 +198,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_5_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_5_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'go-for-import'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -239,7 +239,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_2_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_2_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'get_budgets'; | ||||
|         $job->provider      = 'ynab'; | ||||
| @@ -281,7 +281,7 @@ class YnabRoutineTest extends TestCase | ||||
|     { | ||||
|         $job                = new ImportJob; | ||||
|         $job->user_id       = $this->user()->id; | ||||
|         $job->key           = 'ynab_r_3_' . random_int(1, 10000); | ||||
|         $job->key           = 'ynab_r_3_' . $this->randomInt(); | ||||
|         $job->status        = 'ready_to_run'; | ||||
|         $job->stage         = 'get_budgets'; | ||||
|         $job->provider      = 'ynab'; | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -43,7 +43,7 @@ class IsDemoUserTest extends TestCase | ||||
|         parent::setUp(); | ||||
|         Log::info(sprintf('Now in %s.', get_class($this))); | ||||
|         Route::middleware([StartFireflySession::class, IsDemoUser::class])->any( | ||||
|             '/_test/is-demo', function () { | ||||
|             '/_test/is-demo', static function () { | ||||
|             return 'OK'; | ||||
|         } | ||||
|         ); | ||||
| @@ -68,6 +68,7 @@ class IsDemoUserTest extends TestCase | ||||
|         $response = $this->get('/_test/is-demo'); | ||||
|         $this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode()); | ||||
|         $response->assertSessionHas('info'); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -42,7 +42,7 @@ class IsSandstormUserTest extends TestCase | ||||
|         parent::setUp(); | ||||
|         Log::info(sprintf('Now in %s.', get_class($this))); | ||||
|         Route::middleware(IsSandStormUser::class)->any( | ||||
|             '/_test/is-sandstorm', function () { | ||||
|             '/_test/is-sandstorm',static function () { | ||||
|             return 'OK'; | ||||
|         } | ||||
|         ); | ||||
|   | ||||
| @@ -71,4 +71,18 @@ class SandstormTest extends TestCase | ||||
|  | ||||
|         putenv('SANDSTORM=0'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Middleware\Sandstorm | ||||
|      */ | ||||
|     public function testMiddlewareNotSandstorm(): void | ||||
|     { | ||||
|         putenv('SANDSTORM=0'); | ||||
|  | ||||
|         $response = $this->get('/_test/sandstorm'); | ||||
|         $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||||
|         $response->assertSee('sandstorm-anon: false'); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										113
									
								
								tests/Unit/Middleware/SecureHeadersTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								tests/Unit/Middleware/SecureHeadersTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,113 @@ | ||||
| <?php | ||||
| /** | ||||
|  * SecureHeadersTest.php | ||||
|  * Copyright (c) 2019 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * 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 | ||||
|  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Tests\Unit\Middleware; | ||||
|  | ||||
| use Config; | ||||
| use FireflyIII\Http\Middleware\SecureHeaders; | ||||
| use Log; | ||||
| use Route; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Tests\TestCase; | ||||
|  | ||||
| /** | ||||
|  * Class SecureHeadersTest | ||||
|  */ | ||||
| class SecureHeadersTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * Set up test | ||||
|      */ | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         Log::info(sprintf('Now in %s.', get_class($this))); | ||||
|         Route::middleware(SecureHeaders::class)->any( | ||||
|             '/_test/secureheaders', static function () { | ||||
|             return view('test.test'); | ||||
|         } | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Middleware\SecureHeaders | ||||
|      */ | ||||
|     public function testMiddlewareBasic(): void | ||||
|     { | ||||
|         $response = $this->get('/_test/secureheaders'); | ||||
|         $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||||
|  | ||||
|         // verify headers | ||||
|  | ||||
|         $response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' ; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com ; manifest-src 'self'; form-action 'self'"); | ||||
|         $response->assertheader('X-XSS-Protection', '1; mode=block'); | ||||
|         $response->assertHeader('X-Frame-Options', 'deny'); | ||||
|         $response->assertheader('X-Content-Type-Options', 'nosniff'); | ||||
|         $response->assertheader('Referrer-Policy', 'no-referrer'); | ||||
|         $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Middleware\SecureHeaders | ||||
|      */ | ||||
|     public function testMiddlewareGoogleAnalytics(): void | ||||
|     { | ||||
|         // response changes when config value is different. | ||||
|         Config::set('firefly.analytics_id', 'abc'); | ||||
|  | ||||
|         $response = $this->get('/_test/secureheaders'); | ||||
|         $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||||
|  | ||||
|         // verify headers | ||||
|  | ||||
|         $response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' www.googletagmanager.com/gtag/js https://www.google-analytics.com/analytics.js; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com https://www.google-analytics.com/; manifest-src 'self'; form-action 'self'"); | ||||
|         $response->assertheader('X-XSS-Protection', '1; mode=block'); | ||||
|         $response->assertheader('X-Content-Type-Options', 'nosniff'); | ||||
|         $response->assertheader('Referrer-Policy', 'no-referrer'); | ||||
|         $response->assertHeader('X-Frame-Options', 'deny'); | ||||
|         $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'"); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \FireflyIII\Http\Middleware\SecureHeaders | ||||
|      */ | ||||
|     public function testMiddlewareFrameHeader(): void | ||||
|     { | ||||
|         // response changes when config value is different. | ||||
|         Config::set('firefly.disable_frame_header', true); | ||||
|  | ||||
|         $response = $this->get('/_test/secureheaders'); | ||||
|         $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); | ||||
|  | ||||
|         // verify headers | ||||
|  | ||||
|         $response->assertHeader('Content-Security-Policy', "default-src 'none'; object-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' ; style-src 'self' 'unsafe-inline'; base-uri 'self'; font-src 'self' data:; connect-src 'self'; img-src 'self' data: https://api.tiles.mapbox.com ; manifest-src 'self'; form-action 'self'"); | ||||
|         $response->assertheader('X-XSS-Protection', '1; mode=block'); | ||||
|         $response->assertheader('X-Content-Type-Options', 'nosniff'); | ||||
|         $response->assertheader('Referrer-Policy', 'no-referrer'); | ||||
|         $response->assertHeaderMissing('X-Frame-Options'); | ||||
|         $response->assertheader('Feature-Policy', "geolocation 'none'; midi 'none'; sync-xhr 'self'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'"); | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user