<commit_before><?php
//
//namespace CultuurNet\UDB3\Offer\ReadModel\JSONLD;
//
//class CdbXMLItemBaseImporterTest extends \PHPUnit_Framework_TestCase
//{
//
//}
<commit_msg>III-1642: Make sure Base importer projects Media Objects and main image<commit_after><?php

namespace CultuurNet\UDB3\Offer\ReadModel\JSONLD;

use CultureFeed_Cdb_Data_EventDetail;
use CultuurNet\UDB3\Cdb\EventItemFactory;
use CultuurNet\UDB3\Iri\CallableIriGenerator;

class CdbXMLItemBaseImporterTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var CdbXMLItemBaseImporter
     */
    private $importer;

    public function setUp()
    {
        $mediaIriGenerator = new CallableIriGenerator(function ($file) {
            return 'http://du.de/media/87e8b421-5e87-4fae-bb3b-2c9119852a11';
        });

        $this->importer = new CdbXMLItemBaseImporter($mediaIriGenerator);
    }

    /**
     * @test
     */
    public function it_should_project_udb2_media_files_as_media_objects()
    {
        $jsonData = (object)[];
        $expectedJsonData = (object)[
            'mediaObject' => [
                [
                    '@id' => 'http://du.de/media/87e8b421-5e87-4fae-bb3b-2c9119852a11',
                    '@type' => 'schema:ImageObject',
                    'contentUrl' => '//media.uitdatabank.be/20141105/ed466c72-451f-4079-94d3-4ab2e0be7b15.jpg',
                    'thumbnailUrl' => '//media.uitdatabank.be/20141105/ed466c72-451f-4079-94d3-4ab2e0be7b15.jpg',
                    'copyrightHolder' => "'<NAME>' - quiz",
                ]
            ]
        ];

        $this->importer->importMedia(
            $this->getEventDetailsFromCDBXMLFile('event_with_photo.cdbxml.xml'),
            $jsonData
        );

        $this->assertEquals($expectedJsonData, $jsonData);
    }

    /**
     * @test
     */
    public function it_should_project_the_main_udb2_picture_as_image()
    {
        $jsonData = (object)[];
        $expectedJsonData = (object)[
            'image' => '//media.uitdatabank.be/20141105/ed466c72-451f-4079-94d3-4ab2e0be7b15.jpg'
        ];

        $this->importer->importPicture(
            $this->getEventDetailsFromCDBXMLFile('event_with_photo.cdbxml.xml'),
            $jsonData
        );

        $this->assertEquals($expectedJsonData, $jsonData);
    }

    /**
     * @param string $fileName
     * @return CultureFeed_Cdb_Data_EventDetail
     */
    private function getEventDetailsFromCDBXMLFile($fileName)
    {
        $cdbXml = file_get_contents(
            __DIR__ . '/../../../Event/samples/' . $fileName
        );

        $udb2Event = EventItemFactory::createEventFromCdbXml(
            'http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.2/FINAL',
            $cdbXml
        );

        return $udb2Event->getDetails()->current();
    }
}

{'fraction_non_alphanumeric': 0.13211600429645542, 'fraction_numerical': 0.05119942713927676, 'mean_word_length': 2.31042654028436, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630532', 'n_tokens_mistral': 1022, 'n_tokens_neox': 942, 'n_words': 105}