Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some new tests.
James Colebcf7452312b0
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpindex 9b9d0235e7..14476ea8e3 100644--- a/app/Http/Controllers/HomeController.php+++ b/app/Http/Controllers/HomeController.php@@ -38,16 +38,6 @@ class HomeController extends ControllerSession::put('end', $end);}- /**- * @return \Illuminate\Http\RedirectResponse- */- public function flush()- {- Cache::flush();-- return Redirect::route('index');- }-/*** @return \Illuminate\View\View*/diff --git a/app/Http/Kernel.php b/app/Http/Kernel.phpindex 1fc059e294..88d5bd657e 100644--- a/app/Http/Kernel.php+++ b/app/Http/Kernel.php@@ -22,6 +22,7 @@ class Kernel extends HttpKernel'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse','Illuminate\Session\Middleware\StartSession','Illuminate\View\Middleware\ShareErrorsFromSession',+ 'FireflyIII\Http\Middleware\ReplaceTestVars','FireflyIII\Http\Middleware\VerifyCsrfToken',];@@ -38,6 +39,7 @@ class Kernel extends HttpKernel'range' => 'FireflyIII\Http\Middleware\Range','reminders' => 'FireflyIII\Http\Middleware\Reminders','piggybanks' => 'FireflyIII\Http\Middleware\PiggyBanks',+];}diff --git a/app/Http/Middleware/ReplaceTestVars.php b/app/Http/Middleware/ReplaceTestVars.phpnew file mode 100644index 0000000000..10daf84d09--- /dev/null+++ b/app/Http/Middleware/ReplaceTestVars.php@@ -0,0 +1,54 @@+<?php++namespace FireflyIII\Http\Middleware;++use Closure;+use Illuminate\Contracts\Foundation\Application;+use Illuminate\Contracts\Routing\Middleware;++/**+ * Class ReplaceTestVars+ *+ * @package App\Http\Middleware+ */+class ReplaceTestVars implements Middleware+{+ /**+ * The application implementation.+ *+ * @var Application+ */+ protected $app;++ /**+ * Create a new filter instance.+ *+ * @param Application $app+ *+ */+ public function __construct(Application $app)+ {+ $this->app = $app;+ }++ /**+ * Handle an incoming request.+ *+ * @param \Illuminate\Http\Request $request+ * @param \Closure $next+ *+ * @return mixed+ */+ public function handle($request, Closure $next)+ {+ if ('testing' === $this->app->environment() && $request->has('_token')) {+ $input = $request->all();+ $input['_token'] = $request->session()->token();+ // we need to update _token value to make sure we get the POST / PUT tests passed.+ $request->replace($input);+ }++ return $next($request);+ }++}\ No newline at end of filediff --git a/tests/controllers/HomeControllerTest.php b/tests/controllers/HomeControllerTest.phpindex cb03ff6fbd..05bd3c7550 100644--- a/tests/controllers/HomeControllerTest.php+++ b/tests/controllers/HomeControllerTest.php@@ -29,39 +29,56 @@ class HomeControllerTest extends TestCase/*** @covers FireflyIII\Http\Controllers\HomeController::dateRange*/- public function testDateRange()+ public function testDateRangeWarning(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete('This test has not been implemented yet.');+ $start = '2014-03-01';+ $end = '2015-03-31';++ $this->be(new FireflyIII\User);+ $this->call('POST', '/daterange', ['end' => $end, 'start' => $start]);+ $this->assertResponseOk();++ $this->assertSessionHas('start');+ $this->assertSessionHas('end');+ $this->assertSessionHas('warning');+}/**- * @covers FireflyIII\Http\Controllers\HomeController::flush+ * @covers FireflyIII\Http\Controllers\HomeController::dateRange*/- public function testFlush()+ public function testDateRange(){- // Remove the following lines when you implement this test.- $this->markTestIncomplete('This test has not been implemented yet.');+ $start = '2015-03-01';+ $end = '2015-03-31';++ $this->be(new FireflyIII\User);+ $this->call('POST', '/daterange', ['end' => $end, 'start' => $start]);+ $this->assertResponseOk();++ $this->assertSessionHas('start');+ $this->assertSessionHas('end');+}/*** @covers FireflyIII\Http\Controllers\HomeController::index*/- public function testIndexNoLogin()+ public function testIndexLoggedIn(){+ $this->be(new FireflyIII\User);$response = $this->call('GET', '/');- $this->assertRedirectedTo('auth/login');+ $this->assertResponseOk();}/*** @covers FireflyIII\Http\Controllers\HomeController::index*/- public function testIndexLoggedIn()+ public function testIndexNoLogin(){- $this->be(new FireflyIII\User);$response = $this->call('GET', '/');- $this->assertResponseOk();+ $this->assertRedirectedTo('auth/login');}