From 55f9adbbe07eaed9c97bbbf2991246ce8408ef83 Mon Sep 17 00:00:00 2001 From: mix5003 Date: Wed, 23 Dec 2020 12:36:03 +0700 Subject: [PATCH] fix can not override xml style --- src/Laravelium/Sitemap/Sitemap.php | 16 +++++++++------- tests/SitemapTest.php | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Laravelium/Sitemap/Sitemap.php b/src/Laravelium/Sitemap/Sitemap.php index 1998df3..f5e70f4 100644 --- a/src/Laravelium/Sitemap/Sitemap.php +++ b/src/Laravelium/Sitemap/Sitemap.php @@ -359,17 +359,19 @@ public function generate($format = 'xml', $style = null) ]; // check if styles are enabled - if ($this->model->getUseStyles()) { - if (null != $this->model->getSloc() && file_exists(public_path($this->model->getSloc().$format.'.xsl'))) { - // use style from your custom location - $style = $this->model->getSloc().$format.'.xsl'; + if (null == $style) { + if ($this->model->getUseStyles()) { + if (null != $this->model->getSloc() && file_exists(public_path($this->model->getSloc().$format.'.xsl'))) { + // use style from your custom location + $style = $this->model->getSloc().$format.'.xsl'; + } else { + // don't use style + $style = null; + } } else { // don't use style $style = null; } - } else { - // don't use style - $style = null; } switch ($format) { diff --git a/tests/SitemapTest.php b/tests/SitemapTest.php index 19e8f8e..c9422c0 100644 --- a/tests/SitemapTest.php +++ b/tests/SitemapTest.php @@ -301,6 +301,7 @@ public function testRenderSitemap() $sitemap = $this->sitemap->render('xml', '/styles/xsl/xml-sitemap.xsl'); $this->assertEquals('text/xml; charset=utf-8', $sitemap->headers->get('Content-Type')); + $this->assertStringContainsString('/styles/xsl/xml-sitemap.xsl', $sitemap->getContent()); $sitemap = $this->sitemap->render('sitemapindex'); $this->assertEquals('text/xml; charset=utf-8', $sitemap->headers->get('Content-Type'));