From 2faf84780fd13c3694fdfa52b914a2a978c44eda Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 20 Jan 2016 09:15:33 +0100 Subject: [PATCH] Implemented some tests. --- database/seeds/TestDataSeeder.php | 89 +++++++++++++ .../Controllers/Auth/AuthControllerTest.php | 50 ++------ .../Auth/PasswordControllerTest.php | 119 +----------------- .../Chart/ChartAccountControllerTest.php | 36 +++--- .../Chart/ChartBillControllerTest.php | 18 ++- .../Chart/ChartBudgetControllerTest.php | 47 ++++--- .../Chart/ChartCategoryControllerTest.php | 63 +++++----- 7 files changed, 176 insertions(+), 246 deletions(-) diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index 67e4ad7d2d..f07a8a3a66 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -1,7 +1,12 @@ createAssetAccounts($user); + + // create a bills for user #1 + $this->createBills($user); + + // create some budgets for user #1 + $this->createBudgets($user); + + // create some categories for user #1 + $this->createCategories($user); } /** @@ -58,4 +72,79 @@ class TestDataSeeder extends Seeder } } + + /** + * @param User $user + */ + private function createBills(User $user) + { + Bill::create( + [ + 'name' => 'Rent', + 'match' => 'rent,land,lord', + 'amount_min' => 795, + 'amount_max' => 805, + 'user_id' => $user->id, + 'date' => '2015-01-01', + 'active' => 1, + 'automatch' => 1, + 'repeat_freq' => 'monthly', + 'skip' => 0, + ] + ); + Bill::create( + [ + 'name' => 'Health insurance', + 'match' => 'zilveren,kruis,health', + 'amount_min' => 120, + 'amount_max' => 140, + 'user_id' => $user->id, + 'date' => '2015-01-01', + 'active' => 1, + 'automatch' => 1, + 'repeat_freq' => 'monthly', + 'skip' => 0, + ] + ); + } + + /** + * @param $user + */ + private function createBudgets($user) + { + $set = [ + Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]), + Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]), + ]; + $current = new Carbon; + /** @var Budget $budget */ + foreach ($set as $budget) { + + // some budget limits: + $start = clone $current; + $end = clone $current; + $start->startOfMonth(); + $end->endOfMonth(); + + BudgetLimit::create( + [ + 'budget_id' => $budget->id, + 'startdate' => $start->format('Y-m-d'), + 'amount' => 500, + 'repeats' => 0, + 'repeat_freq' => 'monthly', + ] + ); + } + } + + /** + * @param User $user + */ + private function createCategories(User $user) + { + Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]); + Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); + } } diff --git a/tests/acceptance/Controllers/Auth/AuthControllerTest.php b/tests/acceptance/Controllers/Auth/AuthControllerTest.php index 2f96a5770a..29d957f17d 100644 --- a/tests/acceptance/Controllers/Auth/AuthControllerTest.php +++ b/tests/acceptance/Controllers/Auth/AuthControllerTest.php @@ -47,7 +47,6 @@ class AuthControllerTest extends TestCase public function testLogin() { $response = $this->call('GET', '/login'); - $this->assertSessionHas('isLoggedIn', 'yes'); $this->assertEquals(200, $response->status()); } @@ -79,7 +78,11 @@ class AuthControllerTest extends TestCase ]; $response = $this->call('POST', '/login', $args); $this->assertEquals(302, $response->status()); - $this->assertSessionHas('isLoggedIn', 'yes'); + + $response = $this->call('GET', '/'); + $this->assertEquals(200, $response->status()); + + } @@ -98,51 +101,12 @@ class AuthControllerTest extends TestCase $this->assertSessionHas('start'); } - /** - * @covers FireflyIII\Http\Controllers\Auth\AuthController::redirectPath - * @todo Implement testRedirectPath(). - */ - public function testRedirectPath() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers FireflyIII\Http\Controllers\Auth\AuthController::register - * @todo Implement testRegister(). */ public function testRegister() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\AuthController::showLoginForm - * @todo Implement testShowLoginForm(). - */ - public function testShowLoginForm() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\AuthController::showRegistrationForm - * @todo Implement testShowRegistrationForm(). - */ - public function testShowRegistrationForm() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $response = $this->call('GET', '/register'); + $this->assertEquals(200, $response->status()); } } diff --git a/tests/acceptance/Controllers/Auth/PasswordControllerTest.php b/tests/acceptance/Controllers/Auth/PasswordControllerTest.php index 3f942b689d..96655ba14c 100644 --- a/tests/acceptance/Controllers/Auth/PasswordControllerTest.php +++ b/tests/acceptance/Controllers/Auth/PasswordControllerTest.php @@ -12,124 +12,17 @@ */ class PasswordControllerTest extends TestCase { - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::getBroker - * @todo Implement testGetBroker(). - */ - public function testGetBroker() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::getEmail - * @todo Implement testGetEmail(). - */ - public function testGetEmail() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::getReset - * @todo Implement testGetReset(). - */ - public function testGetReset() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::postEmail - * @todo Implement testPostEmail(). - */ - public function testPostEmail() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::postReset - * @todo Implement testPostReset(). - */ - public function testPostReset() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::redirectPath - * @todo Implement testRedirectPath(). - */ - public function testRedirectPath() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::reset - * @todo Implement testReset(). - */ - public function testReset() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - /** * @covers FireflyIII\Http\Controllers\Auth\PasswordController::sendResetLinkEmail - * @todo Implement testSendResetLinkEmail(). */ public function testSendResetLinkEmail() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $args = [ + 'email' => 'thegrumpydictator@gmail.com', + '_token' => Session::token(), + ]; + $response = $this->call('POST', '/password/email', $args); + $this->assertEquals(302, $response->status()); } - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::showLinkRequestForm - * @todo Implement testShowLinkRequestForm(). - */ - public function testShowLinkRequestForm() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @covers FireflyIII\Http\Controllers\Auth\PasswordController::showResetForm - * @todo Implement testShowResetForm(). - */ - public function testShowResetForm() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } } diff --git a/tests/acceptance/Controllers/Chart/ChartAccountControllerTest.php b/tests/acceptance/Controllers/Chart/ChartAccountControllerTest.php index 2aebba6630..29dd51e769 100644 --- a/tests/acceptance/Controllers/Chart/ChartAccountControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartAccountControllerTest.php @@ -14,49 +14,45 @@ class ChartAccountControllerTest extends TestCase { /** * @covers FireflyIII\Http\Controllers\Chart\AccountController::expenseAccounts - * @todo Implement testExpenseAccounts(). */ public function testExpenseAccounts() { - // 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/account/expense'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\AccountController::frontpage - * @todo Implement testFrontpage(). */ public function testFrontpage() { - // 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/account/frontpage'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\AccountController::report - * @todo Implement testReport(). */ public function testReport() { - // 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/account/report/default/20160101/20160131/1'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\AccountController::single - * @todo Implement testSingle(). */ public function testSingle() { - // 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/account/1'); + + $this->assertEquals(200, $response->status()); } } diff --git a/tests/acceptance/Controllers/Chart/ChartBillControllerTest.php b/tests/acceptance/Controllers/Chart/ChartBillControllerTest.php index 15d7f4bcb4..e35e5a2d54 100644 --- a/tests/acceptance/Controllers/Chart/ChartBillControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartBillControllerTest.php @@ -15,25 +15,23 @@ class ChartBillControllerTest extends TestCase /** * @covers FireflyIII\Http\Controllers\Chart\BillController::frontpage - * @todo Implement testFrontpage(). */ public function testFrontpage() { - // 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/bill/frontpage'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\BillController::single - * @todo Implement testSingle(). */ public function testSingle() { - // 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/bill/1'); + + $this->assertEquals(200, $response->status()); } } diff --git a/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php b/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php index 887112e330..2968da7905 100644 --- a/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php @@ -15,61 +15,58 @@ class ChartBudgetControllerTest extends TestCase /** * @covers FireflyIII\Http\Controllers\Chart\BudgetController::budget - * @todo Implement testBudget(). */ public function testBudget() { - // 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/budget/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } /** * @covers FireflyIII\Http\Controllers\Chart\BudgetController::budgetLimit - * @todo Implement testBudgetLimit(). */ public function testBudgetLimit() { - // 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/budget/1/1'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\BudgetController::frontpage - * @todo Implement testFrontpage(). */ public function testFrontpage() { - // 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/budget/frontpage'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\BudgetController::multiYear - * @todo Implement testMultiYear(). */ public function testMultiYear() { - // 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/budget/multi-year/default/20150101/20160101/1/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); + } /** * @covers FireflyIII\Http\Controllers\Chart\BudgetController::year - * @todo Implement testYear(). */ public function testYear() { - // 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/budget/year/default/20150101/201512031/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); + } } diff --git a/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php b/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php index 6d16e67578..470ff0c240 100644 --- a/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php +++ b/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php @@ -15,85 +15,78 @@ class ChartCategoryControllerTest extends TestCase /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::all - * @todo Implement testAll(). */ public function testAll() { - // 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/category/1/all'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::currentPeriod - * @todo Implement testCurrentPeriod(). */ public function testCurrentPeriod() { - // 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/category/1/period'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::earnedInPeriod - * @todo Implement testEarnedInPeriod(). */ public function testEarnedInPeriod() { - // 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/category/earned-in-period/default/20150101/20151231/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::frontpage - * @todo Implement testFrontpage(). */ public function testFrontpage() { - // 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/category/frontpage'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::multiYear - * @todo Implement testMultiYear(). */ public function testMultiYear() { - // 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/category/multi-year/default/20150101/20151231/1/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::specificPeriod - * @todo Implement testSpecificPeriod(). */ public function testSpecificPeriod() { - // 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/category/1/period/20150101'); + + $this->assertEquals(200, $response->status()); } /** * @covers FireflyIII\Http\Controllers\Chart\CategoryController::spentInPeriod - * @todo Implement testSpentInPeriod(). */ public function testSpentInPeriod() { - // 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/category/spent-in-period/default/20150101/20151231/1'); +// $this->assertEquals(200, $response->status()); + $this->markTestSkipped('Skipped because sqlite does not support DATE_FORMAT.'); } }