From 7cb0c4cc5bfd8f919d3078e12f960252e23910cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=82=E6=B5=81?= Date: Thu, 13 Aug 2020 15:36:16 +0200 Subject: [PATCH 1/3] Fix Content-Type of SVG when handled by middleware --- src/Middleware/AssetCompressMiddleware.php | 1 + .../AssetCompressMiddlewareTest.php | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Middleware/AssetCompressMiddleware.php b/src/Middleware/AssetCompressMiddleware.php index 6bfa8008..8011ac7f 100644 --- a/src/Middleware/AssetCompressMiddleware.php +++ b/src/Middleware/AssetCompressMiddleware.php @@ -115,6 +115,7 @@ protected function mapType($build) $types = [ 'css' => 'text/css', 'js' => 'application/javascript', + 'svg' => 'image/svg+xml', ]; return $types[$ext] ?? 'application/octet-stream'; diff --git a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php index f96b4719..e70659a4 100644 --- a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php +++ b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php @@ -64,13 +64,37 @@ public function testBuildFile() $request = $this->request->withUri($uri); $result = $this->middleware->process($request, $this->handler); - $this->assertEquals('application/javascript', $result->getHeaderLine('Content-Type')); $body = $result->getBody()->getContents(); $this->assertStringContainsString('var BaseClass = new Class', $body); $this->assertStringContainsString('var Template = new Class', $body); } + public function contentTypesProvider() + { + return [ + ['/cache_js/libs.js', 'application/javascript'], + ['/cache_css/all.css', 'text/css'], + ['/cache_svg/foo.bar.svg', 'image/svg+xml'], + ]; + } + + /** + * test returned content types + * @dataProvider contentTypesProvider + * + * @return void + */ + public function testBuildFileContentTypes($path, $expected) + { + $uri = $this->request->getUri()->withPath($path); + $request = $this->request->withUri($uri); + + $result = $this->middleware->process($request, $this->handler); + + $this->assertEquals($expected, $result->getHeaderLine('Content-Type')); + } + /** * test building plugin assets. * @@ -85,8 +109,6 @@ public function testPluginIniBuildFile() $result = $this->middleware->process($request, $this->handler); - $this->assertEquals('application/javascript', $result->getHeaderLine('Content-Type')); - $body = $result->getBody()->getContents(); $this->assertStringContainsString('var BaseClass = new Class', $body); $this->assertStringContainsString('var Template = new Class', $body); @@ -105,7 +127,6 @@ public function testBuildFileIsCached() $result = $this->middleware->process($request, $this->handler); $body = $result->getBody()->getContents(); - $this->assertEquals('application/javascript', $result->getHeaderLine('Content-Type')); $this->assertStringContainsString('BaseClass', $body); $this->assertTrue(file_exists(CACHE . 'asset_compress' . DS . 'libs.js'), 'Cache file was created.'); @@ -142,7 +163,6 @@ public function testBuildThemedAsset() $result = $this->middleware->process($request, $this->handler); $body = $result->getBody()->getContents(); - $this->assertEquals('text/css', $result->getHeaderLine('Content-Type')); $this->assertStringContainsString('color: blue', $body); } From c662fa60c420318994cc0460f64ef6cdd813b6c6 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 15 Aug 2020 09:47:45 +0000 Subject: [PATCH 2/3] Fixing style errors. --- tests/TestCase/Middleware/AssetCompressMiddlewareTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php index e70659a4..4716328b 100644 --- a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php +++ b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php @@ -81,8 +81,8 @@ public function contentTypesProvider() /** * test returned content types - * @dataProvider contentTypesProvider * + * @dataProvider contentTypesProvider * @return void */ public function testBuildFileContentTypes($path, $expected) From 8313658ba3e76ec4c6e455fad9bdfdabf1ee2c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=82=E6=B5=81?= Date: Sat, 15 Aug 2020 23:02:47 +0200 Subject: [PATCH 3/3] Remove double spaces To make Stickler CI happy. --- tests/TestCase/Middleware/AssetCompressMiddlewareTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php index 4716328b..bde5b026 100644 --- a/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php +++ b/tests/TestCase/Middleware/AssetCompressMiddlewareTest.php @@ -73,8 +73,8 @@ public function testBuildFile() public function contentTypesProvider() { return [ - ['/cache_js/libs.js', 'application/javascript'], - ['/cache_css/all.css', 'text/css'], + ['/cache_js/libs.js', 'application/javascript'], + ['/cache_css/all.css', 'text/css'], ['/cache_svg/foo.bar.svg', 'image/svg+xml'], ]; }