mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Updated code coverage, improved binder code.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace Tests\Unit\Helpers;
|
||||
|
||||
|
||||
use FireflyIII\Http\Middleware\Binder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
@@ -55,6 +56,80 @@ class BinderTest extends TestCase
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
|
||||
*/
|
||||
public function testAccountList()
|
||||
{
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{accountList}', function (Collection $accounts) {
|
||||
return 'count: ' . $accounts->count();
|
||||
}
|
||||
);
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/1,2');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('count: 2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
|
||||
*/
|
||||
public function testAccountListEmpty()
|
||||
{
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{accountList}', function (Collection $accounts) {
|
||||
return 'count: ' . $accounts->count();
|
||||
}
|
||||
);
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
|
||||
*/
|
||||
public function testAccountListInvalid()
|
||||
{
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{accountList}', function (Collection $accounts) {
|
||||
return 'count: ' . $accounts->count();
|
||||
}
|
||||
);
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/0,1,2');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('count: 2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
|
||||
*/
|
||||
public function testAccountListNotLoggedIn()
|
||||
{
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{accountList}', function (Collection $accounts) {
|
||||
return 'count: ' . $accounts->count();
|
||||
}
|
||||
);
|
||||
$response = $this->get('/_test/binder/1,2');
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
@@ -92,7 +167,6 @@ class BinderTest extends TestCase
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
@@ -1063,5 +1137,60 @@ class BinderTest extends TestCase
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
|
||||
*/
|
||||
public function testUnfinishedJournal()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{unfinishedJournal}', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/binder/' . $journal->id);
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
|
||||
*/
|
||||
public function testUnfinishedJournalFinished()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('completed', 1)->first();
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{unfinishedJournal}', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
$response = $this->get('/_test/binder/' . $journal->id);
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Binder::performBinding
|
||||
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
|
||||
*/
|
||||
public function testUnfinishedJournalNotLoggedIn()
|
||||
{
|
||||
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
|
||||
Route::middleware(Binder::class)->any(
|
||||
'/_test/binder/{unfinishedJournal}', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
$response = $this->get('/_test/binder/' . $journal->id);
|
||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user