Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Currency code test.
James Cole5cb948d0f3fc
diff --git a/app/Support/Binder/CurrencyCode.php b/app/Support/Binder/CurrencyCode.phpindex 0245fa4405..a8887c6466 100644--- a/app/Support/Binder/CurrencyCode.php+++ b/app/Support/Binder/CurrencyCode.php@@ -38,9 +38,11 @@ class CurrencyCode implements BinderInterface*/public static function routeBinder($value, $route){- $currency = TransactionCurrency::where('code', $value)->first();- if (null !== $currency) {- return $currency;+ if (auth()->check()) {+ $currency = TransactionCurrency::where('code', $value)->first();+ if (null !== $currency) {+ return $currency;+ }}throw new NotFoundHttpException;}diff --git a/tests/Unit/Middleware/BinderTest.php b/tests/Unit/Middleware/BinderTest.phpindex b92460dcf2..d9a394c28a 100644--- a/tests/Unit/Middleware/BinderTest.php+++ b/tests/Unit/Middleware/BinderTest.php@@ -373,6 +373,62 @@ 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\CurrencyCode::routeBinder+ */+ public function testCurrencyCode()+ {+ Route::middleware(Binder::class)->any(+ '/_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::handle+ * @covers \FireflyIII\Http\Middleware\Binder::__construct+ * @covers \FireflyIII\Http\Middleware\Binder::performBinding+ * @covers \FireflyIII\Support\Binder\CurrencyCode::routeBinder+ */+ public function testCurrencyCodeNotFound()+ {+ Route::middleware(Binder::class)->any(+ '/_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::handle+ * @covers \FireflyIII\Http\Middleware\Binder::__construct+ * @covers \FireflyIII\Http\Middleware\Binder::performBinding+ * @covers \FireflyIII\Support\Binder\CurrencyCode::routeBinder+ */+ public function testCurrencyCodeNotLoggedIn()+ {+ Route::middleware(Binder::class)->any(+ '/_test/binder/{fromCurrencyCode}', function () {+ return 'OK';+ }+ );++ $response = $this->get('/_test/binder/EUR');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }+/*** @covers \FireflyIII\Http\Middleware\Binder::handle* @covers \FireflyIII\Http\Middleware\Binder::__construct@@ -454,17 +510,16 @@ class BinderTest extends TestCase* @covers \FireflyIII\Http\Middleware\Binder::performBinding* @covers \FireflyIII\Models\ImportJob::routeBinder*/- public function testImportJobNotFound()+ public function testImportJobBadStatus(){Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {return 'OK';});-$this->be($this->user());- $response = $this->get('/_test/binder/0');- $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ $response = $this->get('/_test/binder/bad-status');+ $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());}/**@@ -473,7 +528,7 @@ class BinderTest extends TestCase* @covers \FireflyIII\Http\Middleware\Binder::performBinding* @covers \FireflyIII\Models\ImportJob::routeBinder*/- public function testImportJobNotLoggedIn()+ public function testImportJobNotFound(){Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {@@ -481,30 +536,28 @@ class BinderTest extends TestCase});- $response = $this->get('/_test/binder/testImport');+ $this->be($this->user());+ $response = $this->get('/_test/binder/0');$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\Models\ImportJob::routeBinder*/- public function testImportJobBadStatus()+ public function testImportJobNotLoggedIn(){Route::middleware(Binder::class)->any('/_test/binder/{importJob}', function () {return 'OK';});- $this->be($this->user());- $response = $this->get('/_test/binder/bad-status');- $this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());- }-+ $response = $this->get('/_test/binder/testImport');+ $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());+ }/*** @covers \FireflyIII\Http\Middleware\Binder::handle@@ -1010,7 +1063,5 @@ class BinderTest extends TestCase$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());}--}\ No newline at end of file