mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Updated code coverage, improved binder code.
This commit is contained in:
parent
5cb948d0f3
commit
a3ec741d67
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -31,52 +32,41 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
*/
|
*/
|
||||||
class AccountList implements BinderInterface
|
class AccountList implements BinderInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Collection
|
public static function routeBinder(string $value, Route $route): Collection
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$ids = explode(',', $value);
|
$list = [];
|
||||||
// filter ids:
|
$incoming = explode(',', $value);
|
||||||
$ids = self::filterIds($ids);
|
foreach ($incoming as $entry) {
|
||||||
|
$list[] = intval($entry);
|
||||||
|
}
|
||||||
|
$list = array_unique($list);
|
||||||
|
if (count($list) === 0) {
|
||||||
|
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
/** @var \Illuminate\Support\Collection $object */
|
/** @var \Illuminate\Support\Collection $collection */
|
||||||
$object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
$collection = auth()->user()->accounts()
|
||||||
->whereIn('accounts.id', $ids)
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->where('user_id', auth()->user()->id)
|
->whereIn('accounts.id', $list)
|
||||||
->get(['accounts.*']);
|
->get(['accounts.*']);
|
||||||
if ($object->count() > 0) {
|
if ($collection->count() > 0) {
|
||||||
$object = $object->sortBy(
|
$collection = $collection->sortBy(
|
||||||
function (Account $account) {
|
function (Account $account) {
|
||||||
return $account->name;
|
return $account->name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return $object;
|
return $collection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new NotFoundHttpException;
|
throw new NotFoundHttpException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $ids
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected static function filterIds(array $ids): array
|
|
||||||
{
|
|
||||||
$new = [];
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
if (intval($id) > 0) {
|
|
||||||
$new[] = $id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$new = array_unique($new);
|
|
||||||
|
|
||||||
return $new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,16 +22,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface BinderInterface.
|
* Interface BinderInterface.
|
||||||
*/
|
*/
|
||||||
interface BinderInterface
|
interface BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route);
|
public static function routeBinder(string $value, Route $route);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class BudgetList implements BinderInterface
|
class BudgetList implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Collection
|
public static function routeBinder(string $value, Route $route): Collection
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$ids = explode(',', $value);
|
$ids = explode(',', $value);
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class CategoryList implements BinderInterface
|
class CategoryList implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Collection
|
public static function routeBinder(string $value, Route $route): Collection
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$ids = explode(',', $value);
|
$ids = explode(',', $value);
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,15 +32,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class CurrencyCode implements BinderInterface
|
class CurrencyCode implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return TransactionCurrency
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route)
|
public static function routeBinder(string $value, Route $route): TransactionCurrency
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$currency = TransactionCurrency::where('code', $value)->first();
|
$currency = TransactionCurrency::where('code', trim($value))->first();
|
||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Binder;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use FireflyIII\Helpers\FiscalHelper;
|
use FireflyIII\Helpers\FiscalHelper;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Log;
|
use Log;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -34,12 +35,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class Date implements BinderInterface
|
class Date implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Carbon
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Carbon
|
public static function routeBinder(string $value, Route $route): Carbon
|
||||||
{
|
{
|
||||||
$fiscalHelper = new FiscalHelper;
|
$fiscalHelper = new FiscalHelper;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -32,12 +33,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class JournalList implements BinderInterface
|
class JournalList implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Collection
|
public static function routeBinder(string $value, Route $route): Collection
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$ids = explode(',', $value);
|
$ids = explode(',', $value);
|
||||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Support\Binder;
|
|||||||
|
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@ -33,12 +34,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class TagList implements BinderInterface
|
class TagList implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): Collection
|
public static function routeBinder(string $value, Route $route): Collection
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$tags = explode(',', $value);
|
$tags = explode(',', $value);
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use Illuminate\Routing\Route;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,20 +32,20 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|||||||
class UnfinishedJournal implements BinderInterface
|
class UnfinishedJournal implements BinderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @param $route
|
* @param Route $route
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return TransactionJournal
|
||||||
*/
|
*/
|
||||||
public static function routeBinder($value, $route): TransactionJournal
|
public static function routeBinder(string $value, Route $route): TransactionJournal
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$object = TransactionJournal::where('transaction_journals.id', $value)
|
$journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $value)
|
||||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||||
->where('completed', 0)
|
->where('completed', 0)
|
||||||
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
|
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
|
||||||
if ($object) {
|
if (!is_null($journal)) {
|
||||||
return $object;
|
return $journal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class Amount.
|
* Class Amount.
|
||||||
*/
|
*/
|
||||||
class Amount extends Facade
|
class Amount extends Facade
|
||||||
|
@ -25,7 +25,8 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Amount.
|
* @codeCoverageIgnore
|
||||||
|
* Class ExpandedForm.
|
||||||
*/
|
*/
|
||||||
class ExpandedForm extends Facade
|
class ExpandedForm extends Facade
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class FireflyConfig.
|
* Class FireflyConfig.
|
||||||
*/
|
*/
|
||||||
class FireflyConfig extends Facade
|
class FireflyConfig extends Facade
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class Navigation.
|
* Class Navigation.
|
||||||
*/
|
*/
|
||||||
class Navigation extends Facade
|
class Navigation extends Facade
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class Preferences.
|
* Class Preferences.
|
||||||
*/
|
*/
|
||||||
class Preferences extends Facade
|
class Preferences extends Facade
|
||||||
|
@ -25,6 +25,7 @@ namespace FireflyIII\Support\Facades;
|
|||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @codeCoverageIgnore
|
||||||
* Class Steam.
|
* Class Steam.
|
||||||
*/
|
*/
|
||||||
class Steam extends Facade
|
class Steam extends Facade
|
||||||
|
@ -25,6 +25,7 @@ namespace Tests\Unit\Helpers;
|
|||||||
|
|
||||||
|
|
||||||
use FireflyIII\Http\Middleware\Binder;
|
use FireflyIII\Http\Middleware\Binder;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Route;
|
use Route;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -55,6 +56,80 @@ class BinderTest extends TestCase
|
|||||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
$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::handle
|
||||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||||
@ -92,7 +167,6 @@ class BinderTest extends TestCase
|
|||||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
* @covers \FireflyIII\Http\Middleware\Binder::handle
|
||||||
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
* @covers \FireflyIII\Http\Middleware\Binder::__construct
|
||||||
@ -1063,5 +1137,60 @@ class BinderTest extends TestCase
|
|||||||
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user