From 60fc99d23f99a9c1aa9b44adc11a9ad192347bcb Mon Sep 17 00:00:00 2001 From: Ernest Walzel Date: Fri, 18 Aug 2023 14:25:17 +0200 Subject: [PATCH] RedirectLegacyCatalogRequestTest --- .../Unit/RedirectLegacyCatalogRequestTest.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/Unit/RedirectLegacyCatalogRequestTest.php diff --git a/tests/Unit/RedirectLegacyCatalogRequestTest.php b/tests/Unit/RedirectLegacyCatalogRequestTest.php new file mode 100644 index 000000000..39f8b6c85 --- /dev/null +++ b/tests/Unit/RedirectLegacyCatalogRequestTest.php @@ -0,0 +1,77 @@ + 'Vodrážka, Jaroslav', + 'work_type' => 'maliarstvo', + 'object_type' => 'závesný obraz', + 'tag' => 'architektúra', + 'topic' => 'architektonický motív', + 'technique' => 'olej', + 'medium' => 'drevo', + 'gallery' => 'Slovenská národná galéria, SNG', + 'has_image' => '1', + 'has_iip' => '1', + 'is_free' => '1', + 'has_text' => '1', + 'years_range' => '1533,1912', + 'color' => '38E619', + 'sort_by' => 'created_at', + ]); + $request = Request::create("/katalog?$legacyQuery"); + + $response = $middleware->handle($request, function () {}); + + $expectedQuery = http_build_query([ + 'filter' => [ + 'author' => ['Vodrážka, Jaroslav'], + 'work_type' => ['maliarstvo'], + 'object_type' => ['závesný obraz'], + 'tag' => ['architektúra'], + 'topic' => ['architektonický motív'], + 'technique' => ['olej'], + 'medium' => ['drevo'], + 'gallery' => ['Slovenská národná galéria, SNG'], + 'has_image' => 'true', + 'has_iip' => 'true', + 'is_free' => 'true', + 'has_text' => 'true', + 'late_latest' => ['gte' => '1533'], + 'date_earliest' => ['lte' => '1912'], + 'color' => '38E619', + 'sort' => ['created_at' => 'asc'], + ], + ]); + + $this->assertEquals($response->getStatusCode(), 302); + $this->assertEquals( + $response->headers->get('location'), + $request->url() . '?' . $expectedQuery + ); + } + + public function test_ignores_new_request_format(): void + { + $middleware = new RedirectLegacyCatalogRequest(); + $query = http_build_query([ + 'filter' => ['topic' => ['summer']], + ]); + $request = Request::create("/katalog?$query"); + + $response = $middleware->handle($request, fn() => new Response()); + + $this->assertEquals($response->getStatusCode(), 200); + } +}