mirror of
https://github.com/werkraum-media/thuecat.git
synced 2024-06-29 06:48:56 +02:00
Fix two bugs: Language handling and price structure
Sorry for fixing two things in one commit. First fixed bug is single offer and / or single price. Those lead to exception / fatal error and are now handled. Second fixed bug is wrong multi language handling. Instead of using supported languages from entity (which does not exist and was miss interpreted) we use configured system languages. Each record is inserted with default language. Also tourist attractions are inserted for all other languages. They are only inserted if they have a title for that language.
This commit is contained in:
parent
261039361b
commit
bf1ae9540b
|
@ -24,6 +24,7 @@ namespace WerkraumMedia\ThueCat\Domain\Import\Converter;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
||||||
|
@ -32,15 +33,20 @@ use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
||||||
class Organisation implements Converter
|
class Organisation implements Converter
|
||||||
{
|
{
|
||||||
private Parser $parser;
|
private Parser $parser;
|
||||||
|
private LanguageHandling $language;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Parser $parser
|
Parser $parser,
|
||||||
|
LanguageHandling $language
|
||||||
) {
|
) {
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
$this->language = $language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
||||||
{
|
{
|
||||||
|
$language = $this->language->getDefaultLanguage($configuration->getStoragePid());
|
||||||
|
|
||||||
$entity = GeneralUtility::makeInstance(
|
$entity = GeneralUtility::makeInstance(
|
||||||
GenericEntity::class,
|
GenericEntity::class,
|
||||||
$configuration->getStoragePid(),
|
$configuration->getStoragePid(),
|
||||||
|
@ -48,8 +54,8 @@ class Organisation implements Converter
|
||||||
0,
|
0,
|
||||||
$this->parser->getId($jsonLD),
|
$this->parser->getId($jsonLD),
|
||||||
[
|
[
|
||||||
'title' => $this->parser->getTitle($jsonLD),
|
'title' => $this->parser->getTitle($jsonLD, $language),
|
||||||
'description' => $this->parser->getDescription($jsonLD),
|
'description' => $this->parser->getDescription($jsonLD, $language),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$entities = GeneralUtility::makeInstance(EntityCollection::class);
|
$entities = GeneralUtility::makeInstance(EntityCollection::class);
|
||||||
|
|
|
@ -62,8 +62,9 @@ class TouristAttraction implements Converter
|
||||||
$entities = GeneralUtility::makeInstance(EntityCollection::class);
|
$entities = GeneralUtility::makeInstance(EntityCollection::class);
|
||||||
$storagePid = $configuration->getStoragePid();
|
$storagePid = $configuration->getStoragePid();
|
||||||
|
|
||||||
foreach ($this->parser->getLanguages($jsonLD) as $language) {
|
foreach ($this->language->getLanguages($storagePid) as $language) {
|
||||||
if ($this->language->isUnknown($language, $storagePid)) {
|
$title = $this->parser->getTitle($jsonLD, $language);
|
||||||
|
if ($title === '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ class TouristAttraction implements Converter
|
||||||
GenericEntity::class,
|
GenericEntity::class,
|
||||||
$storagePid,
|
$storagePid,
|
||||||
'tx_thuecat_tourist_attraction',
|
'tx_thuecat_tourist_attraction',
|
||||||
$this->language->getSystemUid($language, $storagePid),
|
$language->getLanguageId(),
|
||||||
$this->parser->getId($jsonLD),
|
$this->parser->getId($jsonLD),
|
||||||
[
|
[
|
||||||
'title' => $this->parser->getTitle($jsonLD, $language),
|
'title' => $this->parser->getTitle($jsonLD, $language),
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace WerkraumMedia\ThueCat\Domain\Import\Converter;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
||||||
|
@ -34,21 +35,25 @@ use WerkraumMedia\ThueCat\Domain\Repository\Backend\TownRepository;
|
||||||
class TouristInformation implements Converter
|
class TouristInformation implements Converter
|
||||||
{
|
{
|
||||||
private Parser $parser;
|
private Parser $parser;
|
||||||
|
private LanguageHandling $language;
|
||||||
private OrganisationRepository $organisationRepository;
|
private OrganisationRepository $organisationRepository;
|
||||||
private TownRepository $townRepository;
|
private TownRepository $townRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Parser $parser,
|
Parser $parser,
|
||||||
|
LanguageHandling $language,
|
||||||
OrganisationRepository $organisationRepository,
|
OrganisationRepository $organisationRepository,
|
||||||
TownRepository $townRepository
|
TownRepository $townRepository
|
||||||
) {
|
) {
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
$this->language = $language;
|
||||||
$this->organisationRepository = $organisationRepository;
|
$this->organisationRepository = $organisationRepository;
|
||||||
$this->townRepository = $townRepository;
|
$this->townRepository = $townRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
||||||
{
|
{
|
||||||
|
$language = $this->language->getDefaultLanguage($configuration->getStoragePid());
|
||||||
$manager = $this->organisationRepository->findOneByRemoteId(
|
$manager = $this->organisationRepository->findOneByRemoteId(
|
||||||
$this->parser->getManagerId($jsonLD)
|
$this->parser->getManagerId($jsonLD)
|
||||||
);
|
);
|
||||||
|
@ -63,8 +68,8 @@ class TouristInformation implements Converter
|
||||||
0,
|
0,
|
||||||
$this->parser->getId($jsonLD),
|
$this->parser->getId($jsonLD),
|
||||||
[
|
[
|
||||||
'title' => $this->parser->getTitle($jsonLD),
|
'title' => $this->parser->getTitle($jsonLD, $language),
|
||||||
'description' => $this->parser->getDescription($jsonLD),
|
'description' => $this->parser->getDescription($jsonLD, $language),
|
||||||
'managed_by' => $manager ? $manager->getUid() : 0,
|
'managed_by' => $manager ? $manager->getUid() : 0,
|
||||||
'town' => $town ? $town->getUid() : 0,
|
'town' => $town ? $town->getUid() : 0,
|
||||||
]
|
]
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace WerkraumMedia\ThueCat\Domain\Import\Converter;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity;
|
||||||
|
@ -33,18 +34,22 @@ use WerkraumMedia\ThueCat\Domain\Repository\Backend\OrganisationRepository;
|
||||||
class Town implements Converter
|
class Town implements Converter
|
||||||
{
|
{
|
||||||
private Parser $parser;
|
private Parser $parser;
|
||||||
|
private LanguageHandling $language;
|
||||||
private OrganisationRepository $organisationRepository;
|
private OrganisationRepository $organisationRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Parser $parser,
|
Parser $parser,
|
||||||
|
LanguageHandling $language,
|
||||||
OrganisationRepository $organisationRepository
|
OrganisationRepository $organisationRepository
|
||||||
) {
|
) {
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
$this->language = $language;
|
||||||
$this->organisationRepository = $organisationRepository;
|
$this->organisationRepository = $organisationRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
public function convert(array $jsonLD, ImportConfiguration $configuration): EntityCollection
|
||||||
{
|
{
|
||||||
|
$language = $this->language->getDefaultLanguage($configuration->getStoragePid());
|
||||||
$manager = $this->organisationRepository->findOneByRemoteId(
|
$manager = $this->organisationRepository->findOneByRemoteId(
|
||||||
$this->parser->getManagerId($jsonLD)
|
$this->parser->getManagerId($jsonLD)
|
||||||
);
|
);
|
||||||
|
@ -56,8 +61,8 @@ class Town implements Converter
|
||||||
0,
|
0,
|
||||||
$this->parser->getId($jsonLD),
|
$this->parser->getId($jsonLD),
|
||||||
[
|
[
|
||||||
'title' => $this->parser->getTitle($jsonLD),
|
'title' => $this->parser->getTitle($jsonLD, $language),
|
||||||
'description' => $this->parser->getDescription($jsonLD),
|
'description' => $this->parser->getDescription($jsonLD, $language),
|
||||||
'managed_by' => $manager ? $manager->getUid() : 0,
|
'managed_by' => $manager ? $manager->getUid() : 0,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -34,31 +34,16 @@ class LanguageHandling
|
||||||
$this->siteFinder = $siteFinder;
|
$this->siteFinder = $siteFinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUnknown(string $languageIsoCode, int $pageUid): bool
|
|
||||||
{
|
|
||||||
$availableIsoCodes = array_map(function (SiteLanguage $language) {
|
|
||||||
return $language->getTwoLetterIsoCode();
|
|
||||||
}, $this->getLanguages($pageUid));
|
|
||||||
|
|
||||||
return in_array($languageIsoCode, $availableIsoCodes) === false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSystemUid(string $languageIsoCode, int $pageUid): int
|
|
||||||
{
|
|
||||||
foreach ($this->getLanguages($pageUid) as $language) {
|
|
||||||
if ($language->getTwoLetterIsoCode() === $languageIsoCode) {
|
|
||||||
return $language->getLanguageId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return SiteLanguage[]
|
* @return SiteLanguage[]
|
||||||
*/
|
*/
|
||||||
private function getLanguages(int $pageUid): array
|
public function getLanguages(int $pageUid): array
|
||||||
{
|
{
|
||||||
return $this->siteFinder->getSiteByPageId($pageUid)->getLanguages();
|
return $this->siteFinder->getSiteByPageId($pageUid)->getLanguages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDefaultLanguage(int $pageUid): SiteLanguage
|
||||||
|
{
|
||||||
|
return $this->siteFinder->getSiteByPageId($pageUid)->getDefaultLanguage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD;
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Address;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Address;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Media;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Media;
|
||||||
|
@ -52,12 +53,12 @@ class Parser
|
||||||
return $jsonLD['@id'];
|
return $jsonLD['@id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(array $jsonLD, string $language = ''): string
|
public function getTitle(array $jsonLD, SiteLanguage $language): string
|
||||||
{
|
{
|
||||||
return $this->genericFields->getTitle($jsonLD, $language);
|
return $this->genericFields->getTitle($jsonLD, $language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription(array $jsonLD, string $language = ''): string
|
public function getDescription(array $jsonLD, SiteLanguage $language): string
|
||||||
{
|
{
|
||||||
return $this->genericFields->getDescription($jsonLD, $language);
|
return $this->genericFields->getDescription($jsonLD, $language);
|
||||||
}
|
}
|
||||||
|
@ -91,41 +92,4 @@ class Parser
|
||||||
{
|
{
|
||||||
return $this->media->get($jsonLD);
|
return $this->media->get($jsonLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function getLanguages(array $jsonLD): array
|
|
||||||
{
|
|
||||||
if (isset($jsonLD['schema:availableLanguage']) === false) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$languages = $jsonLD['schema:availableLanguage'];
|
|
||||||
|
|
||||||
$languages = array_filter($languages, function (array $language) {
|
|
||||||
return isset($language['@type'])
|
|
||||||
&& $language['@type'] === 'thuecat:Language'
|
|
||||||
;
|
|
||||||
});
|
|
||||||
|
|
||||||
$languages = array_map(function (array $language) {
|
|
||||||
$language = $language['@value'];
|
|
||||||
|
|
||||||
// TODO: Make configurable / easier to extend
|
|
||||||
if ($language === 'thuecat:German') {
|
|
||||||
return 'de';
|
|
||||||
}
|
|
||||||
if ($language === 'thuecat:English') {
|
|
||||||
return 'en';
|
|
||||||
}
|
|
||||||
if ($language === 'thuecat:French') {
|
|
||||||
return 'fr';
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception('Unsupported language "' . $language . '".', 1612367481);
|
|
||||||
}, $languages);
|
|
||||||
|
|
||||||
return $languages;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
|
|
||||||
class GenericFields
|
class GenericFields
|
||||||
{
|
{
|
||||||
private LanguageValues $languageValues;
|
private LanguageValues $languageValues;
|
||||||
|
@ -31,12 +33,12 @@ class GenericFields
|
||||||
$this->languageValues = $languageValues;
|
$this->languageValues = $languageValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(array $jsonLD, string $language = ''): string
|
public function getTitle(array $jsonLD, SiteLanguage $language): string
|
||||||
{
|
{
|
||||||
return $this->languageValues->getValueForLanguage($jsonLD['schema:name'] ?? [], $language);
|
return $this->languageValues->getValueForLanguage($jsonLD['schema:name'] ?? [], $language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDescription(array $jsonLD, string $language = ''): string
|
public function getDescription(array $jsonLD, SiteLanguage $language): string
|
||||||
{
|
{
|
||||||
return $this->languageValues->getValueForLanguage($jsonLD['schema:description'] ?? [], $language);
|
return $this->languageValues->getValueForLanguage($jsonLD['schema:description'] ?? [], $language);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,17 @@ namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
|
|
||||||
class LanguageValues
|
class LanguageValues
|
||||||
{
|
{
|
||||||
public function getValueForLanguage(
|
public function getValueForLanguage(
|
||||||
array $property,
|
array $property,
|
||||||
string $language
|
SiteLanguage $language
|
||||||
): string {
|
): string {
|
||||||
if (
|
if (
|
||||||
$this->doesLanguageMatch($property, $language)
|
isset($property['@value'])
|
||||||
&& isset($property['@value'])
|
&& $this->doesLanguageMatch($property, $language)
|
||||||
) {
|
) {
|
||||||
return $property['@value'];
|
return $property['@value'];
|
||||||
}
|
}
|
||||||
|
@ -48,13 +50,12 @@ class LanguageValues
|
||||||
|
|
||||||
private function doesLanguageMatch(
|
private function doesLanguageMatch(
|
||||||
array $property,
|
array $property,
|
||||||
string $language
|
SiteLanguage $language
|
||||||
): bool {
|
): bool {
|
||||||
|
$isoCode = $language->getTwoLetterIsoCode();
|
||||||
|
|
||||||
return isset($property['@language'])
|
return isset($property['@language'])
|
||||||
&& (
|
&& $property['@language'] === $isoCode
|
||||||
$property['@language'] === $language
|
|
||||||
|| $language === ''
|
|
||||||
)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
|
|
||||||
class Offers
|
class Offers
|
||||||
{
|
{
|
||||||
private GenericFields $genericFields;
|
private GenericFields $genericFields;
|
||||||
|
@ -31,10 +33,17 @@ class Offers
|
||||||
$this->genericFields = $genericFields;
|
$this->genericFields = $genericFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(array $jsonLD, string $language): array
|
public function get(array $jsonLD, SiteLanguage $language): array
|
||||||
{
|
{
|
||||||
$offers = [];
|
$offers = [];
|
||||||
$jsonLDOffers = $jsonLD['schema:makesOffer'] ?? [];
|
$jsonLDOffers = $jsonLD['schema:makesOffer'] ?? [];
|
||||||
|
|
||||||
|
if (isset($jsonLDOffers['@id'])) {
|
||||||
|
return [
|
||||||
|
$this->getOffer($jsonLDOffers, $language),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($jsonLDOffers as $jsonLDOffer) {
|
foreach ($jsonLDOffers as $jsonLDOffer) {
|
||||||
$offer = $this->getOffer($jsonLDOffer, $language);
|
$offer = $this->getOffer($jsonLDOffer, $language);
|
||||||
if ($offer !== []) {
|
if ($offer !== []) {
|
||||||
|
@ -45,7 +54,7 @@ class Offers
|
||||||
return $offers;
|
return $offers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getOffer(array $jsonLD, string $language): array
|
private function getOffer(array $jsonLD, SiteLanguage $language): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'title' => $this->genericFields->getTitle($jsonLD, $language),
|
'title' => $this->genericFields->getTitle($jsonLD, $language),
|
||||||
|
@ -54,11 +63,17 @@ class Offers
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrices(array $jsonLD, string $language): array
|
private function getPrices(array $jsonLD, SiteLanguage $language): array
|
||||||
{
|
{
|
||||||
$prices = [];
|
$prices = [];
|
||||||
$jsonLDPrices = $jsonLD['schema:priceSpecification'] ?? [];
|
$jsonLDPrices = $jsonLD['schema:priceSpecification'] ?? [];
|
||||||
|
|
||||||
|
if (isset($jsonLDPrices['@id'])) {
|
||||||
|
return [
|
||||||
|
$this->getPrice($jsonLDPrices, $language),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($jsonLDPrices as $jsonLDPrice) {
|
foreach ($jsonLDPrices as $jsonLDPrice) {
|
||||||
$price = $this->getPrice($jsonLDPrice, $language);
|
$price = $this->getPrice($jsonLDPrice, $language);
|
||||||
if ($price !== []) {
|
if ($price !== []) {
|
||||||
|
@ -69,7 +84,7 @@ class Offers
|
||||||
return $prices;
|
return $prices;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrice(array $jsonLD, string $language): array
|
private function getPrice(array $jsonLD, SiteLanguage $language): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'title' => $this->genericFields->getTitle($jsonLD, $language),
|
'title' => $this->genericFields->getTitle($jsonLD, $language),
|
||||||
|
|
|
@ -25,8 +25,10 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Converter;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\Organisation;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Organisation;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
||||||
|
@ -46,7 +48,13 @@ class OrganisationTest extends TestCase
|
||||||
public function instanceCanBeCreated(): void
|
public function instanceCanBeCreated(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$subject = new Organisation($parser->reveal());
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
|
||||||
|
$subject = new Organisation(
|
||||||
|
$parser->reveal(),
|
||||||
|
$language->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
self::assertInstanceOf(Organisation::class, $subject);
|
self::assertInstanceOf(Organisation::class, $subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +64,13 @@ class OrganisationTest extends TestCase
|
||||||
public function isInstanceOfConverter(): void
|
public function isInstanceOfConverter(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$subject = new Organisation($parser->reveal());
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
|
||||||
|
$subject = new Organisation(
|
||||||
|
$parser->reveal(),
|
||||||
|
$language->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
self::assertInstanceOf(Converter::class, $subject);
|
self::assertInstanceOf(Converter::class, $subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +80,13 @@ class OrganisationTest extends TestCase
|
||||||
public function canConvertTouristMarketingCompany(): void
|
public function canConvertTouristMarketingCompany(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$subject = new Organisation($parser->reveal());
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
|
||||||
|
$subject = new Organisation(
|
||||||
|
$parser->reveal(),
|
||||||
|
$language->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
self::assertTrue($subject->canConvert([
|
self::assertTrue($subject->canConvert([
|
||||||
'thuecat:TouristMarketingCompany',
|
'thuecat:TouristMarketingCompany',
|
||||||
'schema:Thing',
|
'schema:Thing',
|
||||||
|
@ -89,15 +109,24 @@ class OrganisationTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getDefaultLanguage(10)->willReturn($siteLanguage->reveal());
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD)->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD)->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
|
|
||||||
$configuration = $this->prophesize(ImportConfiguration::class);
|
$configuration = $this->prophesize(ImportConfiguration::class);
|
||||||
$configuration->getStoragePid()->willReturn(10);
|
$configuration->getStoragePid()->willReturn(10);
|
||||||
|
|
||||||
$subject = new Organisation($parser->reveal());
|
$subject = new Organisation(
|
||||||
|
$parser->reveal(),
|
||||||
|
$language->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
||||||
|
|
||||||
self::assertInstanceOf(EntityCollection::class, $entities);
|
self::assertInstanceOf(EntityCollection::class, $entities);
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Converter;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\TouristAttraction;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\TouristAttraction;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
|
@ -117,26 +118,26 @@ class TouristAttractionTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
$siteLanguage->getLanguageId()->willReturn(2);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getLanguages(10)->willReturn([$siteLanguage->reveal()]);
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
||||||
'https://example.com/resources/043064193523-jcyt',
|
'https://example.com/resources/043064193523-jcyt',
|
||||||
'https://example.com/resources/573211638937-gmqb',
|
'https://example.com/resources/573211638937-gmqb',
|
||||||
]);
|
]);
|
||||||
$parser->getLanguages($jsonLD)->willReturn(['de']);
|
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD, 'de')->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD, 'de')->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
$parser->getOpeningHours($jsonLD)->willReturn([]);
|
$parser->getOpeningHours($jsonLD)->willReturn([]);
|
||||||
$parser->getAddress($jsonLD)->willReturn([]);
|
$parser->getAddress($jsonLD)->willReturn([]);
|
||||||
$parser->getMedia($jsonLD)->willReturn([]);
|
$parser->getMedia($jsonLD)->willReturn([]);
|
||||||
|
|
||||||
$parserForOffers = $this->prophesize(Offers::class);
|
$parserForOffers = $this->prophesize(Offers::class);
|
||||||
$parserForOffers->get($jsonLD, 'de')->willReturn([]);
|
$parserForOffers->get($jsonLD, $siteLanguage->reveal())->willReturn([]);
|
||||||
|
|
||||||
$language = $this->prophesize(LanguageHandling::class);
|
|
||||||
$language->isUnknown('de', 10)->willReturn(false);
|
|
||||||
$language->getSystemUid('de', 10)->willReturn(0);
|
|
||||||
|
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$townRepository = $this->prophesize(TownRepository::class);
|
$townRepository = $this->prophesize(TownRepository::class);
|
||||||
|
@ -159,6 +160,7 @@ class TouristAttractionTest extends TestCase
|
||||||
|
|
||||||
$entity = $entities->getEntities()[0];
|
$entity = $entities->getEntities()[0];
|
||||||
self::assertSame(10, $entity->getTypo3StoragePid());
|
self::assertSame(10, $entity->getTypo3StoragePid());
|
||||||
|
self::assertSame(2, $entity->getTypo3SystemLanguageUid());
|
||||||
self::assertSame('tx_thuecat_tourist_attraction', $entity->getTypo3DatabaseTableName());
|
self::assertSame('tx_thuecat_tourist_attraction', $entity->getTypo3DatabaseTableName());
|
||||||
self::assertSame('https://example.com/resources/018132452787-ngbe', $entity->getRemoteId());
|
self::assertSame('https://example.com/resources/018132452787-ngbe', $entity->getRemoteId());
|
||||||
self::assertSame([
|
self::assertSame([
|
||||||
|
@ -201,26 +203,26 @@ class TouristAttractionTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
$siteLanguage->getLanguageId()->willReturn(2);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getLanguages(10)->willReturn([$siteLanguage->reveal()]);
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
||||||
'https://example.com/resources/043064193523-jcyt',
|
'https://example.com/resources/043064193523-jcyt',
|
||||||
'https://example.com/resources/573211638937-gmqb',
|
'https://example.com/resources/573211638937-gmqb',
|
||||||
]);
|
]);
|
||||||
$parser->getLanguages($jsonLD)->willReturn(['de']);
|
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD, 'de')->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD, 'de')->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
$parser->getOpeningHours($jsonLD)->willReturn([]);
|
$parser->getOpeningHours($jsonLD)->willReturn([]);
|
||||||
$parser->getAddress($jsonLD)->willReturn([]);
|
$parser->getAddress($jsonLD)->willReturn([]);
|
||||||
$parser->getMedia($jsonLD)->willReturn([]);
|
$parser->getMedia($jsonLD)->willReturn([]);
|
||||||
|
|
||||||
$parserForOffers = $this->prophesize(Offers::class);
|
$parserForOffers = $this->prophesize(Offers::class);
|
||||||
$parserForOffers->get($jsonLD, 'de')->willReturn([]);
|
$parserForOffers->get($jsonLD, $siteLanguage->reveal())->willReturn([]);
|
||||||
|
|
||||||
$language = $this->prophesize(LanguageHandling::class);
|
|
||||||
$language->isUnknown('de', 10)->willReturn(false);
|
|
||||||
$language->getSystemUid('de', 10)->willReturn(0);
|
|
||||||
|
|
||||||
$organisation = $this->prophesize(Organisation::class);
|
$organisation = $this->prophesize(Organisation::class);
|
||||||
$organisation->getUid()->willReturn(10);
|
$organisation->getUid()->willReturn(10);
|
||||||
|
@ -253,6 +255,7 @@ class TouristAttractionTest extends TestCase
|
||||||
|
|
||||||
$entity = $entities->getEntities()[0];
|
$entity = $entities->getEntities()[0];
|
||||||
self::assertSame(10, $entity->getTypo3StoragePid());
|
self::assertSame(10, $entity->getTypo3StoragePid());
|
||||||
|
self::assertSame(2, $entity->getTypo3SystemLanguageUid());
|
||||||
self::assertSame('tx_thuecat_tourist_attraction', $entity->getTypo3DatabaseTableName());
|
self::assertSame('tx_thuecat_tourist_attraction', $entity->getTypo3DatabaseTableName());
|
||||||
self::assertSame('https://example.com/resources/018132452787-ngbe', $entity->getRemoteId());
|
self::assertSame('https://example.com/resources/018132452787-ngbe', $entity->getRemoteId());
|
||||||
self::assertSame([
|
self::assertSame([
|
||||||
|
@ -266,4 +269,66 @@ class TouristAttractionTest extends TestCase
|
||||||
'offers' => '[]',
|
'offers' => '[]',
|
||||||
], $entity->getData());
|
], $entity->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function skipsLanguagesWithoutTitle(): void
|
||||||
|
{
|
||||||
|
$jsonLD = [
|
||||||
|
'@id' => 'https://example.com/resources/018132452787-ngbe',
|
||||||
|
'thuecat:managedBy' => [
|
||||||
|
'@id' => 'https://example.com/resources/018132452787-xxxx',
|
||||||
|
],
|
||||||
|
'schema:containedInPlace' => [
|
||||||
|
[
|
||||||
|
'@id' => 'https://example.com/resources/043064193523-jcyt',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'@id' => 'https://example.com/resources/573211638937-gmqb',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'schema:name' => [
|
||||||
|
'@value' => 'Title',
|
||||||
|
],
|
||||||
|
'schema:description' => [
|
||||||
|
[
|
||||||
|
'@value' => 'Description',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
$siteLanguage->getLanguageId()->willReturn(2);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getLanguages(10)->willReturn([$siteLanguage->reveal()]);
|
||||||
|
|
||||||
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
|
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
||||||
|
'https://example.com/resources/043064193523-jcyt',
|
||||||
|
'https://example.com/resources/573211638937-gmqb',
|
||||||
|
]);
|
||||||
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('');
|
||||||
|
$parserForOffers = $this->prophesize(Offers::class);
|
||||||
|
|
||||||
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
|
$townRepository = $this->prophesize(TownRepository::class);
|
||||||
|
|
||||||
|
$configuration = $this->prophesize(ImportConfiguration::class);
|
||||||
|
$configuration->getStoragePid()->willReturn(10);
|
||||||
|
|
||||||
|
$subject = new TouristAttraction(
|
||||||
|
$parser->reveal(),
|
||||||
|
$parserForOffers->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
|
$organisationRepository->reveal(),
|
||||||
|
$townRepository->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
||||||
|
|
||||||
|
self::assertInstanceOf(EntityCollection::class, $entities);
|
||||||
|
self::assertCount(0, $entities->getEntities());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Converter;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\TouristInformation;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\TouristInformation;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
||||||
|
@ -50,11 +52,13 @@ class TouristInformationTest extends TestCase
|
||||||
public function instanceCanBeCreated(): void
|
public function instanceCanBeCreated(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$townRepository = $this->prophesize(TownRepository::class);
|
$townRepository = $this->prophesize(TownRepository::class);
|
||||||
|
|
||||||
$subject = new TouristInformation(
|
$subject = new TouristInformation(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal(),
|
$organisationRepository->reveal(),
|
||||||
$townRepository->reveal()
|
$townRepository->reveal()
|
||||||
);
|
);
|
||||||
|
@ -67,11 +71,13 @@ class TouristInformationTest extends TestCase
|
||||||
public function isInstanceOfConverter(): void
|
public function isInstanceOfConverter(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$townRepository = $this->prophesize(TownRepository::class);
|
$townRepository = $this->prophesize(TownRepository::class);
|
||||||
|
|
||||||
$subject = new TouristInformation(
|
$subject = new TouristInformation(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal(),
|
$organisationRepository->reveal(),
|
||||||
$townRepository->reveal()
|
$townRepository->reveal()
|
||||||
);
|
);
|
||||||
|
@ -84,11 +90,13 @@ class TouristInformationTest extends TestCase
|
||||||
public function canConvertTouristMarketingCompany(): void
|
public function canConvertTouristMarketingCompany(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$townRepository = $this->prophesize(TownRepository::class);
|
$townRepository = $this->prophesize(TownRepository::class);
|
||||||
|
|
||||||
$subject = new TouristInformation(
|
$subject = new TouristInformation(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal(),
|
$organisationRepository->reveal(),
|
||||||
$townRepository->reveal()
|
$townRepository->reveal()
|
||||||
);
|
);
|
||||||
|
@ -125,6 +133,11 @@ class TouristInformationTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getDefaultLanguage(10)->willReturn($siteLanguage);
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
||||||
|
@ -132,8 +145,8 @@ class TouristInformationTest extends TestCase
|
||||||
'https://example.com/resources/573211638937-gmqb',
|
'https://example.com/resources/573211638937-gmqb',
|
||||||
]);
|
]);
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD)->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD)->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
|
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$organisationRepository->findOneByRemoteId('https://example.com/resources/018132452787-xxxx')
|
$organisationRepository->findOneByRemoteId('https://example.com/resources/018132452787-xxxx')
|
||||||
|
@ -150,6 +163,7 @@ class TouristInformationTest extends TestCase
|
||||||
|
|
||||||
$subject = new TouristInformation(
|
$subject = new TouristInformation(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal(),
|
$organisationRepository->reveal(),
|
||||||
$townRepository->reveal()
|
$townRepository->reveal()
|
||||||
);
|
);
|
||||||
|
@ -199,6 +213,11 @@ class TouristInformationTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getDefaultLanguage(10)->willReturn($siteLanguage);
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
$parser->getContainedInPlaceIds($jsonLD)->willReturn([
|
||||||
|
@ -206,8 +225,8 @@ class TouristInformationTest extends TestCase
|
||||||
'https://example.com/resources/573211638937-gmqb',
|
'https://example.com/resources/573211638937-gmqb',
|
||||||
]);
|
]);
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD)->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD)->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
|
|
||||||
$organisation = $this->prophesize(Organisation::class);
|
$organisation = $this->prophesize(Organisation::class);
|
||||||
$organisation->getUid()->willReturn(10);
|
$organisation->getUid()->willReturn(10);
|
||||||
|
@ -228,6 +247,7 @@ class TouristInformationTest extends TestCase
|
||||||
|
|
||||||
$subject = new TouristInformation(
|
$subject = new TouristInformation(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal(),
|
$organisationRepository->reveal(),
|
||||||
$townRepository->reveal()
|
$townRepository->reveal()
|
||||||
);
|
);
|
||||||
|
|
|
@ -25,8 +25,10 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Converter;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Converter\Town;
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Town;
|
||||||
|
use WerkraumMedia\ThueCat\Domain\Import\Importer\LanguageHandling;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
||||||
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
use WerkraumMedia\ThueCat\Domain\Model\Backend\ImportConfiguration;
|
||||||
|
@ -48,10 +50,12 @@ class TownTest extends TestCase
|
||||||
public function instanceCanBeCreated(): void
|
public function instanceCanBeCreated(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
|
|
||||||
$subject = new Town(
|
$subject = new Town(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal()
|
$organisationRepository->reveal()
|
||||||
);
|
);
|
||||||
self::assertInstanceOf(Town::class, $subject);
|
self::assertInstanceOf(Town::class, $subject);
|
||||||
|
@ -63,10 +67,12 @@ class TownTest extends TestCase
|
||||||
public function isInstanceOfConverter(): void
|
public function isInstanceOfConverter(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
|
|
||||||
$subject = new Town(
|
$subject = new Town(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal()
|
$organisationRepository->reveal()
|
||||||
);
|
);
|
||||||
self::assertInstanceOf(Converter::class, $subject);
|
self::assertInstanceOf(Converter::class, $subject);
|
||||||
|
@ -78,10 +84,12 @@ class TownTest extends TestCase
|
||||||
public function canConvertTouristMarketingCompany(): void
|
public function canConvertTouristMarketingCompany(): void
|
||||||
{
|
{
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
|
|
||||||
$subject = new Town(
|
$subject = new Town(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal()
|
$organisationRepository->reveal()
|
||||||
);
|
);
|
||||||
self::assertTrue($subject->canConvert([
|
self::assertTrue($subject->canConvert([
|
||||||
|
@ -107,11 +115,16 @@ class TownTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getDefaultLanguage(10)->willReturn($siteLanguage->reveal());
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD)->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD)->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
|
|
||||||
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
$organisationRepository = $this->prophesize(OrganisationRepository::class);
|
||||||
$organisationRepository->findOneByRemoteId('https://example.com/resources/018132452787-xxxx')->willReturn(null);
|
$organisationRepository->findOneByRemoteId('https://example.com/resources/018132452787-xxxx')->willReturn(null);
|
||||||
|
@ -121,6 +134,7 @@ class TownTest extends TestCase
|
||||||
|
|
||||||
$subject = new Town(
|
$subject = new Town(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal()
|
$organisationRepository->reveal()
|
||||||
);
|
);
|
||||||
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
||||||
|
@ -158,11 +172,16 @@ class TownTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
|
$language = $this->prophesize(LanguageHandling::class);
|
||||||
|
$language->getDefaultLanguage(10)->willReturn($siteLanguage->reveal());
|
||||||
|
|
||||||
$parser = $this->prophesize(Parser::class);
|
$parser = $this->prophesize(Parser::class);
|
||||||
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
$parser->getManagerId($jsonLD)->willReturn('https://example.com/resources/018132452787-xxxx');
|
||||||
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
||||||
$parser->getTitle($jsonLD)->willReturn('Title');
|
$parser->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Title');
|
||||||
$parser->getDescription($jsonLD)->willReturn('Description');
|
$parser->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Description');
|
||||||
|
|
||||||
$organisation = $this->prophesize(Organisation::class);
|
$organisation = $this->prophesize(Organisation::class);
|
||||||
$organisation->getUid()->willReturn(10);
|
$organisation->getUid()->willReturn(10);
|
||||||
|
@ -174,6 +193,7 @@ class TownTest extends TestCase
|
||||||
|
|
||||||
$subject = new Town(
|
$subject = new Town(
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
|
$language->reveal(),
|
||||||
$organisationRepository->reveal()
|
$organisationRepository->reveal()
|
||||||
);
|
);
|
||||||
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
$entities = $subject->convert($jsonLD, $configuration->reveal());
|
||||||
|
|
|
@ -52,53 +52,7 @@ class LanguageHandlingTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function allowsToCheckForUnkownLanguage(): void
|
public function returnsAllLanguagesForGivenPageUid(): void
|
||||||
{
|
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
|
||||||
$language->getTwoLetterIsoCode()->willReturn('en');
|
|
||||||
|
|
||||||
$site = $this->prophesize(Site::class);
|
|
||||||
$site->getLanguages()->willReturn([$language->reveal()]);
|
|
||||||
|
|
||||||
$siteFinder = $this->prophesize(SiteFinder::class);
|
|
||||||
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
|
||||||
|
|
||||||
$subject = new LanguageHandling(
|
|
||||||
$siteFinder->reveal()
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $subject->isUnknown('de', 10);
|
|
||||||
|
|
||||||
self::assertTrue($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function allowsToCheckForKnownLanguage(): void
|
|
||||||
{
|
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
|
||||||
$language->getTwoLetterIsoCode()->willReturn('de');
|
|
||||||
|
|
||||||
$site = $this->prophesize(Site::class);
|
|
||||||
$site->getLanguages()->willReturn([$language->reveal()]);
|
|
||||||
|
|
||||||
$siteFinder = $this->prophesize(SiteFinder::class);
|
|
||||||
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
|
||||||
|
|
||||||
$subject = new LanguageHandling(
|
|
||||||
$siteFinder->reveal()
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $subject->isUnknown('de', 10);
|
|
||||||
|
|
||||||
self::assertFalse($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function providesSystemLanguageUidForLanguage(): void
|
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
$language->getTwoLetterIsoCode()->willReturn('de');
|
$language->getTwoLetterIsoCode()->willReturn('de');
|
||||||
|
@ -114,21 +68,24 @@ class LanguageHandlingTest extends TestCase
|
||||||
$siteFinder->reveal()
|
$siteFinder->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->getSystemUid('de', 10);
|
$result = $subject->getLanguages(10);
|
||||||
|
|
||||||
self::assertSame(2, $result);
|
self::assertCount(1, $result);
|
||||||
|
self::assertSame(2, $result[0]->getLanguageId());
|
||||||
|
self::assertSame('de', $result[0]->getTwoLetterIsoCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function providesZeroAsFallbackSystemLanguageUidForUnkownLanguage(): void
|
public function returnsDefaultLanguageForGivenPageUid(): void
|
||||||
{
|
{
|
||||||
$language = $this->prophesize(SiteLanguage::class);
|
$language = $this->prophesize(SiteLanguage::class);
|
||||||
$language->getTwoLetterIsoCode()->willReturn('fr');
|
$language->getTwoLetterIsoCode()->willReturn('de');
|
||||||
|
$language->getLanguageId()->willReturn(2);
|
||||||
|
|
||||||
$site = $this->prophesize(Site::class);
|
$site = $this->prophesize(Site::class);
|
||||||
$site->getLanguages()->willReturn([$language->reveal()]);
|
$site->getDefaultLanguage()->willReturn($language->reveal());
|
||||||
|
|
||||||
$siteFinder = $this->prophesize(SiteFinder::class);
|
$siteFinder = $this->prophesize(SiteFinder::class);
|
||||||
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
$siteFinder->getSiteByPageId(10)->willReturn($site->reveal());
|
||||||
|
@ -137,8 +94,10 @@ class LanguageHandlingTest extends TestCase
|
||||||
$siteFinder->reveal()
|
$siteFinder->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->getSystemUid('de', 10);
|
$result = $subject->getDefaultLanguage(10);
|
||||||
|
|
||||||
self::assertSame(0, $result);
|
self::assertInstanceOf(SiteLanguage::class, $result);
|
||||||
|
self::assertSame(2, $result->getLanguageId());
|
||||||
|
self::assertSame('de', $result->getTwoLetterIsoCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\JsonLD\Parser;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\LanguageValues;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\LanguageValues;
|
||||||
|
|
||||||
|
@ -52,10 +53,12 @@ class GenericFieldsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function returnsTitle(): void
|
public function returnsTitle(): void
|
||||||
{
|
{
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
$languageValues = $this->prophesize(LanguageValues::class);
|
$languageValues = $this->prophesize(LanguageValues::class);
|
||||||
$languageValues->getValueForLanguage([
|
$languageValues->getValueForLanguage([
|
||||||
'@value' => 'DE Title',
|
'@value' => 'DE Title',
|
||||||
], 'de')->willReturn('DE Title');
|
], $siteLanguage->reveal())->willReturn('DE Title');
|
||||||
|
|
||||||
$subject = new GenericFields(
|
$subject = new GenericFields(
|
||||||
$languageValues->reveal()
|
$languageValues->reveal()
|
||||||
|
@ -65,7 +68,7 @@ class GenericFieldsTest extends TestCase
|
||||||
'schema:name' => [
|
'schema:name' => [
|
||||||
'@value' => 'DE Title',
|
'@value' => 'DE Title',
|
||||||
],
|
],
|
||||||
], 'de');
|
], $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame('DE Title', $result);
|
self::assertSame('DE Title', $result);
|
||||||
}
|
}
|
||||||
|
@ -75,10 +78,12 @@ class GenericFieldsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function returnsDescription(): void
|
public function returnsDescription(): void
|
||||||
{
|
{
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
$languageValues = $this->prophesize(LanguageValues::class);
|
$languageValues = $this->prophesize(LanguageValues::class);
|
||||||
$languageValues->getValueForLanguage([
|
$languageValues->getValueForLanguage([
|
||||||
'@value' => 'DE Description',
|
'@value' => 'DE Description',
|
||||||
], 'de')->willReturn('DE Description');
|
], $siteLanguage->reveal())->willReturn('DE Description');
|
||||||
|
|
||||||
$subject = new GenericFields(
|
$subject = new GenericFields(
|
||||||
$languageValues->reveal()
|
$languageValues->reveal()
|
||||||
|
@ -88,7 +93,7 @@ class GenericFieldsTest extends TestCase
|
||||||
'schema:description' => [
|
'schema:description' => [
|
||||||
'@value' => 'DE Description',
|
'@value' => 'DE Description',
|
||||||
],
|
],
|
||||||
], 'de');
|
], $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame('DE Description', $result);
|
self::assertSame('DE Description', $result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\JsonLD\Parser;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\LanguageValues;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\LanguageValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +31,8 @@ use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\LanguageValues;
|
||||||
*/
|
*/
|
||||||
class LanguageValuesTest extends TestCase
|
class LanguageValuesTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
@ -46,10 +50,13 @@ class LanguageValuesTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function returnsValue(array $jsonLD, string $language, string $expected): void
|
public function returnsValue(array $jsonLD, string $language, string $expected): void
|
||||||
{
|
{
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
$siteLanguage->getTwoLetterIsoCode()->willReturn($language);
|
||||||
|
|
||||||
$subject = new LanguageValues(
|
$subject = new LanguageValues(
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->getValueForLanguage($jsonLD, $language);
|
$result = $subject->getValueForLanguage($jsonLD, $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame($expected, $result);
|
self::assertSame($expected, $result);
|
||||||
}
|
}
|
||||||
|
@ -71,20 +78,6 @@ class LanguageValuesTest extends TestCase
|
||||||
'language' => 'de',
|
'language' => 'de',
|
||||||
'expected' => 'DE value',
|
'expected' => 'DE value',
|
||||||
],
|
],
|
||||||
'has multiple lanugages, no language specified' => [
|
|
||||||
'jsonLD' => [
|
|
||||||
[
|
|
||||||
'@language' => 'de',
|
|
||||||
'@value' => 'DE value',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'@language' => 'fr',
|
|
||||||
'@value' => 'FR value',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'language' => '',
|
|
||||||
'expected' => 'DE value',
|
|
||||||
],
|
|
||||||
'has multiple languages, none matches' => [
|
'has multiple languages, none matches' => [
|
||||||
'jsonLD' => [
|
'jsonLD' => [
|
||||||
[
|
[
|
||||||
|
@ -127,14 +120,6 @@ class LanguageValuesTest extends TestCase
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'expected' => '',
|
'expected' => '',
|
||||||
],
|
],
|
||||||
'has single language, no language specified' => [
|
|
||||||
'jsonLD' => [
|
|
||||||
'@language' => 'de',
|
|
||||||
'@value' => 'DE value',
|
|
||||||
],
|
|
||||||
'language' => '',
|
|
||||||
'expected' => 'DE value',
|
|
||||||
],
|
|
||||||
'has single language, missing @language key' => [
|
'has single language, missing @language key' => [
|
||||||
'jsonLD' => [
|
'jsonLD' => [
|
||||||
'@value' => 'DE value',
|
'@value' => 'DE value',
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\JsonLD\Parser;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Offers;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Offers;
|
||||||
|
|
||||||
|
@ -52,13 +53,14 @@ class OffersTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function returnsEmptyArrayIfNoOfferExists(): void
|
public function returnsEmptyArrayIfNoOfferExists(): void
|
||||||
{
|
{
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
|
|
||||||
$subject = new Offers(
|
$subject = new Offers(
|
||||||
$genericFields->reveal()
|
$genericFields->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->get([], '');
|
$result = $subject->get([], $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame([], $result);
|
self::assertSame([], $result);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +68,7 @@ class OffersTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function returnsSingleOfferWithSinglePrice(): void
|
public function returnsMultipleOfferWithMultiplePrices(): void
|
||||||
{
|
{
|
||||||
$jsonLD = [
|
$jsonLD = [
|
||||||
'schema:makesOffer' => [
|
'schema:makesOffer' => [
|
||||||
|
@ -255,53 +257,66 @@ class OffersTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
|
|
||||||
// Offer 1
|
// Offer 1
|
||||||
$genericFields->getTitle($jsonLD['schema:makesOffer'][0], 'de')->willReturn('Führungen');
|
$genericFields->getTitle(
|
||||||
$genericFields->getDescription($jsonLD['schema:makesOffer'][0], 'de')->willReturn('Immer samstags, um 11:15 Uhr findet eine öffentliche Führung durch das Museum statt. Dauer etwa 90 Minuten');
|
$jsonLD['schema:makesOffer'][0],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Führungen');
|
||||||
|
$genericFields->getDescription(
|
||||||
|
$jsonLD['schema:makesOffer'][0],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Immer samstags, um 11:15 Uhr findet eine öffentliche Führung durch das Museum statt. Dauer etwa 90 Minuten');
|
||||||
$genericFields->getTitle(
|
$genericFields->getTitle(
|
||||||
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][0],
|
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][0],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('Erwachsene');
|
)->willReturn('Erwachsene');
|
||||||
$genericFields->getDescription(
|
$genericFields->getDescription(
|
||||||
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][0],
|
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][0],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('');
|
)->willReturn('');
|
||||||
$genericFields->getTitle(
|
$genericFields->getTitle(
|
||||||
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][1],
|
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][1],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('Ermäßigt');
|
)->willReturn('Ermäßigt');
|
||||||
$genericFields->getDescription(
|
$genericFields->getDescription(
|
||||||
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][1],
|
$jsonLD['schema:makesOffer'][0]['schema:priceSpecification'][1],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('als ermäßigt gelten schulpflichtige Kinder, Auszubildende, Studierende, Rentner/-innen, Menschen mit Behinderungen, Inhaber Sozialausweis der Landeshauptstadt Erfurt');
|
)->willReturn('als ermäßigt gelten schulpflichtige Kinder, Auszubildende, Studierende, Rentner/-innen, Menschen mit Behinderungen, Inhaber Sozialausweis der Landeshauptstadt Erfurt');
|
||||||
|
|
||||||
// Offer2
|
// Offer2
|
||||||
$genericFields->getTitle($jsonLD['schema:makesOffer'][1], 'de')->willReturn('Eintritt');
|
$genericFields->getTitle(
|
||||||
$genericFields->getDescription($jsonLD['schema:makesOffer'][1], 'de')->willReturn("Schulklassen und Kitagruppen im Rahmen des Unterrichts: Eintritt frei\nAn jedem ersten Dienstag im Monat: Eintritt frei");
|
$jsonLD['schema:makesOffer'][1],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Eintritt');
|
||||||
|
$genericFields->getDescription(
|
||||||
|
$jsonLD['schema:makesOffer'][1],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn("Schulklassen und Kitagruppen im Rahmen des Unterrichts: Eintritt frei\nAn jedem ersten Dienstag im Monat: Eintritt frei");
|
||||||
$genericFields->getTitle(
|
$genericFields->getTitle(
|
||||||
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][0],
|
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][0],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('Ermäßigt');
|
)->willReturn('Ermäßigt');
|
||||||
$genericFields->getDescription(
|
$genericFields->getDescription(
|
||||||
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][0],
|
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][0],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('als ermäßigt gelten schulpflichtige Kinder, Auszubildende, Studierende, Rentner/-innen, Menschen mit Behinderungen, Inhaber Sozialausweis der Landeshauptstadt Erfurt');
|
)->willReturn('als ermäßigt gelten schulpflichtige Kinder, Auszubildende, Studierende, Rentner/-innen, Menschen mit Behinderungen, Inhaber Sozialausweis der Landeshauptstadt Erfurt');
|
||||||
$genericFields->getTitle(
|
$genericFields->getTitle(
|
||||||
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][1],
|
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][1],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('Familienkarte');
|
)->willReturn('Familienkarte');
|
||||||
$genericFields->getDescription(
|
$genericFields->getDescription(
|
||||||
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][1],
|
$jsonLD['schema:makesOffer'][1]['schema:priceSpecification'][1],
|
||||||
'de'
|
$siteLanguage->reveal()
|
||||||
)->willReturn('');
|
)->willReturn('');
|
||||||
|
|
||||||
$subject = new Offers(
|
$subject = new Offers(
|
||||||
$genericFields->reveal()
|
$genericFields->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->get($jsonLD, 'de');
|
$result = $subject->get($jsonLD, $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame([
|
self::assertSame([
|
||||||
[
|
[
|
||||||
|
@ -346,4 +361,111 @@ class OffersTest extends TestCase
|
||||||
],
|
],
|
||||||
], $result);
|
], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function returnsSingleOfferWithSinglePrice(): void
|
||||||
|
{
|
||||||
|
$jsonLD = [
|
||||||
|
'schema:makesOffer' => [
|
||||||
|
'@id' => 'genid-28b33237f71b41e3ad54a99e1da769b9-b5',
|
||||||
|
'@type' => [
|
||||||
|
0 => 'schema:Intangible',
|
||||||
|
1 => 'schema:Thing',
|
||||||
|
2 => 'schema:Offer',
|
||||||
|
],
|
||||||
|
'rdfs:label' => [
|
||||||
|
'@language' => 'de',
|
||||||
|
'@value' => 'Führungen',
|
||||||
|
],
|
||||||
|
'schema:description' => [
|
||||||
|
'@language' => 'de',
|
||||||
|
'@value' => 'Immer samstags, um 11:15 Uhr findet eine öffentliche Führung durch das Museum statt. Dauer etwa 90 Minuten',
|
||||||
|
],
|
||||||
|
'schema:name' => [
|
||||||
|
'@language' => 'de',
|
||||||
|
'@value' => 'Führungen',
|
||||||
|
],
|
||||||
|
'schema:offeredBy' => [
|
||||||
|
'@id' => 'https://thuecat.org/resources/165868194223-zmqf',
|
||||||
|
],
|
||||||
|
'schema:priceSpecification' => [
|
||||||
|
'@id' => 'genid-28b33237f71b41e3ad54a99e1da769b9-b6',
|
||||||
|
'@type' => [
|
||||||
|
0 => 'schema:Intangible',
|
||||||
|
1 => 'schema:StructuredValue',
|
||||||
|
2 => 'schema:PriceSpecification',
|
||||||
|
3 => 'schema:Thing',
|
||||||
|
],
|
||||||
|
'rdfs:label' => [
|
||||||
|
'@language' => 'de',
|
||||||
|
'@value' => 'Erwachsene',
|
||||||
|
],
|
||||||
|
'schema:name' => [
|
||||||
|
'@language' => 'de',
|
||||||
|
'@value' => 'Erwachsene',
|
||||||
|
],
|
||||||
|
'schema:price' => [
|
||||||
|
'@type' => 'schema:Number',
|
||||||
|
'@value' => '8',
|
||||||
|
],
|
||||||
|
'schema:priceCurrency' => [
|
||||||
|
'@type' => 'thuecat:Currency',
|
||||||
|
'@value' => 'thuecat:EUR',
|
||||||
|
],
|
||||||
|
'thuecat:calculationRule' => [
|
||||||
|
'@type' => 'thuecat:CalculationRule',
|
||||||
|
'@value' => 'thuecat:PerPerson',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'thuecat:offerType' => [
|
||||||
|
'@type' => 'thuecat:OfferType',
|
||||||
|
'@value' => 'thuecat:GuidedTourOffer',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
|
|
||||||
|
$genericFields->getTitle(
|
||||||
|
$jsonLD['schema:makesOffer'],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Führungen');
|
||||||
|
$genericFields->getDescription(
|
||||||
|
$jsonLD['schema:makesOffer'],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Immer samstags, um 11:15 Uhr findet eine öffentliche Führung durch das Museum statt. Dauer etwa 90 Minuten');
|
||||||
|
$genericFields->getTitle(
|
||||||
|
$jsonLD['schema:makesOffer']['schema:priceSpecification'],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('Erwachsene');
|
||||||
|
$genericFields->getDescription(
|
||||||
|
$jsonLD['schema:makesOffer']['schema:priceSpecification'],
|
||||||
|
$siteLanguage->reveal()
|
||||||
|
)->willReturn('');
|
||||||
|
|
||||||
|
$subject = new Offers(
|
||||||
|
$genericFields->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $subject->get($jsonLD, $siteLanguage->reveal());
|
||||||
|
|
||||||
|
self::assertSame([
|
||||||
|
[
|
||||||
|
'title' => 'Führungen',
|
||||||
|
'description' => 'Immer samstags, um 11:15 Uhr findet eine öffentliche Führung durch das Museum statt. Dauer etwa 90 Minuten',
|
||||||
|
'prices' => [
|
||||||
|
[
|
||||||
|
'title' => 'Erwachsene',
|
||||||
|
'description' => '',
|
||||||
|
'price' => 8.0,
|
||||||
|
'currency' => 'EUR',
|
||||||
|
'rule' => 'PerPerson',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
], $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\JsonLD;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Address;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\Address;
|
||||||
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser\GenericFields;
|
||||||
|
@ -94,8 +95,10 @@ class ParserTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
$genericFields->getTitle($jsonLD, 'de')->willReturn('Erfurt');
|
$genericFields->getTitle($jsonLD, $siteLanguage->reveal())->willReturn('Erfurt');
|
||||||
|
|
||||||
$openingHours = $this->prophesize(OpeningHours::class);
|
$openingHours = $this->prophesize(OpeningHours::class);
|
||||||
$address = $this->prophesize(Address::class);
|
$address = $this->prophesize(Address::class);
|
||||||
|
@ -108,7 +111,7 @@ class ParserTest extends TestCase
|
||||||
$media->reveal()
|
$media->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->getTitle($jsonLD, 'de');
|
$result = $subject->getTitle($jsonLD, $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame('Erfurt', $result);
|
self::assertSame('Erfurt', $result);
|
||||||
}
|
}
|
||||||
|
@ -125,8 +128,10 @@ class ParserTest extends TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$siteLanguage = $this->prophesize(SiteLanguage::class);
|
||||||
|
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
$genericFields = $this->prophesize(GenericFields::class);
|
||||||
$genericFields->getDescription($jsonLD, 'de')->willReturn('Erfurt');
|
$genericFields->getDescription($jsonLD, $siteLanguage->reveal())->willReturn('Erfurt');
|
||||||
|
|
||||||
$openingHours = $this->prophesize(OpeningHours::class);
|
$openingHours = $this->prophesize(OpeningHours::class);
|
||||||
$address = $this->prophesize(Address::class);
|
$address = $this->prophesize(Address::class);
|
||||||
|
@ -139,7 +144,7 @@ class ParserTest extends TestCase
|
||||||
$media->reveal()
|
$media->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$result = $subject->getDescription($jsonLD, 'de');
|
$result = $subject->getDescription($jsonLD, $siteLanguage->reveal());
|
||||||
|
|
||||||
self::assertSame('Erfurt', $result);
|
self::assertSame('Erfurt', $result);
|
||||||
}
|
}
|
||||||
|
@ -206,97 +211,6 @@ class ParserTest extends TestCase
|
||||||
], $result);
|
], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function returnsLanguages(): void
|
|
||||||
{
|
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
|
||||||
$openingHours = $this->prophesize(OpeningHours::class);
|
|
||||||
$address = $this->prophesize(Address::class);
|
|
||||||
$media = $this->prophesize(Media::class);
|
|
||||||
|
|
||||||
$subject = new Parser(
|
|
||||||
$genericFields->reveal(),
|
|
||||||
$openingHours->reveal(),
|
|
||||||
$address->reveal(),
|
|
||||||
$media->reveal()
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $subject->getLanguages([
|
|
||||||
'schema:availableLanguage' => [
|
|
||||||
0 => [
|
|
||||||
'@type' => 'thuecat:Language',
|
|
||||||
'@value' => 'thuecat:German',
|
|
||||||
],
|
|
||||||
1 => [
|
|
||||||
'@type' => 'thuecat:Language',
|
|
||||||
'@value' => 'thuecat:English',
|
|
||||||
],
|
|
||||||
2 => [
|
|
||||||
'@type' => 'thuecat:Language',
|
|
||||||
'@value' => 'thuecat:French',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
self::assertSame([
|
|
||||||
'de',
|
|
||||||
'en',
|
|
||||||
'fr',
|
|
||||||
], $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function throwsExceptionOnUnkownLanguage(): void
|
|
||||||
{
|
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
|
||||||
$openingHours = $this->prophesize(OpeningHours::class);
|
|
||||||
$address = $this->prophesize(Address::class);
|
|
||||||
$media = $this->prophesize(Media::class);
|
|
||||||
|
|
||||||
$subject = new Parser(
|
|
||||||
$genericFields->reveal(),
|
|
||||||
$openingHours->reveal(),
|
|
||||||
$address->reveal(),
|
|
||||||
$media->reveal()
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->expectExceptionCode(1612367481);
|
|
||||||
$result = $subject->getLanguages([
|
|
||||||
'schema:availableLanguage' => [
|
|
||||||
0 => [
|
|
||||||
'@type' => 'thuecat:Language',
|
|
||||||
'@value' => 'thuecat:Unkown',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function returnsNoLanguagesIfInfoIsMissing(): void
|
|
||||||
{
|
|
||||||
$genericFields = $this->prophesize(GenericFields::class);
|
|
||||||
$openingHours = $this->prophesize(OpeningHours::class);
|
|
||||||
$address = $this->prophesize(Address::class);
|
|
||||||
$media = $this->prophesize(Media::class);
|
|
||||||
|
|
||||||
$subject = new Parser(
|
|
||||||
$genericFields->reveal(),
|
|
||||||
$openingHours->reveal(),
|
|
||||||
$address->reveal(),
|
|
||||||
$media->reveal()
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = $subject->getLanguages([]);
|
|
||||||
|
|
||||||
self::assertSame([], $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue