Some new tests.

This commit is contained in:
James Cole 2015-03-28 06:19:09 +01:00
parent b9000519e4
commit bcf7452312
4 changed files with 91 additions and 28 deletions

View File

@ -38,16 +38,6 @@ class HomeController extends Controller
Session::put('end', $end);
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush()
{
Cache::flush();
return Redirect::route('index');
}
/**
* @return \Illuminate\View\View
*/

View File

@ -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',
];
}

View File

@ -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);
}
}

View File

@ -26,31 +26,38 @@ class HomeControllerTest extends TestCase
parent::tearDown();
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::dateRange
*/
public function testDateRangeWarning()
{
$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::dateRange
*/
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';
/**
* @covers FireflyIII\Http\Controllers\HomeController::flush
*/
public function testFlush()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
$this->be(new FireflyIII\User);
$this->call('POST', '/daterange', ['end' => $end, 'start' => $start]);
$this->assertResponseOk();
/**
* @covers FireflyIII\Http\Controllers\HomeController::index
*/
public function testIndexNoLogin()
{
$response = $this->call('GET', '/');
$this->assertRedirectedTo('auth/login');
$this->assertSessionHas('start');
$this->assertSessionHas('end');
}
@ -65,4 +72,14 @@ class HomeControllerTest extends TestCase
}
/**
* @covers FireflyIII\Http\Controllers\HomeController::index
*/
public function testIndexNoLogin()
{
$response = $this->call('GET', '/');
$this->assertRedirectedTo('auth/login');
}
}