diff --git a/Classes/Domain/Model/Import.php b/Classes/Domain/Model/Import.php index 400b034..1ae05b2 100644 --- a/Classes/Domain/Model/Import.php +++ b/Classes/Domain/Model/Import.php @@ -6,6 +6,7 @@ use TYPO3\CMS\Core\Resource\Folder; use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject; +use WerkraumMedia\Events\Domain\Model\Import\Features; /** * Actual request to import. @@ -26,7 +27,8 @@ public function __construct( protected ?Category $categoryParent = null, int $featuresPid = 0, protected ?Category $featuresParent = null, - protected ?Region $region = null + protected ?Region $region = null, + protected int $importFeatures = 0, ) { // Do not allow categories on pid 0 if ($categoriesPid === 0) { @@ -85,4 +87,9 @@ public function getSearchQuery(): string { return $this->restSearchQuery; } + + public function getFeatures(): Features + { + return new Features($this->importFeatures); + } } diff --git a/Classes/Domain/Model/Import/Features.php b/Classes/Domain/Model/Import/Features.php new file mode 100644 index 0000000..bf7a8c0 --- /dev/null +++ b/Classes/Domain/Model/Import/Features.php @@ -0,0 +1,36 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace WerkraumMedia\Events\Domain\Model\Import; + +use TYPO3\CMS\Core\Type\BitSet; + +final class Features extends BitSet +{ + public const HTML_FOR_DETAIL = 0b1; + + public function hasHtmlForDetailEnabled(): bool + { + return $this->get(self::HTML_FOR_DETAIL); + } +} diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index af04c2c..36df56c 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -356,25 +356,58 @@ private function hasRelation(string $needle, array $haystack): bool private function setTexts(array $texts): void { $shouldSetPrice = true; + $detailText = ''; + foreach ($texts as $text) { - if (isset($text['value']) === false) { + if ( + isset($text['value']) === false + || is_string($text['value']) === false + ) { continue; } - if ($text['rel'] == 'details' && $text['type'] == 'text/plain') { - $this->tmpCurrentEvent->setDetails(str_replace("\n\n", "\n", (string)$text['value'])); + $value = str_replace("\n\n", "\n", $text['value']); + + if ( + $text['rel'] == 'details' + && $text['type'] == 'text/html' + && $this->import->getFeatures()->hasHtmlForDetailEnabled() + && $value + ) { + $detailText = $value; + continue; } + + if ( + $text['rel'] == 'details' + && $text['type'] == 'text/plain' + && ( + $this->import->getFeatures()->hasHtmlForDetailEnabled() === false + || $detailText === '' + ) + ) { + $detailText = $value; + continue; + } + if ($text['rel'] == 'teaser' && $text['type'] == 'text/plain') { - $this->tmpCurrentEvent->setTeaser(str_replace("\n\n", "\n", (string)$text['value'])); + $this->tmpCurrentEvent->setTeaser($value); + continue; } + if ($shouldSetPrice && $text['rel'] == 'PRICE_INFO_EXTRA' && $text['type'] == 'text/plain') { $shouldSetPrice = false; - $this->tmpCurrentEvent->setPriceInfo(str_replace("\n\n", "\n", (string)$text['value'])); + $this->tmpCurrentEvent->setPriceInfo($value); + continue; } + if ($shouldSetPrice && $text['rel'] == 'PRICE_INFO' && $text['type'] == 'text/plain') { - $this->tmpCurrentEvent->setPriceInfo(str_replace("\n\n", "\n", (string)$text['value'])); + $this->tmpCurrentEvent->setPriceInfo($value); + continue; } } + + $this->tmpCurrentEvent->setDetails($detailText); } private function getOrCreateEvent(string $globalId, string $title): Event diff --git a/Configuration/TCA/tx_events_domain_model_import.php b/Configuration/TCA/tx_events_domain_model_import.php index cda62bb..e7f93cc 100644 --- a/Configuration/TCA/tx_events_domain_model_import.php +++ b/Configuration/TCA/tx_events_domain_model_import.php @@ -19,7 +19,20 @@ ], 'types' => [ '1' => [ - 'showitem' => 'title, hidden, --div--;LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.div.typo3, --palette--;;typo3_storage, --palette--;;categories, --palette--;;features,--palette--;;relations, --div--;LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.div.rest, rest_experience, rest_search_query', + 'showitem' => implode(',', [ + 'title', + 'hidden', + '--div--;LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.div.typo3', + '--palette--;;typo3_storage', + '--palette--;;categories', + '--palette--;;features', + '-palette--;;relations', + '--div--;LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.div.rest', + 'rest_experience', + 'rest_search_query', + '--div--;LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.div.import', + 'import_features', + ]), ], ], 'palettes' => [ @@ -169,5 +182,20 @@ 'max' => 255, ], ], + 'import_features' => [ + 'exclude' => true, + 'label' => 'LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.import_features', + 'description' => 'LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.import_features.description', + 'config' => [ + 'type' => 'check', + 'cols' => 'inline', + 'default' => '0', + 'items' => [ + [ + 'label' => 'LLL:EXT:events/Resources/Private/Language/locallang_csh_import.xlf:tx_events_domain_model_import.import_features.html_for_detail', + ], + ], + ], + ], ], ]; diff --git a/Documentation/Changelog/4.2.0.rst b/Documentation/Changelog/4.2.0.rst new file mode 100644 index 0000000..d23aec1 --- /dev/null +++ b/Documentation/Changelog/4.2.0.rst @@ -0,0 +1,33 @@ +4.2.0 +===== + +Breaking +-------- + +Nothing + +Features +-------- + +* Support HTML for detail text of events when importing data from destination.one. + + This can be enabled within the import configuration. That way one can restrict the + HTML import to certain import configurations. + + Ensure to adjust the templates when turning on the feature. + Either use `f:format.html` or `f:sanitize.html` as content might be unsafe. + +Fixes +----- + +Nothing + +Tasks +----- + +Nothing + +Deprecation +----------- + +Nothing diff --git a/Resources/Private/Language/locallang_csh_import.xlf b/Resources/Private/Language/locallang_csh_import.xlf index 8d81c0c..ca9ba97 100644 --- a/Resources/Private/Language/locallang_csh_import.xlf +++ b/Resources/Private/Language/locallang_csh_import.xlf @@ -12,6 +12,9 @@ REST + + Import + Relations @@ -81,6 +84,15 @@ See: https://developer.et4.de/reference/current/#eT4META-search-param-q.html (todo check, was not loadable) + + Import Features + + + Enable certain features related to the import. + + + HTML for Event Details + diff --git a/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsHtmlTextIfConfigured.php b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsHtmlTextIfConfigured.php new file mode 100644 index 0000000..1f12a97 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsHtmlTextIfConfigured.php @@ -0,0 +1,13 @@ + [ + 0 => [ + 'uid' => '1', + 'global_id' => 'e_100354481', + 'details' => 'Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.
Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)
Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.
Es gilt die 2G-PLUS-Regel. 
', + ], + ], +]; diff --git a/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfConfigured.php b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfConfigured.php new file mode 100644 index 0000000..71858dc --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfConfigured.php @@ -0,0 +1,18 @@ + [ + 0 => [ + 'uid' => '1', + 'global_id' => 'e_100354481', + 'details' => implode("\n", [ + 'Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.', + 'Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)', + 'Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.', + 'Es gilt die 2G-PLUS-Regel.', + ]), + ], + ], +]; diff --git a/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfHtmlIsConfiguredButUnavailable.php b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfHtmlIsConfiguredButUnavailable.php new file mode 100644 index 0000000..71858dc --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsPlainTextIfHtmlIsConfiguredButUnavailable.php @@ -0,0 +1,18 @@ + [ + 0 => [ + 'uid' => '1', + 'global_id' => 'e_100354481', + 'details' => implode("\n", [ + 'Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.', + 'Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)', + 'Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.', + 'Es gilt die 2G-PLUS-Regel.', + ]), + ], + ], +]; diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/Database/ImportConfigurationWithHtml.php b/Tests/Functional/Import/DestinationDataTest/Fixtures/Database/ImportConfigurationWithHtml.php new file mode 100644 index 0000000..0d93c0c --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/Database/ImportConfigurationWithHtml.php @@ -0,0 +1,18 @@ + [ + [ + 'uid' => '1', + 'pid' => '2', + 'title' => 'Example import configuration', + 'storage_pid' => '2', + 'files_folder' => '1:/staedte/beispielstadt/events/', + 'region' => '1', + 'rest_experience' => 'beispielstadt', + 'import_features' => '1', + ], + ], +]; diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithHtmlTextTexts.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithHtmlTextTexts.json new file mode 100644 index 0000000..a3ac3e9 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithHtmlTextTexts.json @@ -0,0 +1,84 @@ +{ + "status": "OK", + "count": 1, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100354481", + "id": "100354481", + "type": "Event", + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de/", + "email": "stadtbibliothek@rudolstadt.de", + "author": "support@hubermedia.de", + "cuisine_types": [], + "payment": [], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-07-13T15:00:00+02:00", + "end": "2022-07-13T16:30:00+02:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "numbers": [], + "name": "Stadtbibliothek Rudolstadt", + "attributes": [ + ], + "features": [ + ], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + } + ], + "created": "2099-11-10T23:02:00+00:00", + "changed": "2099-12-14T08:28:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.
Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)
Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.
Es gilt die 2G-PLUS-Regel. 
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.\nEintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)\nUm Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.\nEs gilt die 2G-PLUS-Regel." + } + ], + "title": "Kurzf\u00fchrung - Historische Altstadt", + "type": "Event", + "web": "http://www.erfurt-tourismus.de/stadtfuehrung/individuell/kurzfuehrung-historische-altstadt/", + "zip": "99084" + } + ] +} diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithPlainTextTexts.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithPlainTextTexts.json new file mode 100644 index 0000000..a3ac3e9 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithPlainTextTexts.json @@ -0,0 +1,84 @@ +{ + "status": "OK", + "count": 1, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100354481", + "id": "100354481", + "type": "Event", + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de/", + "email": "stadtbibliothek@rudolstadt.de", + "author": "support@hubermedia.de", + "cuisine_types": [], + "payment": [], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-07-13T15:00:00+02:00", + "end": "2022-07-13T16:30:00+02:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "numbers": [], + "name": "Stadtbibliothek Rudolstadt", + "attributes": [ + ], + "features": [ + ], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + } + ], + "created": "2099-11-10T23:02:00+00:00", + "changed": "2099-12-14T08:28:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.
Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)
Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.
Es gilt die 2G-PLUS-Regel. 
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.\nEintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)\nUm Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.\nEs gilt die 2G-PLUS-Regel." + } + ], + "title": "Kurzf\u00fchrung - Historische Altstadt", + "type": "Event", + "web": "http://www.erfurt-tourismus.de/stadtfuehrung/individuell/kurzfuehrung-historische-altstadt/", + "zip": "99084" + } + ] +} diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToEmptyType.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToEmptyType.json new file mode 100644 index 0000000..d980967 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToEmptyType.json @@ -0,0 +1,84 @@ +{ + "status": "OK", + "count": 1, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100354481", + "id": "100354481", + "type": "Event", + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de/", + "email": "stadtbibliothek@rudolstadt.de", + "author": "support@hubermedia.de", + "cuisine_types": [], + "payment": [], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-07-13T15:00:00+02:00", + "end": "2022-07-13T16:30:00+02:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "numbers": [], + "name": "Stadtbibliothek Rudolstadt", + "attributes": [ + ], + "features": [ + ], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + } + ], + "created": "2099-11-10T23:02:00+00:00", + "changed": "2099-12-14T08:28:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.\nEintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)\nUm Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.\nEs gilt die 2G-PLUS-Regel." + } + ], + "title": "Kurzf\u00fchrung - Historische Altstadt", + "type": "Event", + "web": "http://www.erfurt-tourismus.de/stadtfuehrung/individuell/kurzfuehrung-historische-altstadt/", + "zip": "99084" + } + ] +} diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToMissingType.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToMissingType.json new file mode 100644 index 0000000..e8c519a --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithoutHtmlTextTextsDueToMissingType.json @@ -0,0 +1,79 @@ +{ + "status": "OK", + "count": 1, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100354481", + "id": "100354481", + "type": "Event", + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de/", + "email": "stadtbibliothek@rudolstadt.de", + "author": "support@hubermedia.de", + "cuisine_types": [], + "payment": [], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-07-13T15:00:00+02:00", + "end": "2022-07-13T16:30:00+02:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "numbers": [], + "name": "Stadtbibliothek Rudolstadt", + "attributes": [ + ], + "features": [ + ], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + } + ], + "created": "2099-11-10T23:02:00+00:00", + "changed": "2099-12-14T08:28:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "texts": [ + { + "rel": "details", + "type": "text/plain", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.\nEintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)\nUm Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.\nEs gilt die 2G-PLUS-Regel." + } + ], + "title": "Kurzf\u00fchrung - Historische Altstadt", + "type": "Event", + "web": "http://www.erfurt-tourismus.de/stadtfuehrung/individuell/kurzfuehrung-historische-altstadt/", + "zip": "99084" + } + ] +} diff --git a/Tests/Functional/Import/DestinationDataTest/ImportsTextsTest.php b/Tests/Functional/Import/DestinationDataTest/ImportsTextsTest.php new file mode 100644 index 0000000..3831218 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/ImportsTextsTest.php @@ -0,0 +1,90 @@ +setUpConfiguration([ + 'restUrl = https://example.com/some-path/', + 'license = example-license', + 'restType = Event', + 'restLimit = 3', + 'restMode = next_months,12', + 'restTemplate = ET2014A.json', + ]); + } + + protected function tearDown(): void + { + $this->assertEmptyLog(); + + parent::tearDown(); + } + + #[Test] + public function importsPlainTextIfConfigured(): void + { + $this->importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php'); + + $requests = &$this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithPlainTextTexts.json') ?: ''), + ]); + + $tester = $this->executeCommand(); + + self::assertSame(0, $tester->getStatusCode()); + $this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsPlainTextIfConfigured.php'); + } + + #[Test] + public function importsHtmlTextIfConfiguredAndAvailable(): void + { + $this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportConfigurationWithHtml.php'); + $requests = &$this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithHtmlTextTexts.json') ?: ''), + ]); + + $tester = $this->executeCommand(); + + self::assertSame(0, $tester->getStatusCode()); + $this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsHtmlTextIfConfigured.php'); + } + + #[Test] + #[DataProvider('responseWithoutHtml')] + public function importsPlainTextIfHtmlIsConfiguredButUnavailable( + string $responseName + ): void { + $this->importPHPDataSet(__DIR__ . '/Fixtures/Database/ImportConfigurationWithHtml.php'); + $requests = &$this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithoutHtmlTextTextsDueTo' . $responseName . '.json') ?: ''), + ]); + + $tester = $this->executeCommand(); + + self::assertSame(0, $tester->getStatusCode()); + $this->assertPHPDataSet(__DIR__ . '/Assertions/ImportsPlainTextIfHtmlIsConfiguredButUnavailable.php'); + } + + public static function responseWithoutHtml(): iterable + { + yield 'Missing type text/html' => [ + 'responseName' => 'MissingType', + ]; + yield 'Empty type text/html' => [ + 'responseName' => 'EmptyType', + ]; + } +} diff --git a/ext_emconf.php b/ext_emconf.php index 028c3cf..6ad5214 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ 'author' => 'Dirk Koritnik, Daniel Siepmann', 'author_email' => 'koritnik@werkraum-media.de, coding@daniel-siepmann.de', 'state' => 'stable', - 'version' => '4.1.0', + 'version' => '4.2.0', 'constraints' => [ 'depends' => [ 'typo3' => '', diff --git a/ext_tables.sql b/ext_tables.sql index 01a8882..45178cd 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -85,6 +85,8 @@ CREATE TABLE tx_events_domain_model_import ( rest_experience varchar(1024) DEFAULT '' NOT NULL, rest_search_query varchar(1024) DEFAULT '' NOT NULL, + + import_features tinyint(4) DEFAULT '0' NOT NULL, ); CREATE TABLE tx_events_domain_model_location (