firefly-iii/tests/Unit/Middleware/BinderTest.php

1402 lines
43 KiB
PHP
Raw Normal View History

<?php
/**
* BinderTest.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
2017-12-25 08:30:50 -06:00
namespace Tests\Unit\Middleware;
2017-12-25 08:30:50 -06:00
use Carbon\Carbon;
use FireflyIII\Helpers\FiscalHelperInterface;
2018-02-10 02:22:04 -06:00
use FireflyIII\Http\Middleware\Binder;
2017-12-25 08:30:50 -06:00
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
/**
* Class BinderTest
* Per object: works, not existing, not logged in + existing
*/
2018-02-10 02:22:04 -06:00
class BinderTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Account::routeBinder
*/
public function testAccount(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{account}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
*/
public function testAccountList(): void
{
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
*/
public function testAccountListEmpty(): void
{
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
*/
public function testAccountListInvalid(): void
{
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Support\Binder\AccountList::routeBinder
*/
public function testAccountListNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Models\Account::routeBinder
*/
public function testAccountNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{account}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Account::routeBinder
*/
public function testAccountNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{account}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Attachment::routeBinder
*/
public function testAttachment(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{attachment}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Attachment::routeBinder
*/
public function testAttachmentNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{attachment}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Attachment::routeBinder
*/
public function testAttachmentNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{attachment}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Bill::routeBinder
*/
public function testBill(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{bill}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Bill::routeBinder
*/
public function testBillNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{bill}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Bill::routeBinder
*/
public function testBillNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{bill}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Budget::routeBinder
*/
public function testBudget(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{budget}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\BudgetLimit::routeBinder
*/
public function testBudgetLimit(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{budgetLimit}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\BudgetLimit::routeBinder
*/
public function testBudgetLimitNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{budgetLimit}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\BudgetLimit::routeBinder
*/
public function testBudgetLimitNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{budgetLimit}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
2017-12-25 08:30:50 -06:00
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\BudgetList::routeBinder
*/
public function testBudgetList(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{budgetList}', function (Collection $budgets) {
return 'count: ' . $budgets->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0,1,2');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('count: 3');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\BudgetList::routeBinder
*/
public function testBudgetListInvalid(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{budgetList}', function (Collection $budgets) {
return 'count: ' . $budgets->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Budget::routeBinder
*/
public function testBudgetNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{budget}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Budget::routeBinder
*/
public function testBudgetNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{budget}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Category::routeBinder
*/
public function testCategory(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{category}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
2017-12-25 08:30:50 -06:00
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\CategoryList::routeBinder
*/
public function testCategoryList(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{categoryList}', function (Collection $categories) {
return 'count: ' . $categories->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0,1,2');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('count: 3');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\CategoryList::routeBinder
*/
public function testCategoryListInvalid(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{categoryList}', function (Collection $categories) {
return 'count: ' . $categories->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Category::routeBinder
*/
public function testCategoryNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{category}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Category::routeBinder
*/
public function testCategoryNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{category}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
2017-12-25 02:00:09 -06:00
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 02:00:09 -06:00
* @covers \FireflyIII\Support\Binder\CurrencyCode::routeBinder
*/
public function testCurrencyCode(): void
2017-12-25 02:00:09 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 02:00:09 -06:00
'/_test/binder/{fromCurrencyCode}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/USD');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 02:00:09 -06:00
* @covers \FireflyIII\Support\Binder\CurrencyCode::routeBinder
*/
public function testCurrencyCodeNotFound(): void
2017-12-25 02:00:09 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 02:00:09 -06:00
'/_test/binder/{fromCurrencyCode}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/ABC');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 02:00:09 -06:00
* @covers \FireflyIII\Support\Binder\CurrencyCode::routeBinder
*/
public function testCurrencyCodeNotLoggedIn(): void
2017-12-25 02:00:09 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 02:00:09 -06:00
'/_test/binder/{fromCurrencyCode}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/EUR');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
2017-12-25 08:30:50 -06:00
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDate(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
// mock fiscal helper:
2018-08-06 12:14:30 -05:00
$date = new Carbon;
2018-07-28 05:10:25 -05:00
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/20170917');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: 2017-09-17');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateCurrentMonthEnd(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
$date = new Carbon;
$date->endOfMonth();
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/currentMonthEnd');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateCurrentMonthStart(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
$date = new Carbon;
$date->startOfMonth();
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/currentMonthStart');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateCurrentYearEnd(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
$date = new Carbon;
$date->endOfYear();
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/currentYearEnd');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateCurrentYearStart(): void
2017-12-25 08:30:50 -06:00
{
2018-07-28 05:10:25 -05:00
$date = new Carbon;
$date->startOfYear();
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/currentYearStart');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateFiscalYearEnd(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
$date = new Carbon;
$date->endOfYear();
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
2018-07-28 05:10:25 -05:00
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/currentFiscalYearEnd');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateFiscalYearStart(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
$date = new Carbon;
$date->startOfYear();
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
2018-07-28 05:10:25 -05:00
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
$this->be($this->user());
$response = $this->get('/_test/binder/currentFiscalYearStart');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('date: ' . $date->format('Y-m-d'));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\Date::routeBinder
*/
public function testDateInvalid(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{date}', function (Carbon $date) {
return 'date: ' . $date->format('Y-m-d');
}
);
2018-07-28 05:10:25 -05:00
$date = new Carbon;
// mock fiscal helper:
$helper = $this->mock(FiscalHelperInterface::class);
$helper->shouldReceive('endOfFiscalYear')->andReturn($date)->once();
$helper->shouldReceive('startOfFiscalYear')->andReturn($date)->once();
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/fakedate');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob::routeBinder
*/
public function testExportJob(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/testExport');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob::routeBinder
*/
public function testExportJobNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob::routeBinder
*/
public function testExportJobNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/testExport');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ImportJob::routeBinder
*/
public function testImportJob(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{importJob}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/testImport');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ImportJob::routeBinder
*/
public function testImportJobNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{importJob}', function () {
return 'OK';
}
);
2017-12-25 02:00:09 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ImportJob::routeBinder
*/
public function testImportJobNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{importJob}', function () {
return 'OK';
}
);
2017-12-25 02:00:09 -06:00
$response = $this->get('/_test/binder/testImport');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
2017-12-25 08:30:50 -06:00
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\JournalList::routeBinder
*/
public function testJournalList(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{journalList}', function (Collection $journals) {
return 'count: ' . $journals->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
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\JournalList::routeBinder
*/
public function testJournalListEmpty(): void
2017-12-25 08:30:50 -06:00
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{journalList}', function (Collection $journals) {
return 'count: ' . $journals->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\LinkType::routeBinder
*/
public function testLinkType(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\LinkType::routeBinder
*/
public function testLinkTypeNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\LinkType::routeBinder
*/
public function testLinkTypeNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{linkType}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\PiggyBank::routeBinder
*/
public function testPiggyBank(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\PiggyBank::routeBinder
*/
public function testPiggyBankNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\PiggyBank::routeBinder
*/
public function testPiggyBankNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{piggyBank}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Rule::routeBinder
*/
public function testRule(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{rule}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\RuleGroup::routeBinder
*/
public function testRuleGroup(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{ruleGroup}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\RuleGroup::routeBinder
*/
public function testRuleGroupNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{ruleGroup}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\RuleGroup::routeBinder
*/
public function testRuleGroupNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{ruleGroup}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Rule::routeBinder
*/
public function testRuleNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{rule}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Rule::routeBinder
*/
public function testRuleNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{rule}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournal::routeBinder
*/
public function testTJ(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournal::routeBinder
*/
public function testTJNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournal::routeBinder
*/
public function testTJNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Tag::routeBinder
*/
public function testTag(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tag}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\TagList::routeBinder
*/
public function testTagList(): void
2017-12-25 08:30:50 -06:00
{
2018-02-28 13:18:47 -06:00
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos->shouldReceive('setUser');
$tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
2018-02-28 13:18:47 -06:00
$tagRepos->shouldReceive('get')->once()->andReturn($tags);
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{tagList}', function (Collection $tags) {
return 'count: ' . $tags->count();
}
);
2018-02-28 13:18:47 -06:00
2018-04-02 07:17:11 -05:00
$names = implode(',', $tags->pluck('tag')->toArray());
2017-12-25 08:30:50 -06:00
2018-02-28 13:18:47 -06:00
2017-12-25 08:30:50 -06:00
$this->be($this->user());
$response = $this->get('/_test/binder/' . $names);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('count: 2');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
2017-12-25 08:30:50 -06:00
* @covers \FireflyIII\Support\Binder\TagList::routeBinder
*/
public function testTagListEmpty(): void
2017-12-25 08:30:50 -06:00
{
2018-02-28 13:18:47 -06:00
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->once()->andReturn(new Collection());
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2017-12-25 08:30:50 -06:00
'/_test/binder/{tagList}', function (Collection $tags) {
return 'count: ' . $tags->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/noblaexista');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Tag::routeBinder
*/
public function testTagNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tag}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Tag::routeBinder
*/
public function testTagNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{tag}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionCurrency::routeBinder
*/
public function testTransactionCurrency(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{currency}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionCurrency::routeBinder
*/
public function testTransactionCurrencyNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{currency}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionCurrency::routeBinder
*/
public function testTransactionCurrencyNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{currency}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournalLink::routeBinder
*/
public function testTransactionJournalLink(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournalLink::routeBinder
*/
public function testTransactionJournalLinkNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionJournalLink::routeBinder
*/
public function testTransactionJournalLinkNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionType::routeBinder
*/
public function testTransactionType(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{transactionType}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/withdrawal');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionType::routeBinder
*/
public function testTransactionTypeNotFound(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{transactionType}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/unknown');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionType::routeBinder
*/
public function testTransactionTypeNotLoggedIn(): void
{
2018-02-10 02:22:04 -06:00
Route::middleware(Binder::class)->any(
2018-01-10 13:07:47 -06:00
'/_test/binder/{transactionType}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/withdrawal');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
*/
public function testUnfinishedJournal(): void
{
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
*/
public function testUnfinishedJournalFinished(): void
{
$journal = $this->user()->transactionJournals()->where('completed', 1)->first();
2018-02-10 02:22:04 -06:00
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
* @covers \FireflyIII\Support\Binder\UnfinishedJournal::routeBinder
*/
public function testUnfinishedJournalNotLoggedIn(): void
{
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
2018-02-10 02:22:04 -06:00
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());
}
2018-03-04 08:14:29 -06:00
}