mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	I think this covers everything.
This commit is contained in:
		| @@ -96,7 +96,7 @@ class RecurringTransaction extends Ardent | ||||
|                     $start->addMonths($skip * 6); | ||||
|                     break; | ||||
|                 case 'yearly': | ||||
|                     $this->addYears($skip); | ||||
|                     $start->addYears($skip); | ||||
|                     break; | ||||
|  | ||||
|             } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| <?php | ||||
|  | ||||
| use LaravelBook\Ardent\Ardent; | ||||
|  | ||||
| /** | ||||
|  * TransactionType | ||||
| @@ -14,16 +15,16 @@ | ||||
|  * @method static \Illuminate\Database\Query\Builder|\TransactionType whereUpdatedAt($value) | ||||
|  * @method static \Illuminate\Database\Query\Builder|\TransactionType whereType($value) | ||||
|  */ | ||||
| class TransactionType extends Eloquent | ||||
| class TransactionType extends Ardent | ||||
| { | ||||
|     public function transactionJournals() | ||||
|     { | ||||
|         return $this->hasMany('TransactionJournal'); | ||||
|     } | ||||
|  | ||||
|     public static $factory | ||||
|         = [ | ||||
|             'type' => 'string' | ||||
|         ]; | ||||
|  | ||||
|     public function transactionJournals() | ||||
|     { | ||||
|         return $this->hasMany('TransactionJournal'); | ||||
|     } | ||||
|  | ||||
| }  | ||||
| @@ -91,11 +91,6 @@ class User extends Ardent implements UserInterface, RemindableInterface | ||||
|         return $this->hasMany('Component'); | ||||
|     } | ||||
|  | ||||
|     public function piggybanks() | ||||
|     { | ||||
|         return $this->hasMany('Piggybank'); | ||||
|     } | ||||
|  | ||||
|     public function preferences() | ||||
|     { | ||||
|         return $this->hasMany('Preference'); | ||||
|   | ||||
| @@ -97,20 +97,240 @@ class ModelTest extends TestCase | ||||
|         $rep->save(); | ||||
|         $limit->save(); | ||||
|  | ||||
|         $this->assertEquals($rep->limit_id,$limit->id); | ||||
|         $this->assertEquals($rep->limit_id, $limit->id); | ||||
|         $this->assertEquals($limit->component_id, $budget->id); | ||||
|  | ||||
|         // create repetition: | ||||
|         $start = new Carbon; | ||||
|         $list = ['daily','weekly','monthly','quarterly','half-year','yearly']; | ||||
|         foreach($list as $entry) { | ||||
|         $list = ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly']; | ||||
|         foreach ($list as $entry) { | ||||
|             $limit->repeat_freq = $entry; | ||||
|             $limit->createRepetition($start); | ||||
|         } | ||||
|  | ||||
|         // try and fail: | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @expectedException \Firefly\Exception\FireflyException | ||||
|      */ | ||||
|     public function testLimitrepetition() | ||||
|     { | ||||
|         $limit = f::create('Limit'); | ||||
|         $rep = f::create('LimitRepetition'); | ||||
|         $budget = f::create('Budget'); | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $one = f::create('Transaction'); | ||||
|         $two = f::create('Transaction'); | ||||
|         $one->amount = 300; | ||||
|         $two->amount = -300; | ||||
|  | ||||
|         $rep->limit()->associate($limit); | ||||
|         $limit->budget()->associate($budget); | ||||
|         $journal->transactions()->save($one); | ||||
|         $journal->transactions()->save($two); | ||||
|         $journal->budgets()->save($budget); | ||||
|  | ||||
|         $this->assertEquals(($rep->amount - 300), $rep->left()); | ||||
|  | ||||
|         // repeat frequency (not present) for periodOrder | ||||
|         $testDate = new Carbon; | ||||
|         $testDate->startOfMonth(); | ||||
|         $rep->repeat_freq = null; | ||||
|         $this->assertEquals($testDate->format('Ymd') . '-3', $rep->periodOrder()); | ||||
|  | ||||
|         // repeat frequency (present) for periodOrder | ||||
|         $list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily']; | ||||
|         foreach ($list as $index => $entry) { | ||||
|             $rep->repeat_freq = $entry; | ||||
|             $this->assertEquals($testDate->format('Ymd') . '-' . $index, $rep->periodOrder()); | ||||
|         } | ||||
|  | ||||
|         // repeat freq (invalid) for periodOrder | ||||
|         $rep->repeat_freq = 'bad'; | ||||
|         $rep->periodOrder(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @expectedException \Firefly\Exception\FireflyException | ||||
|      */ | ||||
|     public function testLimitrepetitionContinued() | ||||
|     { | ||||
|         $limit = f::create('Limit'); | ||||
|         $rep = f::create('LimitRepetition'); | ||||
|         $budget = f::create('Budget'); | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $one = f::create('Transaction'); | ||||
|         $two = f::create('Transaction'); | ||||
|         $one->amount = 300; | ||||
|         $two->amount = -300; | ||||
|  | ||||
|         $rep->limit()->associate($limit); | ||||
|         $limit->budget()->associate($budget); | ||||
|         $journal->transactions()->save($one); | ||||
|         $journal->transactions()->save($two); | ||||
|         $journal->budgets()->save($budget); | ||||
|  | ||||
|         // repeat frequency (not present) for periodShow | ||||
|         $testDate = new Carbon; | ||||
|         $testDate->startOfMonth(); | ||||
|         $rep->repeat_freq = null; | ||||
|         $this->assertEquals($testDate->format('F Y'), $rep->periodShow()); | ||||
|  | ||||
|         // repeat frequency (present) for periodOrder | ||||
|         $list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily']; | ||||
|         foreach ($list as $index => $entry) { | ||||
|             $rep->repeat_freq = $entry; | ||||
|             $this->assertGreaterThan(0, strlen($rep->periodShow())); | ||||
|         } | ||||
|  | ||||
|         // repeat freq (invalid) for periodOrder | ||||
|         $rep->repeat_freq = 'bad'; | ||||
|         $rep->periodShow(); | ||||
|     } | ||||
|  | ||||
|     public function testPiggybank() | ||||
|     { | ||||
|         $piggy = f::create('Piggybank'); | ||||
|         $account = f::create('Account'); | ||||
|         $piggy->account()->associate($account); | ||||
|  | ||||
|         $this->assertEquals($account->id, $piggy->account_id); | ||||
|     } | ||||
|  | ||||
|     public function testPreference() | ||||
|     { | ||||
|         $pref = f::create('Preference'); | ||||
|         $user = f::create('User'); | ||||
|         $pref->user()->associate($user); | ||||
|         $this->assertEquals($pref->user_id, $user->id); | ||||
|         $pref->data = 'Hello'; | ||||
|         $this->assertEquals($pref->data, 'Hello'); | ||||
|     } | ||||
|  | ||||
|     public function testRecurringtransaction() | ||||
|     { | ||||
|         $rec = f::create('RecurringTransaction'); | ||||
|         $user = f::create('User'); | ||||
|         $rec->user()->associate($user); | ||||
|         $this->assertEquals($rec->user_id, $user->id); | ||||
|  | ||||
|         $list = ['yearly', 'half-year', 'quarterly', 'monthly', 'weekly', 'daily']; | ||||
|         foreach ($list as $index => $entry) { | ||||
|             $start = clone $rec->date; | ||||
|             $rec->repeat_freq = $entry; | ||||
|             $end = $rec->next(); | ||||
|             $this->assertTrue($end > $start); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function testTransaction() | ||||
|     { | ||||
|         $transaction = f::create('Transaction'); | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $component = f::create('Component'); | ||||
|         $budget = f::create('Budget'); | ||||
|         $category = f::create('Category'); | ||||
|         $account = f::create('Account'); | ||||
|  | ||||
|         $transaction->transactionJournal()->associate($journal); | ||||
|         $this->assertEquals($transaction->transaction_journal_id, $journal->id); | ||||
|         $transaction->components()->save($component); | ||||
|         $this->assertEquals($transaction->components()->first()->id, $component->id); | ||||
|         $transaction->budgets()->save($budget); | ||||
|         $this->assertEquals($transaction->budgets()->first()->id, $budget->id); | ||||
|         $transaction->categories()->save($category); | ||||
|         $this->assertEquals($transaction->categories()->first()->id, $category->id); | ||||
|         $transaction->account()->associate($account); | ||||
|         $this->assertEquals($transaction->account_id, $account->id); | ||||
|     } | ||||
|  | ||||
|     public function testTransactionCurrency() | ||||
|     { | ||||
|         $cur = f::create('TransactionCurrency'); | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $cur->transactionjournals()->save($journal); | ||||
|         $journal->save(); | ||||
|         $cur->save(); | ||||
|         $this->assertEquals($cur->id, $journal->transaction_currency_id); | ||||
|     } | ||||
|  | ||||
|     public function testTransactionJournal() | ||||
|     { | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $type = f::create('TransactionType'); | ||||
|         $user = f::create('User'); | ||||
|         $cur = f::create('TransactionCurrency'); | ||||
|         $transaction = f::create('Transaction'); | ||||
|         $component = f::create('Component'); | ||||
|         $budget = f::create('Budget'); | ||||
|         $category = f::create('Category'); | ||||
|  | ||||
|         $journal->transactionType()->associate($type); | ||||
|         $this->assertEquals($type->id, $journal->transaction_type_id); | ||||
|  | ||||
|         $journal->user()->associate($user); | ||||
|         $this->assertEquals($user->id, $journal->user_id); | ||||
|  | ||||
|         $journal->transactionCurrency()->associate($cur); | ||||
|         $this->assertEquals($cur->id, $journal->transaction_currency_id); | ||||
|  | ||||
|         $journal->transactions()->save($transaction); | ||||
|         $this->assertEquals($journal->transactions()->first()->id, $transaction->id); | ||||
|  | ||||
|         $journal->components()->save($component); | ||||
|         $this->assertEquals($journal->components()->first()->id, $component->id); | ||||
|  | ||||
|         $journal->budgets()->save($budget); | ||||
|         $this->assertEquals($journal->budgets()->first()->id, $budget->id); | ||||
|  | ||||
|         $journal->categories()->save($category); | ||||
|         $this->assertEquals($journal->categories()->first()->id, $category->id); | ||||
|     } | ||||
|  | ||||
|     public function testTransactionType() | ||||
|     { | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|         $type = f::create('TransactionType'); | ||||
|  | ||||
|         $type->transactionjournals()->save($journal); | ||||
|         $this->assertEquals($type->transactionJournals()->first()->id, $journal->id); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testUser() | ||||
|     { | ||||
|         $user = f::create('User'); | ||||
|  | ||||
|         $account = f::create('Account'); | ||||
|         $bud = f::create('Budget'); | ||||
|         $cat = f::create('Category'); | ||||
|         $comp = f::create('Component'); | ||||
|         $pref = f::create('Preference'); | ||||
|         $rec = f::create('RecurringTransaction'); | ||||
|         $journal = f::create('TransactionJournal'); | ||||
|  | ||||
|         $user->accounts()->save($account); | ||||
|         $this->assertEquals($account->id,$user->accounts()->first()->id); | ||||
|  | ||||
|         $user->components()->save($comp); | ||||
|         $this->assertEquals($comp->id,$user->components()->first()->id); | ||||
|  | ||||
|         $user->budgets()->save($bud); | ||||
|         $this->assertEquals($bud->id,$user->budgets()->first()->id); | ||||
|  | ||||
|         $user->categories()->save($cat); | ||||
|         $this->assertEquals($cat->id,$user->categories()->first()->id); | ||||
|  | ||||
|         $user->preferences()->save($pref); | ||||
|         $this->assertEquals($pref->id,$user->preferences()->first()->id); | ||||
|  | ||||
|         $user->recurringtransactions()->save($rec); | ||||
|         $this->assertEquals($rec->id,$user->recurringtransactions()->first()->id); | ||||
|  | ||||
|         $user->transactionjournals()->save($journal); | ||||
|         $this->assertEquals($journal->id,$user->transactionjournals()->first()->id); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user