2021-02-01 14:14:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Import\Converter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-02-03 17:20:01 +01:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
2021-02-01 14:14:05 +01:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Converter;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Converter\Organisation;
|
2021-02-03 17:20:01 +01:00
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\JsonLD\Parser;
|
|
|
|
use WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection;
|
2021-02-01 14:14:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers WerkraumMedia\ThueCat\Domain\Import\Converter\Organisation
|
2021-02-03 17:20:01 +01:00
|
|
|
* @uses WerkraumMedia\ThueCat\Domain\Import\Model\EntityCollection
|
2021-02-01 14:14:05 +01:00
|
|
|
* @uses WerkraumMedia\ThueCat\Domain\Import\Model\GenericEntity
|
|
|
|
*/
|
|
|
|
class OrganisationTest extends TestCase
|
|
|
|
{
|
2021-02-03 17:20:01 +01:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2021-02-01 14:14:05 +01:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function instanceCanBeCreated(): void
|
|
|
|
{
|
2021-02-03 17:20:01 +01:00
|
|
|
$parser = $this->prophesize(Parser::class);
|
|
|
|
$subject = new Organisation($parser->reveal());
|
2021-02-01 14:14:05 +01:00
|
|
|
self::assertInstanceOf(Organisation::class, $subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function isInstanceOfConverter(): void
|
|
|
|
{
|
2021-02-03 17:20:01 +01:00
|
|
|
$parser = $this->prophesize(Parser::class);
|
|
|
|
$subject = new Organisation($parser->reveal());
|
2021-02-01 14:14:05 +01:00
|
|
|
self::assertInstanceOf(Converter::class, $subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canConvertTouristMarketingCompany(): void
|
|
|
|
{
|
2021-02-03 17:20:01 +01:00
|
|
|
$parser = $this->prophesize(Parser::class);
|
|
|
|
$subject = new Organisation($parser->reveal());
|
2021-02-01 14:14:05 +01:00
|
|
|
self::assertTrue($subject->canConvert([
|
|
|
|
'thuecat:TouristMarketingCompany',
|
|
|
|
'schema:Thing',
|
|
|
|
'ttgds:Organization',
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function convertsJsonIdToGenericEntity(): void
|
|
|
|
{
|
2021-02-03 17:20:01 +01:00
|
|
|
$jsonLD = [
|
2021-02-01 14:14:05 +01:00
|
|
|
'@id' => 'https://example.com/resources/018132452787-ngbe',
|
|
|
|
'schema:name' => [
|
|
|
|
'@value' => 'Title',
|
|
|
|
],
|
|
|
|
'schema:description' => [
|
|
|
|
'@value' => 'Description',
|
|
|
|
],
|
2021-02-03 17:20:01 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
$parser = $this->prophesize(Parser::class);
|
|
|
|
$parser->getId($jsonLD)->willReturn('https://example.com/resources/018132452787-ngbe');
|
|
|
|
$parser->getTitle($jsonLD)->willReturn('Title');
|
|
|
|
$parser->getDescription($jsonLD)->willReturn('Description');
|
|
|
|
|
|
|
|
$subject = new Organisation($parser->reveal());
|
|
|
|
$entities = $subject->convert($jsonLD);
|
|
|
|
|
|
|
|
self::assertInstanceOf(EntityCollection::class, $entities);
|
|
|
|
self::assertCount(1, $entities->getEntities());
|
2021-02-01 14:14:05 +01:00
|
|
|
|
2021-02-03 17:20:01 +01:00
|
|
|
$entity = $entities->getEntities()[0];
|
2021-02-15 16:05:46 +01:00
|
|
|
self::assertSame(10, $entity->getTypo3StoragePid());
|
2021-02-01 14:14:05 +01:00
|
|
|
self::assertSame('tx_thuecat_organisation', $entity->getTypo3DatabaseTableName());
|
|
|
|
self::assertSame('https://example.com/resources/018132452787-ngbe', $entity->getRemoteId());
|
|
|
|
self::assertSame([
|
|
|
|
'title' => 'Title',
|
|
|
|
'description' => 'Description',
|
|
|
|
], $entity->getData());
|
|
|
|
}
|
|
|
|
}
|