[BUGFIX] Records sitemap uses wrong data array 98/58598/3
authorSusanne Moog <susanne.moog@typo3.org>
Tue, 9 Oct 2018 10:12:29 +0000 (12:12 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 9 Oct 2018 12:02:38 +0000 (14:02 +0200)
The records sitemap has an additional level of nesting for
data from database but was trying to access database data
on the first level resulting in missing URL parameters in
generated URLs.

This array access has been fixed.

Resolves: #86602
Releases: master
Change-Id: I0e5e368f177ad2fc4358b8ef8927e220536fa59f
Reviewed-on: https://review.typo3.org/58598
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/seo/Classes/XmlSitemap/RecordsXmlSitemapDataProvider.php
typo3/sysext/seo/Tests/Functional/Fixtures/pages-sitemap.xml
typo3/sysext/seo/Tests/Functional/Fixtures/records.typoscript [new file with mode: 0644]
typo3/sysext/seo/Tests/Functional/Fixtures/sys_category.xml [new file with mode: 0644]
typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapRecordsTest.php [new file with mode: 0644]

index da3d9ff..aca31fc 100644 (file)
@@ -101,7 +101,7 @@ class RecordsXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider
         $pageId = $this->config['url']['pageId'] ?? $GLOBALS['TSFE']->id;
         $additionalParams = [];
 
-        $additionalParams = $this->getUrlFieldParameterMap($additionalParams, $data);
+        $additionalParams = $this->getUrlFieldParameterMap($additionalParams, $data['data']);
         $additionalParams = $this->getUrlAdditionalParams($additionalParams);
 
         $additionalParamsString = http_build_query(
index f61c853..721c9b3 100644 (file)
         <slug>/dummy-1-4-10</slug>
         <deleted>0</deleted>
     </pages>
+    <pages>
+        <uid>11</uid>
+        <pid>1</pid>
+        <title>SysFolder</title>
+        <doktype>254</doktype>
+        <deleted>0</deleted>
+    </pages>
 </dataset>
diff --git a/typo3/sysext/seo/Tests/Functional/Fixtures/records.typoscript b/typo3/sysext/seo/Tests/Functional/Fixtures/records.typoscript
new file mode 100644 (file)
index 0000000..30e86e4
--- /dev/null
@@ -0,0 +1,24 @@
+plugin.tx_seo {
+  config {
+    xmlSitemap {
+      sitemaps {
+        records {
+          provider = TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider
+          config {
+            table = sys_category
+            sortField = sorting
+            lastModifiedField = tstamp
+            pid = 11
+            url {
+              pageId = 1
+              fieldToParameterMap {
+                uid = tx_example_category[id]
+              }
+              useCacheHash = 1
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/typo3/sysext/seo/Tests/Functional/Fixtures/sys_category.xml b/typo3/sysext/seo/Tests/Functional/Fixtures/sys_category.xml
new file mode 100644 (file)
index 0000000..6437edf
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+       <sys_category>
+               <uid>1</uid>
+               <pid>11</pid>
+               <tstamp>1537545656</tstamp>
+               <crdate>1537545656</crdate>
+               <deleted>0</deleted>
+               <hidden>0</hidden>
+               <starttime>0</starttime>
+               <endtime>0</endtime>
+               <sorting>256</sorting>
+               <title>Examples</title>
+       </sys_category>
+       <sys_category>
+               <uid>2</uid>
+               <pid>11</pid>
+               <tstamp>1537545656</tstamp>
+               <crdate>1537545656</crdate>
+               <deleted>0</deleted>
+               <hidden>0</hidden>
+               <starttime>0</starttime>
+               <endtime>0</endtime>
+               <sorting>128</sorting>
+               <title>News</title>
+       </sys_category>
+</data>
diff --git a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapRecordsTest.php b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapRecordsTest.php
new file mode 100644 (file)
index 0000000..8c3f5b1
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Frontend\Tests\Functional\XmlSitemap;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase;
+use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
+
+/**
+ * Contains functional tests for the XmlSitemap Index
+ */
+class XmlSitemapRecordsTest extends AbstractTestCase
+{
+    /**
+     * @var string[]
+     */
+    protected $coreExtensionsToLoad = [
+        'core',
+        'frontend',
+        'seo'
+    ];
+
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/pages-sitemap.xml');
+        $this->importDataSet('EXT:seo/Tests/Functional/Fixtures/sys_category.xml');
+        $this->setUpFrontendRootPage(
+            1,
+            [
+                'constants' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript'],
+                'setup' => [
+                    'EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript',
+                    'EXT:seo/Tests/Functional/Fixtures/records.typoscript'
+                ],
+            ]
+        );
+    }
+
+    /**
+     * @test
+     */
+    public function checkIfSiteMapIndexContainsSysCategoryLinks(): void
+    {
+        $this->writeSiteConfiguration(
+            'website-local',
+            $this->buildSiteConfiguration(1, 'http://localhost/'),
+            [
+                $this->buildDefaultLanguageConfiguration('EN', '/'),
+            ]
+        );
+
+        $response = $this->executeFrontendRequest(
+            (new InternalRequest('http://localhost/'))->withQueryParameters(
+                [
+                    'id' => 1,
+                    'type' => 1533906435,
+                    'sitemap' => 'records',
+                ]
+            )
+        );
+
+        $this->assertEquals(200, $response->getStatusCode());
+        $this->assertArrayHasKey('Content-Length', $response->getHeaders());
+        $stream = $response->getBody();
+        $stream->rewind();
+        $content = $stream->getContents();
+        self::assertContains('http://localhost/?tx_example_category%5Bid%5D=1&amp;', $content);
+        self::assertContains('http://localhost/?tx_example_category%5Bid%5D=2&amp;', $content);
+        $this->assertGreaterThan(0, $response->getHeader('Content-Length')[0]);
+    }
+}