/** * @covers \unicode::toUTF8 */ public function testToUTF8() { $reference = 'Un éléphant ça trompe énormément !'; $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/MacOSRoman.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/ISOLatin1.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/ISOLatin2.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/Latin5.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/UTF-8.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/WindowsLatin1.txt'))); $this->assertEquals($reference, $this->object->toUTF8(file_get_contents(__DIR__ . '/../files/WindowsLatin2.txt'))); }
/** * {@inheritdoc} */ public function toMetadataArray(\databox_descriptionStructure $metadatasStructure) { $metas = []; $unicode = new \unicode(); foreach ($metadatasStructure as $databox_field) { if ('' === $databox_field->get_tag()->getTagname()) { // skipping fields without sources continue; } if ($this->containsKey($databox_field->get_tag()->getTagname())) { if ($databox_field->is_multi()) { $values = $this->get($databox_field->get_tag()->getTagname())->getValue()->asArray(); $tmp = []; foreach ($values as $value) { foreach (\caption_field::get_multi_values($value, $databox_field->get_separator()) as $v) { $tmp[] = $v; } } $values = array_unique($tmp); foreach ($values as $value) { $value = $unicode->substituteCtrlCharacters($value, ' '); $value = $unicode->toUTF8($value); if ($databox_field->get_type() == 'date') { $value = $unicode->parseDate($value); } $metas[] = ['meta_struct_id' => $databox_field->get_id(), 'value' => $value, 'meta_id' => null]; } } else { $value = $this->get($databox_field->get_tag()->getTagname())->getValue()->asString(); $value = $unicode->substituteCtrlCharacters($value, ' '); $value = $unicode->toUTF8($value); if ($databox_field->get_type() == 'date') { $value = $unicode->parseDate($value); } $metas[] = ['meta_struct_id' => $databox_field->get_id(), 'value' => $value, 'meta_id' => null]; } } } unset($unicode); return $metas; }