diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index f07a8a3a66..dedc2809d9 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -5,8 +5,10 @@ use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; use FireflyIII\Models\Bill; use FireflyIII\Models\Budget; -use FireflyIII\Models\Category; use FireflyIII\Models\BudgetLimit; +use FireflyIII\Models\Category; +use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\PiggyBankEvent; use FireflyIII\User; use Illuminate\Database\Seeder; @@ -36,6 +38,9 @@ class TestDataSeeder extends Seeder // create some categories for user #1 $this->createCategories($user); + + // create some piggy banks for user #1 + $this->createPiggybanks($user); } /** @@ -113,7 +118,7 @@ class TestDataSeeder extends Seeder */ private function createBudgets($user) { - $set = [ + $set = [ Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]), Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]), ]; @@ -122,8 +127,8 @@ class TestDataSeeder extends Seeder foreach ($set as $budget) { // some budget limits: - $start = clone $current; - $end = clone $current; + $start = clone $current; + $end = clone $current; $start->startOfMonth(); $end->endOfMonth(); @@ -147,4 +152,162 @@ class TestDataSeeder extends Seeder Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]); Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); } + + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @param User $user + */ + protected function createPiggybanks(User $user) + { + $account = $this->findAccount($user, 'TestData Savings'); + + $camera = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New camera', + 'targetamount' => 1000, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 1, + ] + ); + $repetition = $camera->piggyBankRepetitions()->first(); + $repetition->currentamount = 735; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-05-01', + 'amount' => '245', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-06-01', + 'amount' => '245', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-07-01', + 'amount' => '245', + ] + ); + + + $phone = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New phone', + 'targetamount' => 600, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 2, + ] + ); + $repetition = $phone->piggyBankRepetitions()->first(); + $repetition->currentamount = 333; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-05-01', + 'amount' => '111', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-06-01', + 'amount' => '111', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-07-01', + 'amount' => '111', + ] + ); + + $couch = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New couch', + 'targetamount' => 500, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 3, + ] + ); + $repetition = $couch->piggyBankRepetitions()->first(); + $repetition->currentamount = 120; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-05-01', + 'amount' => '40', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-06-01', + 'amount' => '40', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-07-01', + 'amount' => '40', + ] + ); + + // empty one. + PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New head set', + 'targetamount' => 500, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 4, + ] + ); + + } + + /** + * @param User $user + * @param $name + * + * @return Account|null + */ + protected function findAccount(User $user, $name) + { + /** @var Account $account */ + foreach (Account::get() as $account) { + if ($account->name == $name && $user->id == $account->user_id) { + return $account; + break; + } + } + + return null; + } } diff --git a/tests/acceptance/Controllers/AccountControllerTest.php b/tests/acceptance/Controllers/AccountControllerTest.php index b8973d6d34..f4cd9ac26b 100644 --- a/tests/acceptance/Controllers/AccountControllerTest.php +++ b/tests/acceptance/Controllers/AccountControllerTest.php @@ -99,18 +99,25 @@ class AccountControllerTest extends TestCase $this->assertEquals(302, $response->status()); $this->assertSessionHas('success'); - $this->markTestIncomplete(); } /** * @covers FireflyIII\Http\Controllers\AccountController::update - * @todo Implement testUpdate(). */ public function testUpdate() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->session(['accounts.edit.url' => 'http://localhost']); + $args = [ + 'id' => 1, + 'name' => 'TestData new name', + 'active' => 1, + '_token' => Session ::token(), + ]; + $this->be($this->user()); + + $response = $this->call('POST', '/accounts/update/1', $args); + $this->assertEquals(302, $response->status()); + $this->assertSessionHas('success'); + } } diff --git a/tests/acceptance/Controllers/Chart/ChartPiggyBankControllerTest.php b/tests/acceptance/Controllers/Chart/ChartPiggyBankControllerTest.php index b514cf48bf..a7f0e7e6fd 100644 --- a/tests/acceptance/Controllers/Chart/ChartPiggyBankControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartPiggyBankControllerTest.php @@ -15,13 +15,11 @@ class ChartPiggyBankControllerTest extends TestCase /** * @covers FireflyIII\Http\Controllers\Chart\PiggyBankController::history - * @todo Implement testHistory(). */ public function testHistory() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $this->be($this->user()); + $response = $this->call('GET', '/chart/piggy-bank/1'); + $this->assertEquals(200, $response->status()); } } diff --git a/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php b/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php index 8f8c932089..ac922dd8ed 100644 --- a/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartReportControllerTest.php @@ -14,25 +14,23 @@ class ChartReportControllerTest extends TestCase { /** * @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOut - * @todo Implement testYearInOut(). */ public function testYearInOut() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); +// $this->be($this->user()); +// $response = $this->call('GET', '/chart/report/in-out/default/20150101/20151231/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } /** * @covers FireflyIII\Http\Controllers\Chart\ReportController::yearInOutSummarized - * @todo Implement testYearInOutSummarized(). */ public function testYearInOutSummarized() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); +// $this->be($this->user()); +// $response = $this->call('GET', '/chart/report/in-out-sum/default/20150101/20151231/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } }